Search in sources :

Example 16 with ExtensionsType

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

the class SAMLRequestWriter method write.

/**
 * Write a {@code LogoutRequestType} to stream
 *
 * @param logOutRequest
 *
 * @throws ProcessingException
 */
public void write(LogoutRequestType logOutRequest) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.LOGOUT_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(), logOutRequest.getID());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), logOutRequest.getVersion());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), logOutRequest.getIssueInstant().toString());
    URI destination = logOutRequest.getDestination();
    if (destination != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
    }
    String consent = logOutRequest.getConsent();
    if (StringUtil.isNotNull(consent))
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
    NameIDType issuer = logOutRequest.getIssuer();
    write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX));
    Element signature = logOutRequest.getSignature();
    if (signature != null) {
        StaxUtil.writeDOMElement(writer, signature);
    }
    ExtensionsType extensions = logOutRequest.getExtensions();
    if (extensions != null && !extensions.getAny().isEmpty()) {
        write(extensions);
    }
    NameIDType nameID = logOutRequest.getNameID();
    if (nameID != null) {
        write(nameID, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
    }
    List<String> sessionIndexes = logOutRequest.getSessionIndex();
    for (String sessionIndex : sessionIndexes) {
        StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.SESSION_INDEX.get(), PROTOCOL_NSURI.get());
        StaxUtil.writeCharacters(writer, sessionIndex);
        StaxUtil.writeEndElement(writer);
        StaxUtil.flush(writer);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType) 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 17 with ExtensionsType

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

the class SAMLResponseWriter method write.

/**
 * Write a {@code StatusResponseType}
 *
 * @param response
 * @param qname QName of the starting element
 * @param out
 *
 * @throws ProcessingException
 */
public void write(StatusResponseType response, QName qname) throws ProcessingException {
    if (qname == null) {
        StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_RESPONSE_TYPE.get(), JBossSAMLURIConstants.PROTOCOL_NSURI.get());
    } else {
        StaxUtil.writeStartElement(writer, qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
    }
    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();
    write(issuer, new QName(JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
    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();
    write(status);
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : 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) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType)

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