Search in sources :

Example 1 with AuthnContextClassRefType

use of org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType 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 AuthnContextClassRefType

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

the class SAML2Response method createAuthnStatement.

/**
 * Create an AuthnStatement
 *
 * @param authnContextDeclRef such as JBossSAMLURIConstants.AC_PASSWORD_PROTECTED_TRANSPORT
 * @param issueInstant
 *
 * @return
 */
public AuthnStatementType createAuthnStatement(String authnContextDeclRef, XMLGregorianCalendar issueInstant) {
    AuthnStatementType authnStatement = new AuthnStatementType(issueInstant);
    AuthnContextType act = new AuthnContextType();
    String authContextDeclRef = JBossSAMLURIConstants.AC_PASSWORD_PROTECTED_TRANSPORT.get();
    act.addAuthenticatingAuthority(URI.create(authContextDeclRef));
    AuthnContextType.AuthnContextTypeSequence sequence = new AuthnContextType.AuthnContextTypeSequence();
    sequence.setClassRef(new AuthnContextClassRefType(JBossSAMLURIConstants.AC_PASSWORD.getUri()));
    act.setSequence(sequence);
    authnStatement.setAuthnContext(act);
    return authnStatement;
}
Also used : AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) AuthnContextClassRefType(org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType) AuthnContextType(org.keycloak.dom.saml.v2.assertion.AuthnContextType)

Example 3 with AuthnContextClassRefType

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

the class StatementUtil method createAuthnStatement.

/**
 * Create an AuthnStatementType given the issue instant and the type of authentication
 *
 * @param instant an instanceof {@link XMLGregorianCalendar}
 * @param authnContextClassRefValue indicate the type of authentication performed
 *
 * @return {@link AuthnStatementType}
 */
public static AuthnStatementType createAuthnStatement(XMLGregorianCalendar instant, String authnContextClassRefValue) {
    AuthnStatementType authnStatement = new AuthnStatementType(instant);
    AuthnContextType authnContext = new AuthnContextType();
    AuthnContextClassRefType authnContextClassRef = new AuthnContextClassRefType(URI.create(authnContextClassRefValue));
    AuthnContextType.AuthnContextTypeSequence sequence = new AuthnContextType.AuthnContextTypeSequence();
    sequence.setClassRef(authnContextClassRef);
    authnContext.setSequence(sequence);
    authnStatement.setAuthnContext(authnContext);
    return authnStatement;
}
Also used : AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) AuthnContextClassRefType(org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType) AuthnContextType(org.keycloak.dom.saml.v2.assertion.AuthnContextType)

Example 4 with AuthnContextClassRefType

use of org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType 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)4 AuthnContextType (org.keycloak.dom.saml.v2.assertion.AuthnContextType)4 AuthnContextDeclRefType (org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType)2 AuthnContextDeclType (org.keycloak.dom.saml.v2.assertion.AuthnContextDeclType)2 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)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