Search in sources :

Example 1 with SAMLAssertionWriter

use of org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter 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 2 with SAMLAssertionWriter

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

the class AssertionUtil method asString.

/**
 * Given {@code AssertionType}, convert it into a String
 *
 * @param assertion
 *
 * @return
 *
 * @throws ProcessingException
 */
public static String asString(AssertionType assertion) throws ProcessingException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
    writer.write(assertion);
    return new String(baos.toByteArray(), GeneralConstants.SAML_CHARSET);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAMLAssertionWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter)

Example 3 with SAMLAssertionWriter

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

the class AssertionUtil method asDocument.

/**
 * Given {@code AssertionType}, convert it into a DOM Document.
 *
 * @param assertion
 *
 * @return
 *
 * @throws ProcessingException
 */
public static Document asDocument(AssertionType assertion) throws ProcessingException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
    writer.write(assertion);
    try {
        return DocumentUtil.getDocument(new ByteArrayInputStream(baos.toByteArray()));
    } catch (Exception e) {
        throw logger.processingError(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAMLAssertionWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter) ParsingException(org.keycloak.saml.common.exceptions.ParsingException) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException) ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) IssueInstantMissingException(org.keycloak.saml.common.exceptions.fed.IssueInstantMissingException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 SAMLAssertionWriter (org.keycloak.saml.processing.core.saml.v2.writers.SAMLAssertionWriter)3 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)1 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)1 ArtifactResponseType (org.keycloak.dom.saml.v2.protocol.ArtifactResponseType)1 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)1 ConfigurationException (org.keycloak.saml.common.exceptions.ConfigurationException)1 ParsingException (org.keycloak.saml.common.exceptions.ParsingException)1 IssueInstantMissingException (org.keycloak.saml.common.exceptions.fed.IssueInstantMissingException)1 SAMLResponseWriter (org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter)1