Java Code Examples for org.apache.cxf.helpers.domutils#getElementQName()

The following examples show how to use org.apache.cxf.helpers.domutils#getElementQName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String getIDFromSTR(Element el) {
    Element child = DOMUtils.getFirstElement(el);
    if (child == null) {
        return null;
    }
    QName elName = DOMUtils.getElementQName(child);
    if (elName.equals(new QName(WSConstants.SIG_NS, "KeyInfo"))
        || elName.equals(new QName(WSConstants.WSSE_NS, "KeyIdentifier"))) {
        return DOMUtils.getContent(child);
    } else if (elName.equals(Reference.TOKEN)) {
        return child.getAttribute("URI");
    } else if (elName.equals(new QName(STSUtils.SCT_NS_05_02, "Identifier"))
               || elName.equals(new QName(STSUtils.SCT_NS_05_12, "Identifier"))) {
        return DOMUtils.getContent(child);
    }
    return null;
}
 
Example 2
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String findIDFromSamlToken(Element samlToken) {
    String id = null;
    if (samlToken != null) {
        QName elName = DOMUtils.getElementQName(samlToken);
        if (elName.equals(new QName(WSConstants.SAML_NS, "Assertion"))
            && samlToken.hasAttributeNS(null, "AssertionID")) {
            id = samlToken.getAttributeNS(null, "AssertionID");
        } else if (elName.equals(new QName(WSConstants.SAML2_NS, "Assertion"))
            && samlToken.hasAttributeNS(null, "ID")) {
            id = samlToken.getAttributeNS(null, "ID");
        }
        if (id == null) {
            id = samlToken.getAttributeNS(WSConstants.WSU_NS, "Id");
        }
    }
    return id;
}
 
Example 3
Source File: SimpleBatchSTSClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected String getIDFromSTR(Element el) {
    Element child = DOMUtils.getFirstElement(el);
    if (child == null) {
        return null;
    }
    QName elName = DOMUtils.getElementQName(child);
    if (elName.equals(new QName(WSS4JConstants.SIG_NS, "KeyInfo"))
        || elName.equals(new QName(WSS4JConstants.WSSE_NS, "KeyIdentifier"))) {
        return DOMUtils.getContent(child);
    } else if (elName.equals(Reference.TOKEN)) {
        return child.getAttributeNS(null, "URI");
    } else if (elName.equals(new QName(STSUtils.SCT_NS_05_02, "Identifier"))
               || elName.equals(new QName(STSUtils.SCT_NS_05_12, "Identifier"))) {
        return DOMUtils.getContent(child);
    }
    return null;
}
 
Example 4
Source File: SimpleBatchSTSClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected String findID(Element rar, Element rur, Element rst) {
    String id = null;
    if (rst != null) {
        QName elName = DOMUtils.getElementQName(rst);
        if (elName.equals(new QName(WSS4JConstants.SAML_NS, "Assertion"))
            && rst.hasAttributeNS(null, "AssertionID")) {
            id = rst.getAttributeNS(null, "AssertionID");
        } else if (elName.equals(new QName(WSS4JConstants.SAML2_NS, "Assertion"))
            && rst.hasAttributeNS(null, "ID")) {
            id = rst.getAttributeNS(null, "ID");
        }
        if (id == null) {
            id = this.getIDFromSTR(rst);
        }
    }
    if (id == null && rar != null) {
        id = this.getIDFromSTR(rar);
    }
    if (id == null && rur != null) {
        id = this.getIDFromSTR(rur);
    }
    if (id == null && rst != null) {
        id = rst.getAttributeNS(WSS4JConstants.WSU_NS, "Id");
    }
    return id;
}
 
Example 5
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String findID(Element rar, Element rur, Element rst) {
    String id = null;
    if (rst != null) {
        QName elName = DOMUtils.getElementQName(rst);
        if (elName.equals(new QName(WSConstants.SAML_NS, "Assertion"))
            && rst.hasAttributeNS(null, "AssertionID")) {
            id = rst.getAttributeNS(null, "AssertionID");
        } else if (elName.equals(new QName(WSConstants.SAML2_NS, "Assertion"))
            && rst.hasAttributeNS(null, "ID")) {
            id = rst.getAttributeNS(null, "ID");
        }
        if (id == null) {
            id = this.getIDFromSTR(rst);
        }
    }
    if (id == null && rar != null) {
        id = this.getIDFromSTR(rar);
    }
    if (id == null && rur != null) {
        id = this.getIDFromSTR(rur);
    }
    if (id == null && rst != null) {
        id = rst.getAttributeNS(WSConstants.WSU_NS, "Id");
    }
    return id;
}
 
Example 6
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String findIDFromSamlToken(Element samlToken) {
    String id = null;
    if (samlToken != null) {
        QName elName = DOMUtils.getElementQName(samlToken);
        if (elName.equals(new QName(WSConstants.SAML_NS, "Assertion"))
            && samlToken.hasAttributeNS(null, "AssertionID")) {
            id = samlToken.getAttributeNS(null, "AssertionID");
        } else if (elName.equals(new QName(WSConstants.SAML2_NS, "Assertion"))
            && samlToken.hasAttributeNS(null, "ID")) {
            id = samlToken.getAttributeNS(null, "ID");
        }
        if (id == null) {
            id = samlToken.getAttributeNS(WSConstants.WSU_NS, "Id");
        }
    }
    return id;
}
 
Example 7
Source File: AbstractSTSClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected String getIDFromSTR(Element el) {
    Element child = DOMUtils.getFirstElement(el);
    if (child == null) {
        return null;
    }
    QName elName = DOMUtils.getElementQName(child);
    if (elName.equals(new QName(WSS4JConstants.SIG_NS, "KeyInfo"))
        || elName.equals(new QName(WSS4JConstants.WSSE_NS, "KeyIdentifier"))) {
        return DOMUtils.getContent(child);
    } else if (elName.equals(Reference.TOKEN)) {
        return child.getAttributeNS(null, "URI");
    } else if (elName.equals(new QName(STSUtils.SCT_NS_05_02, "Identifier"))
               || elName.equals(new QName(STSUtils.SCT_NS_05_12, "Identifier"))) {
        return DOMUtils.getContent(child);
    }
    return null;
}
 
Example 8
Source File: AbstractSTSClient.java    From steady with Apache License 2.0 6 votes vote down vote up
protected String findID(Element rar, Element rur, Element rst) {
    String id = null;
    if (rst != null) {
        QName elName = DOMUtils.getElementQName(rst);
        if (elName.equals(new QName(WSConstants.SAML_NS, "Assertion"))
            && rst.hasAttributeNS(null, "AssertionID")) {
            id = rst.getAttributeNS(null, "AssertionID");
        } else if (elName.equals(new QName(WSConstants.SAML2_NS, "Assertion"))
            && rst.hasAttributeNS(null, "ID")) {
            id = rst.getAttributeNS(null, "ID");
        }
        if (id == null) {
            id = this.getIDFromSTR(rst);
        }
    }
    if (id == null && rar != null) {
        id = this.getIDFromSTR(rar);
    }
    if (id == null && rur != null) {
        id = this.getIDFromSTR(rur);
    }
    if (id == null && rst != null) {
        id = rst.getAttributeNS(WSConstants.WSU_NS, "Id");
    }
    return id;
}
 
Example 9
Source File: MessageModeOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void validateFaultDetail(Element detail, Schema schema, BindingOperationInfo bop) throws Exception {
    if (detail != null) {
        Element el = DOMUtils.getFirstElement(detail);
        while (el != null) {
            QName qn = DOMUtils.getElementQName(el);
            for (BindingFaultInfo bfi : bop.getFaults()) {
                if (bfi.getFaultInfo().getMessagePartByIndex(0).getConcreteName().equals(qn)) {
                    //Found a fault with the correct QName, we can validate it
                    schema.newValidator().validate(new DOMSource(DOMUtils.getDomElement(el)));
                }
            }
            el = DOMUtils.getNextElement(el);
        }
    }
}
 
Example 10
Source File: SupportingTokensBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    QName name = DOMUtils.getElementQName(element);
    SupportingToken supportingToken = null;

    if (SP11Constants.SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_SUPPORTING,
                                              SP11Constants.INSTANCE,
                                              builder);
    } else if (SP11Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_SIGNED, 
                                              SP11Constants.INSTANCE,
                                              builder);
    } else if (SP11Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_ENDORSING, 
                                              SP11Constants.INSTANCE,
                                              builder);
    } else if (SP11Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING,
                                              SP11Constants.INSTANCE,
                                              builder);
    }

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), supportingToken);
        /*
         * for the moment we will say there should be only one alternative
         */
        break;
    }

    return supportingToken;
}
 
Example 11
Source File: PolicyConstants.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void findAllPolicyElementsOfLocalName(Element el, String localName, List<Element> val) {
    QName qn = DOMUtils.getElementQName(el);
    if (localName.equals(qn.getLocalPart()) && Constants.isInPolicyNS(qn)) {
        val.add(el);
    }
    el = DOMUtils.getFirstElement(el);
    while (el != null) {
        findAllPolicyElementsOfLocalName(el, localName, val);
        el = DOMUtils.getNextElement(el);
    }
}
 
Example 12
Source File: DispatchImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private QName getPayloadElementName(SOAPMessage soapMessage) {
    try {
        // we only care about the first element node, not text nodes
        Element element = DOMUtils.getFirstElement(SAAJUtils.getBody(soapMessage));
        if (element != null) {
            return DOMUtils.getElementQName(element);
        }
    } catch (Exception e) {
        //ignore
    }
    return null;
}
 
Example 13
Source File: SecureConversationTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
    
    
    SecureConversationToken conversationToken = new SecureConversationToken(consts);
    conversationToken.setOptional(PolicyConstants.isOptional(element));
    conversationToken.setIgnorable(PolicyConstants.isIgnorable(element));

    String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
    if (attribute != null) {
        conversationToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
    }
    
    Element elem = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    while (elem != null) {
        QName qn = DOMUtils.getElementQName(elem);
        if (Constants.isPolicyElement(qn)) {
            foundPolicy = true;
            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                conversationToken.setDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_IMPLIED_DERIVED_KEYS) 
                                                      != null) {
                conversationToken.setImpliedDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_EXPLICIT_DERIVED_KEYS)
                                                          != null) {
                conversationToken.setExplicitDerivedKeys(true);
            }


            if (DOMUtils.getFirstChildWithName(elem,
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE) != null) {
                conversationToken.setRequireExternalUriRef(true);
            }

            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc10SecurityContextToken(true);
            }
            
            if (DOMUtils.getFirstChildWithName(elem, 
                    consts.getNamespace(),
                    SPConstants.SC13_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc13SecurityContextToken(true);
            }

            Element bootstrapPolicyElement = DOMUtils.getFirstChildWithName(elem, 
                                                                            consts.getNamespace(),
                                                                            SPConstants.BOOTSTRAP_POLICY);
            if (bootstrapPolicyElement != null) {
                Policy policy = builder.getPolicy(DOMUtils.getFirstElement(bootstrapPolicyElement));
                conversationToken.setBootstrapPolicy(policy);
            }

        } else if (consts.getNamespace().equals(qn.getNamespaceURI())
            && SPConstants.ISSUER.equals(qn.getLocalPart())) {
            conversationToken.setIssuerEpr(DOMUtils.getFirstElement(elem));                
        }
        elem = DOMUtils.getNextElement(elem);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:SecureConversationToken/wsp:Policy must have a value"
        );
    }
    
    return conversationToken;
}
 
Example 14
Source File: SupportingTokens12Builder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    QName name = DOMUtils.getElementQName(element);
    SupportingToken supportingToken = null;

    if (SP12Constants.SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SUPPORTING,
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    }

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), supportingToken);
        /*
         * for the moment we will say there should be only one alternative 
         */
        break;            
    }

    return supportingToken;
}
 
Example 15
Source File: SpnegoContextTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
    
    SpnegoContextToken spnegoContextToken = new SpnegoContextToken(consts);
    spnegoContextToken.setOptional(PolicyConstants.isOptional(element));
    spnegoContextToken.setIgnorable(PolicyConstants.isIgnorable(element));
    
    String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
    if (attribute != null) {
        spnegoContextToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
    }

    Element elem = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    while (elem != null) {
        QName qn = DOMUtils.getElementQName(elem);
        if (Constants.isPolicyElement(qn)) {
            foundPolicy = true;
            if (DOMUtils.getFirstChildWithName(elem, consts.getNamespace(),
                    SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                spnegoContextToken.setDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                    SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
                spnegoContextToken.setImpliedDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                    SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
                spnegoContextToken.setExplicitDerivedKeys(true);
            }
        } else if (consts.getNamespace().equals(qn.getNamespaceURI())
                && SPConstants.ISSUER.equals(qn.getLocalPart())) {
            spnegoContextToken.setIssuerEpr(DOMUtils.getFirstElement(elem));
        }
        elem = DOMUtils.getNextElement(elem);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:SpnegoContextToken/wsp:Policy must have a value"
        );
    }
    return spnegoContextToken;
}
 
Example 16
Source File: SecureConversationTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
    
    
    SecureConversationToken conversationToken = new SecureConversationToken(consts);
    conversationToken.setOptional(PolicyConstants.isOptional(element));
    conversationToken.setIgnorable(PolicyConstants.isIgnorable(element));

    String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
    if (attribute != null) {
        conversationToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
    }
    
    Element elem = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    while (elem != null) {
        QName qn = DOMUtils.getElementQName(elem);
        if (Constants.isPolicyElement(qn)) {
            foundPolicy = true;
            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                conversationToken.setDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_IMPLIED_DERIVED_KEYS) 
                                                      != null) {
                conversationToken.setImpliedDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_EXPLICIT_DERIVED_KEYS)
                                                          != null) {
                conversationToken.setExplicitDerivedKeys(true);
            }


            if (DOMUtils.getFirstChildWithName(elem,
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE) != null) {
                conversationToken.setRequireExternalUriRef(true);
            }

            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc10SecurityContextToken(true);
            }
            
            if (DOMUtils.getFirstChildWithName(elem, 
                    consts.getNamespace(),
                    SPConstants.SC13_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc13SecurityContextToken(true);
            }

            Element bootstrapPolicyElement = DOMUtils.getFirstChildWithName(elem, 
                                                                            consts.getNamespace(),
                                                                            SPConstants.BOOTSTRAP_POLICY);
            if (bootstrapPolicyElement != null) {
                Policy policy = builder.getPolicy(DOMUtils.getFirstElement(bootstrapPolicyElement));
                conversationToken.setBootstrapPolicy(policy);
            }

        } else if (consts.getNamespace().equals(qn.getNamespaceURI())
            && SPConstants.ISSUER.equals(qn.getLocalPart())) {
            conversationToken.setIssuerEpr(DOMUtils.getFirstElement(elem));                
        }
        elem = DOMUtils.getNextElement(elem);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:SecureConversationToken/wsp:Policy must have a value"
        );
    }
    
    return conversationToken;
}
 
Example 17
Source File: SupportingTokens12Builder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    QName name = DOMUtils.getElementQName(element);
    SupportingToken supportingToken = null;

    if (SP12Constants.SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SUPPORTING,
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    }

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), supportingToken);
        /*
         * for the moment we will say there should be only one alternative 
         */
        break;            
    }

    return supportingToken;
}
 
Example 18
Source File: SecureConversationTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
    
    
    SecureConversationToken conversationToken = new SecureConversationToken(consts);
    conversationToken.setOptional(PolicyConstants.isOptional(element));
    conversationToken.setIgnorable(PolicyConstants.isIgnorable(element));

    String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
    if (attribute != null) {
        conversationToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
    }
    
    Element elem = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    while (elem != null) {
        QName qn = DOMUtils.getElementQName(elem);
        if (Constants.isPolicyElement(qn)) {
            foundPolicy = true;
            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                conversationToken.setDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_IMPLIED_DERIVED_KEYS) 
                                                      != null) {
                conversationToken.setImpliedDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_EXPLICIT_DERIVED_KEYS)
                                                          != null) {
                conversationToken.setExplicitDerivedKeys(true);
            }


            if (DOMUtils.getFirstChildWithName(elem,
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE) != null) {
                conversationToken.setRequireExternalUriRef(true);
            }

            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc10SecurityContextToken(true);
            }
            
            if (DOMUtils.getFirstChildWithName(elem, 
                    consts.getNamespace(),
                    SPConstants.SC13_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc13SecurityContextToken(true);
            }

            Element bootstrapPolicyElement = DOMUtils.getFirstChildWithName(elem, 
                                                                            consts.getNamespace(),
                                                                            SPConstants.BOOTSTRAP_POLICY);
            if (bootstrapPolicyElement != null) {
                Policy policy = builder.getPolicy(DOMUtils.getFirstElement(bootstrapPolicyElement));
                conversationToken.setBootstrapPolicy(policy);
            }

        } else if (consts.getNamespace().equals(qn.getNamespaceURI())
            && SPConstants.ISSUER.equals(qn.getLocalPart())) {
            conversationToken.setIssuerEpr(DOMUtils.getFirstElement(elem));                
        }
        elem = DOMUtils.getNextElement(elem);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:SecureConversationToken/wsp:Policy must have a value"
        );
    }
    
    return conversationToken;
}
 
Example 19
Source File: SupportingTokens12Builder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    QName name = DOMUtils.getElementQName(element);
    SupportingToken supportingToken = null;

    if (SP12Constants.SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SUPPORTING,
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    }

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), supportingToken);
        /*
         * for the moment we will say there should be only one alternative 
         */
        break;            
    }

    return supportingToken;
}
 
Example 20
Source File: SecureConversationTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
    
    
    SecureConversationToken conversationToken = new SecureConversationToken(consts);
    conversationToken.setOptional(PolicyConstants.isOptional(element));
    conversationToken.setIgnorable(PolicyConstants.isIgnorable(element));

    String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
    if (attribute != null) {
        conversationToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
    }
    
    Element elem = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    while (elem != null) {
        QName qn = DOMUtils.getElementQName(elem);
        if (Constants.isPolicyElement(qn)) {
            foundPolicy = true;
            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                conversationToken.setDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_IMPLIED_DERIVED_KEYS) 
                                                      != null) {
                conversationToken.setImpliedDerivedKeys(true);
            } else if (DOMUtils.getFirstChildWithName(elem, 
                                                      SP12Constants
                                                          .REQUIRE_EXPLICIT_DERIVED_KEYS)
                                                          != null) {
                conversationToken.setExplicitDerivedKeys(true);
            }


            if (DOMUtils.getFirstChildWithName(elem,
                                               consts.getNamespace(),
                                               SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE) != null) {
                conversationToken.setRequireExternalUriRef(true);
            }

            if (DOMUtils.getFirstChildWithName(elem, 
                                               consts.getNamespace(),
                                               SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc10SecurityContextToken(true);
            }
            
            if (DOMUtils.getFirstChildWithName(elem, 
                    consts.getNamespace(),
                    SPConstants.SC13_SECURITY_CONTEXT_TOKEN) != null) {
                conversationToken.setSc13SecurityContextToken(true);
            }

            Element bootstrapPolicyElement = DOMUtils.getFirstChildWithName(elem, 
                                                                            consts.getNamespace(),
                                                                            SPConstants.BOOTSTRAP_POLICY);
            if (bootstrapPolicyElement != null) {
                Policy policy = builder.getPolicy(DOMUtils.getFirstElement(bootstrapPolicyElement));
                conversationToken.setBootstrapPolicy(policy);
            }

        } else if (consts.getNamespace().equals(qn.getNamespaceURI())
            && SPConstants.ISSUER.equals(qn.getLocalPart())) {
            conversationToken.setIssuerEpr(DOMUtils.getFirstElement(elem));                
        }
        elem = DOMUtils.getNextElement(elem);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:SecureConversationToken/wsp:Policy must have a value"
        );
    }
    
    return conversationToken;
}