Search in sources :

Example 6 with ExtensionsType

use of org.keycloak.dom.saml.v2.protocol.ExtensionsType in project keycloak by keycloak.

the class SAMLRequestWriter method write.

/**
 * Write a {@code AuthnRequestType } to stream
 *
 * @param request
 *
 * @throws org.keycloak.saml.common.exceptions.ProcessingException
 */
public void write(AuthnRequestType request) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.AUTHN_REQUEST.get(), PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
    StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
    // Attributes
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
    URI destination = request.getDestination();
    if (destination != null)
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
    String consent = request.getConsent();
    if (StringUtil.isNotNull(consent))
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
    URI assertionURL = request.getAssertionConsumerServiceURL();
    if (assertionURL != null)
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_URL.get(), assertionURL.toASCIIString());
    Boolean forceAuthn = request.isForceAuthn();
    if (forceAuthn != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.FORCE_AUTHN.get(), forceAuthn.toString());
    }
    Boolean isPassive = request.isIsPassive();
    // maximize compatibility we emit it only if it is set to true
    if (isPassive != null && isPassive == true) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.IS_PASSIVE.get(), isPassive.toString());
    }
    URI protocolBinding = request.getProtocolBinding();
    if (protocolBinding != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROTOCOL_BINDING.get(), protocolBinding.toString());
    }
    Integer assertionIndex = request.getAssertionConsumerServiceIndex();
    if (assertionIndex != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_INDEX.get(), assertionIndex.toString());
    }
    Integer attrIndex = request.getAttributeConsumingServiceIndex();
    if (attrIndex != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.ATTRIBUTE_CONSUMING_SERVICE_INDEX.get(), attrIndex.toString());
    }
    String providerName = request.getProviderName();
    if (StringUtil.isNotNull(providerName)) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROVIDER_NAME.get(), providerName);
    }
    NameIDType issuer = request.getIssuer();
    if (issuer != null) {
        write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX), false);
    }
    SubjectType subject = request.getSubject();
    if (subject != null) {
        write(subject);
    }
    Element sig = request.getSignature();
    if (sig != null) {
        StaxUtil.writeDOMElement(writer, sig);
    }
    ExtensionsType extensions = request.getExtensions();
    if (extensions != null && !extensions.getAny().isEmpty()) {
        write(extensions);
    }
    NameIDPolicyType nameIDPolicy = request.getNameIDPolicy();
    if (nameIDPolicy != null) {
        write(nameIDPolicy);
    }
    RequestedAuthnContextType requestedAuthnContext = request.getRequestedAuthnContext();
    if (requestedAuthnContext != null) {
        write(requestedAuthnContext);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType) NameIDPolicyType(org.keycloak.dom.saml.v2.protocol.NameIDPolicyType) RequestedAuthnContextType(org.keycloak.dom.saml.v2.protocol.RequestedAuthnContextType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) PROTOCOL_NSURI(org.keycloak.saml.common.constants.JBossSAMLURIConstants.PROTOCOL_NSURI) URI(java.net.URI) ASSERTION_NSURI(org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)

Example 7 with ExtensionsType

use of org.keycloak.dom.saml.v2.protocol.ExtensionsType in project keycloak by keycloak.

the class SAMLMetadataWriter method writeOrganization.

public void writeOrganization(OrganizationType org) throws ProcessingException {
    if (org == null)
        throw new ProcessingException(logger.nullArgumentError("Organization"));
    StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.ORGANIZATION.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
    ExtensionsType extensions = org.getExtensions();
    if (extensions != null) {
        write(extensions);
    }
    // Write the name
    List<LocalizedNameType> nameList = org.getOrganizationName();
    for (LocalizedNameType localName : nameList) {
        StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.ORGANIZATION_NAME.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
        writeLocalizedType(localName);
    }
    // Write the display name
    List<LocalizedNameType> displayNameList = org.getOrganizationDisplayName();
    for (LocalizedNameType localName : displayNameList) {
        StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.ORGANIZATION_DISPLAY_NAME.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
        writeLocalizedType(localName);
    }
    // Write the url
    List<LocalizedURIType> uriList = org.getOrganizationURL();
    for (LocalizedURIType uri : uriList) {
        StaxUtil.writeStartElement(writer, METADATA_PREFIX, JBossSAMLConstants.ORGANIZATION_URL.get(), JBossSAMLURIConstants.METADATA_NSURI.get());
        String lang = uri.getLang();
        String val = uri.getValue().toString();
        StaxUtil.writeAttribute(writer, new QName(JBossSAMLURIConstants.XML.get(), JBossSAMLConstants.LANG.get(), "xml"), lang);
        StaxUtil.writeCharacters(writer, val);
        StaxUtil.writeEndElement(writer);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : LocalizedURIType(org.keycloak.dom.saml.v2.metadata.LocalizedURIType) LocalizedNameType(org.keycloak.dom.saml.v2.metadata.LocalizedNameType) QName(javax.xml.namespace.QName) ExtensionsType(org.keycloak.dom.saml.v2.metadata.ExtensionsType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Example 8 with ExtensionsType

use of org.keycloak.dom.saml.v2.protocol.ExtensionsType in project keycloak by keycloak.

the class SAMLResponseWriter method write.

public void write(ArtifactResponseType response) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ARTIFACT_RESPONSE.get(), JBossSAMLURIConstants.PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, JBossSAMLURIConstants.PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, JBossSAMLURIConstants.ASSERTION_NSURI.get());
    StaxUtil.writeDefaultNameSpace(writer, JBossSAMLURIConstants.ASSERTION_NSURI.get());
    writeBaseAttributes(response);
    NameIDType issuer = response.getIssuer();
    if (issuer != null) {
        write(issuer, new QName(JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX));
    }
    Element sig = response.getSignature();
    if (sig != null) {
        StaxUtil.writeDOMElement(writer, sig);
    }
    ExtensionsType extensions = response.getExtensions();
    if (extensions != null && extensions.getAny() != null && !extensions.getAny().isEmpty()) {
        write(extensions);
    }
    StatusType status = response.getStatus();
    if (status != null) {
        write(status);
    }
    Object anyObj = response.getAny();
    if (anyObj instanceof AuthnRequestType) {
        AuthnRequestType authn = (AuthnRequestType) anyObj;
        SAMLRequestWriter requestWriter = new SAMLRequestWriter(writer);
        requestWriter.write(authn);
    } else if (anyObj instanceof LogoutRequestType) {
        LogoutRequestType logoutRequestType = (LogoutRequestType) anyObj;
        SAMLRequestWriter requestWriter = new SAMLRequestWriter(writer);
        requestWriter.write(logoutRequestType);
    } else if (anyObj instanceof ResponseType) {
        ResponseType rt = (ResponseType) anyObj;
        write(rt);
    } else if (anyObj instanceof StatusResponseType) {
        StatusResponseType rt = (StatusResponseType) anyObj;
        write(rt, new QName(PROTOCOL_NSURI.get(), JBossSAMLConstants.LOGOUT_RESPONSE.get(), "samlp"));
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) QName(javax.xml.namespace.QName) StatusType(org.keycloak.dom.saml.v2.protocol.StatusType) Element(org.w3c.dom.Element) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType) LogoutRequestType(org.keycloak.dom.saml.v2.protocol.LogoutRequestType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType)

Example 9 with ExtensionsType

use of org.keycloak.dom.saml.v2.protocol.ExtensionsType in project keycloak by keycloak.

the class SAMLResponseWriter method write.

/**
 * Write a {@code ResponseType} to stream
 *
 * @param response
 * @param out
 *
 * @throws org.keycloak.saml.common.exceptions.ProcessingException
 */
public void write(ResponseType response) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.RESPONSE__PROTOCOL.get(), JBossSAMLURIConstants.PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, JBossSAMLURIConstants.PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, JBossSAMLURIConstants.ASSERTION_NSURI.get());
    writeBaseAttributes(response);
    NameIDType issuer = response.getIssuer();
    if (issuer != null) {
        write(issuer, new QName(JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX));
    }
    ExtensionsType extensions = response.getExtensions();
    if (extensions != null && extensions.getAny() != null && !extensions.getAny().isEmpty()) {
        write(extensions);
    }
    StatusType status = response.getStatus();
    write(status);
    List<ResponseType.RTChoiceType> choiceTypes = response.getAssertions();
    if (choiceTypes != null) {
        for (ResponseType.RTChoiceType choiceType : choiceTypes) {
            AssertionType assertion = choiceType.getAssertion();
            if (assertion != null) {
                assertionWriter.write(assertion);
            }
            EncryptedAssertionType encryptedAssertion = choiceType.getEncryptedAssertion();
            if (encryptedAssertion != null) {
                Element encElement = encryptedAssertion.getEncryptedElement();
                StaxUtil.writeDOMElement(writer, encElement);
            }
        }
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : QName(javax.xml.namespace.QName) StatusType(org.keycloak.dom.saml.v2.protocol.StatusType) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType) Element(org.w3c.dom.Element) EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType)

Example 10 with ExtensionsType

use of org.keycloak.dom.saml.v2.protocol.ExtensionsType in project keycloak by keycloak.

the class SAML2AuthnRequestBuilder method createAuthnRequest.

public AuthnRequestType createAuthnRequest() {
    AuthnRequestType res = this.authnRequestType;
    res.setIssuer(issuer);
    res.setDestination(URI.create(this.destination));
    if (!this.extensions.isEmpty()) {
        ExtensionsType extensionsType = new ExtensionsType();
        for (NodeGenerator extension : this.extensions) {
            extensionsType.addExtension(extension);
        }
        res.setExtensions(extensionsType);
    }
    return res;
}
Also used : AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType)

Aggregations

ExtensionsType (org.keycloak.dom.saml.v2.protocol.ExtensionsType)12 Element (org.w3c.dom.Element)10 QName (javax.xml.namespace.QName)8 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)7 ExtensionsType (org.keycloak.dom.saml.v2.metadata.ExtensionsType)5 URI (java.net.URI)4 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)4 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)4 StatusType (org.keycloak.dom.saml.v2.protocol.StatusType)4 ASSERTION_NSURI (org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)4 PROTOCOL_NSURI (org.keycloak.saml.common.constants.JBossSAMLURIConstants.PROTOCOL_NSURI)4 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)2 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)2 SubjectType (org.keycloak.dom.saml.v2.assertion.SubjectType)2 EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)2 ArtifactResponseType (org.keycloak.dom.saml.v2.protocol.ArtifactResponseType)2 AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)2 LogoutRequestType (org.keycloak.dom.saml.v2.protocol.LogoutRequestType)2 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)2 SAML2Response (org.keycloak.saml.processing.api.saml.v2.response.SAML2Response)2