Search in sources :

Example 1 with URIType

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

URI (java.net.URI)1 AuthnContextClassRefType (org.keycloak.dom.saml.v2.assertion.AuthnContextClassRefType)1 AuthnContextDeclRefType (org.keycloak.dom.saml.v2.assertion.AuthnContextDeclRefType)1 AuthnContextDeclType (org.keycloak.dom.saml.v2.assertion.AuthnContextDeclType)1 AuthnContextType (org.keycloak.dom.saml.v2.assertion.AuthnContextType)1 URIType (org.keycloak.dom.saml.v2.assertion.URIType)1 ASSERTION_NSURI (org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)1