Search in sources :

Example 1 with AuthnContextDeclRefType

use of org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType in project keycloak by keycloak.

the class SAMLAuthnContextParser method processSubElement.

@Override
protected void processSubElement(XMLEventReader xmlEventReader, AuthnContextType target, SAMLAssertionQNames element, StartElement elementDetail) throws ParsingException {
    String text;
    AuthnContextType.AuthnContextTypeSequence authnContextSequence;
    switch(element) {
        case AUTHN_CONTEXT_DECL:
            Element dom = StaxParserUtil.getDOMElement(xmlEventReader);
            AuthnContextDeclType authnContextDecl = new AuthnContextDeclType(dom);
            authnContextSequence = target.getSequence() != null ? target.getSequence() : new AuthnContextType.AuthnContextTypeSequence();
            authnContextSequence.setAuthnContextDecl(authnContextDecl);
            target.setSequence(authnContextSequence);
            break;
        case AUTHN_CONTEXT_DECL_REF:
            StaxParserUtil.advance(xmlEventReader);
            text = StaxParserUtil.getElementText(xmlEventReader);
            AuthnContextDeclRefType authnContextDeclRef = new AuthnContextDeclRefType(URI.create(text));
            target.addURIType(authnContextDeclRef);
            break;
        case AUTHN_CONTEXT_CLASS_REF:
            StaxParserUtil.advance(xmlEventReader);
            text = StaxParserUtil.getElementText(xmlEventReader);
            AuthnContextClassRefType authnContextClassRef = new AuthnContextClassRefType(URI.create(text));
            authnContextSequence = target.getSequence() != null ? target.getSequence() : new AuthnContextType.AuthnContextTypeSequence();
            authnContextSequence.setClassRef(authnContextClassRef);
            target.setSequence(authnContextSequence);
            break;
        case AUTHENTICATING_AUTHORITY:
            StaxParserUtil.advance(xmlEventReader);
            text = StaxParserUtil.getElementText(xmlEventReader);
            target.addAuthenticatingAuthority(URI.create(text));
            break;
        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
Also used : AuthnContextClassRefType(org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType) AuthnContextDeclType(org.keycloak.dom.saml.v2.assertion.AuthnContextDeclType) Element(org.w3c.dom.Element) StartElement(javax.xml.stream.events.StartElement) AuthnContextDeclRefType(org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType) AuthnContextType(org.keycloak.dom.saml.v2.assertion.AuthnContextType)

Example 2 with AuthnContextDeclRefType

use of org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType in project keycloak by keycloak.

the class SAMLAssertionWriter method write.

/**
 * Write an {@code AuthnContextType} to stream
 *
 * @param authContext
 *
 * @throws ProcessingException
 */
public void write(AuthnContextType authContext) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT.get(), ASSERTION_NSURI.get());
    AuthnContextType.AuthnContextTypeSequence sequence = authContext.getSequence();
    if (sequence != null) {
        AuthnContextClassRefType authnContextClassRefType = sequence.getClassRef();
        if (authnContextClassRefType != null) {
            StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get(), ASSERTION_NSURI.get());
            StaxUtil.writeCharacters(writer, authnContextClassRefType.getValue().toASCIIString());
            StaxUtil.writeEndElement(writer);
        }
        Set<URIType> uriTypes = sequence.getURIType();
        if (uriTypes != null) {
            for (URIType uriType : uriTypes) {
                if (uriType instanceof AuthnContextDeclType) {
                    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL.get(), ASSERTION_NSURI.get());
                    StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
                    StaxUtil.writeEndElement(writer);
                }
                if (uriType instanceof AuthnContextDeclRefType) {
                    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL_REF.get(), ASSERTION_NSURI.get());
                    StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
                    StaxUtil.writeEndElement(writer);
                }
            }
        }
    }
    Set<URI> authAuthorities = authContext.getAuthenticatingAuthority();
    if (authAuthorities != null) {
        for (URI aa : authAuthorities) {
            StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHENTICATING_AUTHORITY.get(), ASSERTION_NSURI.get());
            StaxUtil.writeCharacters(writer, aa.toASCIIString());
            StaxUtil.writeEndElement(writer);
        }
    }
    Set<URIType> uriTypes = authContext.getURIType();
    for (URIType uriType : uriTypes) {
        if (uriType instanceof AuthnContextClassRefType) {
            StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get(), ASSERTION_NSURI.get());
            StaxUtil.writeCharacters(writer, uriType.getValue().toString());
            StaxUtil.writeEndElement(writer);
        } else if (uriType instanceof AuthnContextDeclRefType) {
            StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL_REF.get(), ASSERTION_NSURI.get());
            StaxUtil.writeCharacters(writer, uriType.getValue().toString());
            StaxUtil.writeEndElement(writer);
        } else if (uriType instanceof AuthnContextDeclType) {
            StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECL.get(), ASSERTION_NSURI.get());
            StaxUtil.writeCharacters(writer, uriType.getValue().toString());
            StaxUtil.writeEndElement(writer);
        }
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : AuthnContextClassRefType(org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType) AuthnContextDeclType(org.keycloak.dom.saml.v2.assertion.AuthnContextDeclType) AuthnContextDeclRefType(org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType) AuthnContextType(org.keycloak.dom.saml.v2.assertion.AuthnContextType) URIType(org.keycloak.dom.saml.v2.assertion.URIType) URI(java.net.URI) ASSERTION_NSURI(org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)

Aggregations

AuthnContextClassRefType (org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType)2 AuthnContextDeclRefType (org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType)2 AuthnContextDeclType (org.keycloak.dom.saml.v2.assertion.AuthnContextDeclType)2 AuthnContextType (org.keycloak.dom.saml.v2.assertion.AuthnContextType)2 URI (java.net.URI)1 StartElement (javax.xml.stream.events.StartElement)1 URIType (org.keycloak.dom.saml.v2.assertion.URIType)1 ASSERTION_NSURI (org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)1 Element (org.w3c.dom.Element)1