Search in sources :

Example 6 with SAMLResponseWriter

use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter in project keycloak by keycloak.

the class SAMLDataMarshaller method serialize.

@Override
public String serialize(Object obj) {
    // Lame impl, but hopefully sufficient for now. See if something better is needed...
    if (obj.getClass().getName().startsWith("org.keycloak.dom.saml")) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            if (obj instanceof ResponseType) {
                ResponseType responseType = (ResponseType) obj;
                SAMLResponseWriter samlWriter = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(bos));
                samlWriter.write(responseType);
            } else if (obj instanceof AssertionType) {
                AssertionType assertion = (AssertionType) obj;
                SAMLAssertionWriter samlWriter = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(bos));
                samlWriter.write(assertion);
            } else if (obj instanceof AuthnStatementType) {
                AuthnStatementType authnStatement = (AuthnStatementType) obj;
                SAMLAssertionWriter samlWriter = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(bos));
                samlWriter.write(authnStatement, true);
            } else if (obj instanceof ArtifactResponseType) {
                ArtifactResponseType artifactResponseType = (ArtifactResponseType) obj;
                SAMLResponseWriter samlWriter = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(bos));
                samlWriter.write(artifactResponseType);
            } else {
                throw new IllegalArgumentException("Don't know how to serialize object of type " + obj.getClass().getName());
            }
        } catch (ProcessingException pe) {
            throw new RuntimeException(pe);
        }
        return new String(bos.toByteArray(), GeneralConstants.SAML_CHARSET);
    } else {
        return super.serialize(obj);
    }
}
Also used : AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) SAMLResponseWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter) ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) SAMLAssertionWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter) ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Example 7 with SAMLResponseWriter

use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter in project keycloak by keycloak.

the class SAML2Request method convert.

/**
 * Convert a SAML2 Response into a Document
 *
 * @param responseType
 *
 * @return
 *
 * @throws ProcessingException
 * @throws ParsingException
 * @throws ConfigurationException
 */
public static Document convert(ResponseType responseType) throws ProcessingException, ParsingException, ConfigurationException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SAMLResponseWriter writer = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
    writer.write(responseType);
    ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
    return DocumentUtil.getDocument(bis);
}
Also used : SAMLResponseWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with SAMLResponseWriter

use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter in project keycloak by keycloak.

the class SAML2Response method marshall.

/**
 * Marshall the ResponseType into a writer
 *
 * @param responseType
 * @param writer
 *
 * @throws ProcessingException
 */
public void marshall(ResponseType responseType, Writer writer) throws ProcessingException {
    SAMLResponseWriter samlWriter = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(writer));
    samlWriter.write(responseType);
}
Also used : SAMLResponseWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter)

Aggregations

SAMLResponseWriter (org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)4 ArtifactResponseType (org.keycloak.dom.saml.v2.protocol.ArtifactResponseType)3 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)2 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)2 QName (javax.xml.namespace.QName)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)1 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)1 ArtifactResolveType (org.keycloak.dom.saml.v2.protocol.ArtifactResolveType)1 AttributeQueryType (org.keycloak.dom.saml.v2.protocol.AttributeQueryType)1 AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)1 LogoutRequestType (org.keycloak.dom.saml.v2.protocol.LogoutRequestType)1 SAML2LoginResponseBuilder (org.keycloak.saml.SAML2LoginResponseBuilder)1 SAMLAssertionWriter (org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter)1 SAMLRequestWriter (org.keycloak.saml.processing.core.saml.v2.writers.SAMLRequestWriter)1