Java Code Examples for org.apache.cxf.helpers.DOMUtils#getAttribute()

The following examples show how to use org.apache.cxf.helpers.DOMUtils#getAttribute() . 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: ContentEncryptedElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    
    ContentEncryptedElements contentEncryptedElements 
        = new ContentEncryptedElements(SP12Constants.INSTANCE);
    String attrXPathVersion = DOMUtils.getAttribute(element, SP12Constants.ATTR_XPATH_VERSION);
    
    if (attrXPathVersion != null) {
        contentEncryptedElements.setXPathVersion(attrXPathVersion);
    }
    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, contentEncryptedElements);                
        }
        nd = nd.getNextSibling();
    }
    
    return contentEncryptedElements;
}
 
Example 2
Source File: ContentEncryptedElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    
    ContentEncryptedElements contentEncryptedElements 
        = new ContentEncryptedElements(SP12Constants.INSTANCE);
    String attrXPathVersion = DOMUtils.getAttribute(element, SP12Constants.ATTR_XPATH_VERSION);
    
    if (attrXPathVersion != null) {
        contentEncryptedElements.setXPathVersion(attrXPathVersion);
    }
    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, contentEncryptedElements);                
        }
        nd = nd.getNextSibling();
    }
    
    return contentEncryptedElements;
}
 
Example 3
Source File: ContentEncryptedElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    
    ContentEncryptedElements contentEncryptedElements 
        = new ContentEncryptedElements(SP12Constants.INSTANCE);
    String attrXPathVersion = DOMUtils.getAttribute(element, SP12Constants.ATTR_XPATH_VERSION);
    
    if (attrXPathVersion != null) {
        contentEncryptedElements.setXPathVersion(attrXPathVersion);
    }
    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, contentEncryptedElements);                
        }
        nd = nd.getNextSibling();
    }
    
    return contentEncryptedElements;
}
 
Example 4
Source File: ContentEncryptedElementsBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    
    ContentEncryptedElements contentEncryptedElements 
        = new ContentEncryptedElements(SP12Constants.INSTANCE);
    String attrXPathVersion = DOMUtils.getAttribute(element, SP12Constants.ATTR_XPATH_VERSION);
    
    if (attrXPathVersion != null) {
        contentEncryptedElements.setXPathVersion(attrXPathVersion);
    }
    Node nd = element.getFirstChild();
    while (nd != null) {
        if (nd instanceof Element) {
            processElement((Element)nd, contentEncryptedElements);                
        }
        nd = nd.getNextSibling();
    }
    
    return contentEncryptedElements;
}
 
Example 5
Source File: HttpsTokenBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Assertion build(Element element, AssertionBuilderFactory factory) {
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    
    HttpsToken httpsToken = new HttpsToken(consts);
    httpsToken.setOptional(PolicyConstants.isOptional(element));
    httpsToken.setIgnorable(PolicyConstants.isIgnorable(element));

    if (consts.getVersion() == SPConstants.Version.SP_V11) {
        String attr = DOMUtils.getAttribute(element, SPConstants.REQUIRE_CLIENT_CERTIFICATE);
        if (attr != null) {
            httpsToken.setRequireClientCertificate("true".equals(attr));
        }
    } else {
        Element polEl = PolicyConstants.findPolicyElement(element);
        if (polEl == null) {
            LOG.warning("sp:HttpsToken/wsp:Policy should have a value!");
        } else {
            Element child = DOMUtils.getFirstElement(polEl);
            if (child != null) {
                if (SP12Constants.HTTP_BASIC_AUTHENTICATION.equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpBasicAuthentication(true);
                } else if (SP12Constants.HTTP_DIGEST_AUTHENTICATION
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpDigestAuthentication(true);
                } else if (SP12Constants.REQUIRE_CLIENT_CERTIFICATE
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setRequireClientCertificate(true);
                }
            }
        }
    }

    return httpsToken;
}
 
Example 6
Source File: HttpsTokenBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Assertion build(Element element, AssertionBuilderFactory factory) {
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    
    HttpsToken httpsToken = new HttpsToken(consts);
    httpsToken.setOptional(PolicyConstants.isOptional(element));
    httpsToken.setIgnorable(PolicyConstants.isIgnorable(element));

    if (consts.getVersion() == SPConstants.Version.SP_V11) {
        String attr = DOMUtils.getAttribute(element, SPConstants.REQUIRE_CLIENT_CERTIFICATE);
        if (attr != null) {
            httpsToken.setRequireClientCertificate("true".equals(attr));
        }
    } else {
        Element polEl = PolicyConstants.findPolicyElement(element);
        if (polEl == null) {
            LOG.warning("sp:HttpsToken/wsp:Policy should have a value!");
        } else {
            Element child = DOMUtils.getFirstElement(polEl);
            if (child != null) {
                if (SP12Constants.HTTP_BASIC_AUTHENTICATION.equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpBasicAuthentication(true);
                } else if (SP12Constants.HTTP_DIGEST_AUTHENTICATION
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpDigestAuthentication(true);
                } else if (SP12Constants.REQUIRE_CLIENT_CERTIFICATE
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setRequireClientCertificate(true);
                }
            }
        }
    }

    return httpsToken;
}
 
Example 7
Source File: HttpsTokenBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Assertion build(Element element, AssertionBuilderFactory factory) {
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    
    HttpsToken httpsToken = new HttpsToken(consts);
    httpsToken.setOptional(PolicyConstants.isOptional(element));
    httpsToken.setIgnorable(PolicyConstants.isIgnorable(element));

    if (consts.getVersion() == SPConstants.Version.SP_V11) {
        String attr = DOMUtils.getAttribute(element, SPConstants.REQUIRE_CLIENT_CERTIFICATE);
        if (attr != null) {
            httpsToken.setRequireClientCertificate("true".equals(attr));
        }
    } else {
        Element polEl = PolicyConstants.findPolicyElement(element);
        if (polEl == null) {
            LOG.warning("sp:HttpsToken/wsp:Policy should have a value!");
        } else {
            Element child = DOMUtils.getFirstElement(polEl);
            if (child != null) {
                if (SP12Constants.HTTP_BASIC_AUTHENTICATION.equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpBasicAuthentication(true);
                } else if (SP12Constants.HTTP_DIGEST_AUTHENTICATION
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpDigestAuthentication(true);
                } else if (SP12Constants.REQUIRE_CLIENT_CERTIFICATE
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setRequireClientCertificate(true);
                }
            }
        }
    }

    return httpsToken;
}
 
Example 8
Source File: HttpsTokenBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Assertion build(Element element, AssertionBuilderFactory factory) {
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    
    HttpsToken httpsToken = new HttpsToken(consts);
    httpsToken.setOptional(PolicyConstants.isOptional(element));
    httpsToken.setIgnorable(PolicyConstants.isIgnorable(element));

    if (consts.getVersion() == SPConstants.Version.SP_V11) {
        String attr = DOMUtils.getAttribute(element, SPConstants.REQUIRE_CLIENT_CERTIFICATE);
        if (attr != null) {
            httpsToken.setRequireClientCertificate("true".equals(attr));
        }
    } else {
        Element polEl = PolicyConstants.findPolicyElement(element);
        if (polEl == null) {
            LOG.warning("sp:HttpsToken/wsp:Policy should have a value!");
        } else {
            Element child = DOMUtils.getFirstElement(polEl);
            if (child != null) {
                if (SP12Constants.HTTP_BASIC_AUTHENTICATION.equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpBasicAuthentication(true);
                } else if (SP12Constants.HTTP_DIGEST_AUTHENTICATION
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setHttpDigestAuthentication(true);
                } else if (SP12Constants.REQUIRE_CLIENT_CERTIFICATE
                        .equals(DOMUtils.getElementQName(child))) {
                    httpsToken.setRequireClientCertificate(true);
                }
            }
        }
    }

    return httpsToken;
}
 
Example 9
Source File: SecurityContextTokenBuilder.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;

    SecurityContextToken contextToken = new SecurityContextToken(consts);

    String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());

    if (includeAttr != null) {
        contextToken.setInclusion(consts.getInclusionFromAttributeValue(includeAttr));
    }

    element = PolicyConstants.findPolicyElement(element);
    if (element == null && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:SecurityContextToken/wsp:Policy must have a value"
        );
    }

    if (element != null) {
        if (DOMUtils.getFirstChildWithName(element, 
                consts.getNamespace(),
                SPConstants.REQUIRE_DERIVED_KEYS) != null) {
            contextToken.setDerivedKeys(true);
        }

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

        if (DOMUtils.getFirstChildWithName(element,
                consts.getNamespace(),
                SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
            contextToken.setSc10SecurityContextToken(true);
        }

        if (DOMUtils.getFirstChildWithName(element,
                consts.getNamespace(),
                SPConstants.SC13_SECURITY_CONTEXT_TOKEN) != null) {
            contextToken.setSc13SecurityContextToken(true);
        }
    }

    return contextToken;
}
 
Example 10
Source File: X509TokenBuilder.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;
    X509Token x509Token = new X509Token(consts);
    x509Token.setOptional(PolicyConstants.isOptional(element));
    x509Token.setIgnorable(PolicyConstants.isIgnorable(element));

    Element policyElement = DOMUtils.getFirstElement(element);
    if (policyElement == null && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:X509Token/wsp:Policy must have a value"
        );
    }

    // Process token inclusion
    String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());

    if (includeAttr != null) {
        SPConstants.IncludeTokenType inclusion 
            = consts.getInclusionFromAttributeValue(includeAttr);
        x509Token.setInclusion(inclusion);
    }

    if (policyElement != null) {
        if (DOMUtils.getFirstChildWithName(policyElement, consts.getRequiredDerivedKeys()) != null) {
            x509Token.setDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
            x509Token.setImpliedDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
            x509Token.setExplicitDerivedKeys(true);
        }
    }

    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(), x509Token, consts);

        /*
         * since there should be only one alternative
         */
        break;
    }
    return x509Token;
}
 
Example 11
Source File: X509TokenBuilder.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;
    X509Token x509Token = new X509Token(consts);
    x509Token.setOptional(PolicyConstants.isOptional(element));
    x509Token.setIgnorable(PolicyConstants.isIgnorable(element));

    Element policyElement = DOMUtils.getFirstElement(element);
    if (policyElement == null && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:X509Token/wsp:Policy must have a value"
        );
    }

    // Process token inclusion
    String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());

    if (includeAttr != null) {
        SPConstants.IncludeTokenType inclusion 
            = consts.getInclusionFromAttributeValue(includeAttr);
        x509Token.setInclusion(inclusion);
    }

    if (policyElement != null) {
        if (DOMUtils.getFirstChildWithName(policyElement, consts.getRequiredDerivedKeys()) != null) {
            x509Token.setDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
            x509Token.setImpliedDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
            x509Token.setExplicitDerivedKeys(true);
        }
    }

    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(), x509Token, consts);

        /*
         * since there should be only one alternative
         */
        break;
    }
    return x509Token;
}
 
Example 12
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 13
Source File: IssuedTokenBuilder.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;


    IssuedToken issuedToken = new IssuedToken(consts);
    issuedToken.setOptional(PolicyConstants.isOptional(element));
    issuedToken.setIgnorable(PolicyConstants.isIgnorable(element));

    String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());
    if (includeAttr != null) {
        issuedToken.setInclusion(consts.getInclusionFromAttributeValue(includeAttr));
    }
    
    Element child = DOMUtils.getFirstElement(element);
    boolean foundPolicy = false;
    boolean foundRST = false;
    while (child != null) {
        String ln = child.getLocalName();
        if (SPConstants.ISSUER.equals(ln)) {
            try {
                EndpointReferenceType epr = VersionTransformer.parseEndpointReference(child);
                issuedToken.setIssuerEpr(epr);
            } catch (JAXBException e) {
                throw new IllegalArgumentException(e);
            }
        } else if (SPConstants.REQUEST_SECURITY_TOKEN_TEMPLATE.equals(ln)) {
            foundRST = true;
            issuedToken.setRstTemplate(child);
        } else if (org.apache.neethi.Constants.ELEM_POLICY.equals(ln)) {
            foundPolicy = true;
            Policy policy = builder.getPolicy(child);
            policy = policy.normalize(builder.getPolicyRegistry(), false);

            for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
                processAlternative(iterator.next(), issuedToken);
                break; // since there should be only one alternative ..
            }                
        } else if (SPConstants.ISSUER_NAME.equals(ln)) {
            String issuerName = child.getNodeValue();
            issuedToken.setIssuerName(issuerName);
        }
        
        child = DOMUtils.getNextElement(child);
    }
    
    if (!foundPolicy && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:IssuedToken/wsp:Policy must have a value"
        );
    }
    if (!foundRST) {
        throw new IllegalArgumentException(
            "sp:IssuedToken/sp:RequestSecurityTokenTemplate must have a value"
        );
    }
    
    return issuedToken;
}
 
Example 14
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 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: 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 17
Source File: X509TokenBuilder.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;
    X509Token x509Token = new X509Token(consts);
    x509Token.setOptional(PolicyConstants.isOptional(element));
    x509Token.setIgnorable(PolicyConstants.isIgnorable(element));

    Element policyElement = DOMUtils.getFirstElement(element);
    if (policyElement == null && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:X509Token/wsp:Policy must have a value"
        );
    }

    // Process token inclusion
    String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());

    if (includeAttr != null) {
        SPConstants.IncludeTokenType inclusion 
            = consts.getInclusionFromAttributeValue(includeAttr);
        x509Token.setInclusion(inclusion);
    }

    if (policyElement != null) {
        if (DOMUtils.getFirstChildWithName(policyElement, consts.getRequiredDerivedKeys()) != null) {
            x509Token.setDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
            x509Token.setImpliedDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
            x509Token.setExplicitDerivedKeys(true);
        }
    }

    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(), x509Token, consts);

        /*
         * since there should be only one alternative
         */
        break;
    }
    return x509Token;
}
 
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: X509TokenBuilder.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;
    X509Token x509Token = new X509Token(consts);
    x509Token.setOptional(PolicyConstants.isOptional(element));
    x509Token.setIgnorable(PolicyConstants.isIgnorable(element));

    Element policyElement = DOMUtils.getFirstElement(element);
    if (policyElement == null && consts != SP11Constants.INSTANCE) {
        throw new IllegalArgumentException(
            "sp:X509Token/wsp:Policy must have a value"
        );
    }

    // Process token inclusion
    String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());

    if (includeAttr != null) {
        SPConstants.IncludeTokenType inclusion 
            = consts.getInclusionFromAttributeValue(includeAttr);
        x509Token.setInclusion(inclusion);
    }

    if (policyElement != null) {
        if (DOMUtils.getFirstChildWithName(policyElement, consts.getRequiredDerivedKeys()) != null) {
            x509Token.setDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
            x509Token.setImpliedDerivedKeys(true);
        } else if (DOMUtils.getFirstChildWithName(policyElement, 
                SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
            x509Token.setExplicitDerivedKeys(true);
        }
    }

    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(), x509Token, consts);

        /*
         * since there should be only one alternative
         */
        break;
    }
    return x509Token;
}
 
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;
}