Search in sources :

Example 1 with SAML2Response

use of org.keycloak.saml.processing.api.saml.v2.response.SAML2Response in project keycloak by keycloak.

the class SAMLParserTest method assertParsed.

private <T> T assertParsed(String fileName, Class<T> expectedType) throws IOException, ParsingException, ConfigurationException, ProcessingException {
    try (InputStream st = SAMLParserTest.class.getResourceAsStream(fileName)) {
        Object parsedObject;
        if (SAML2Object.class.isAssignableFrom(expectedType)) {
            parsedObject = new SAML2Response().getSAML2ObjectFromStream(st);
        } else if (SAMLDocumentHolder.class.isAssignableFrom(expectedType)) {
            parsedObject = SAML2Request.getSAML2ObjectFromStream(st);
        } else {
            parsedObject = parser.parse(st);
        }
        assertThat(parsedObject, instanceOf(expectedType));
        return expectedType.cast(parsedObject);
    }
}
Also used : SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SAML2Object(org.keycloak.dom.saml.v2.SAML2Object) SAML2Response(org.keycloak.saml.processing.api.saml.v2.response.SAML2Response)

Example 2 with SAML2Response

use of org.keycloak.saml.processing.api.saml.v2.response.SAML2Response in project keycloak by keycloak.

the class SAML2LoginResponseBuilder method buildDocument.

public Document buildDocument(ResponseType responseType) throws ConfigurationException, ProcessingException {
    Document samlResponseDocument = null;
    try {
        SAML2Response docGen = new SAML2Response();
        samlResponseDocument = docGen.convert(responseType);
        if (logger.isTraceEnabled()) {
            logger.trace("SAML Response Document: " + DocumentUtil.asString(samlResponseDocument));
        }
    } catch (Exception e) {
        throw logger.samlAssertionMarshallError(e);
    }
    return samlResponseDocument;
}
Also used : SAML2Response(org.keycloak.saml.processing.api.saml.v2.response.SAML2Response) Document(org.w3c.dom.Document) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException) ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException)

Example 3 with SAML2Response

use of org.keycloak.saml.processing.api.saml.v2.response.SAML2Response in project keycloak by keycloak.

the class SAML2LogoutResponseBuilder method buildDocument.

public Document buildDocument() throws ProcessingException {
    Document samlResponse = null;
    try {
        StatusResponseType statusResponse = buildModel();
        SAML2Response saml2Response = new SAML2Response();
        samlResponse = saml2Response.convert(statusResponse);
    } catch (ConfigurationException e) {
        throw new ProcessingException(e);
    } catch (ParsingException e) {
        throw new ProcessingException(e);
    }
    return samlResponse;
}
Also used : ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) ParsingException(org.keycloak.saml.common.exceptions.ParsingException) SAML2Response(org.keycloak.saml.processing.api.saml.v2.response.SAML2Response) Document(org.w3c.dom.Document) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Example 4 with SAML2Response

use of org.keycloak.saml.processing.api.saml.v2.response.SAML2Response in project keycloak by keycloak.

the class SAMLRequestParser method parseResponseDocument.

public static SAMLDocumentHolder parseResponseDocument(byte[] samlBytes) {
    if (log.isDebugEnabled()) {
        String str = new String(samlBytes, GeneralConstants.SAML_CHARSET);
        log.debug(str);
    }
    InputStream is = new ByteArrayInputStream(samlBytes);
    SAML2Response response = new SAML2Response();
    try {
        response.getSAML2ObjectFromStream(is);
        return response.getSamlDocumentHolder();
    } catch (Exception e) {
        logger.samlBase64DecodingError(e);
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SAML2Response(org.keycloak.saml.processing.api.saml.v2.response.SAML2Response) IOException(java.io.IOException)

Example 5 with SAML2Response

use of org.keycloak.saml.processing.api.saml.v2.response.SAML2Response in project keycloak by keycloak.

the class SAML2ErrorResponseBuilder method buildDocument.

public Document buildDocument() throws ProcessingException {
    try {
        StatusResponseType statusResponse = new ResponseType(IDGenerator.create("ID_"), XMLTimeUtil.getIssueInstant());
        statusResponse.setStatus(JBossSAMLAuthnResponseFactory.createStatusTypeForResponder(status));
        statusResponse.setIssuer(issuer);
        statusResponse.setDestination(destination);
        if (!this.extensions.isEmpty()) {
            ExtensionsType extensionsType = new ExtensionsType();
            for (NodeGenerator extension : this.extensions) {
                extensionsType.addExtension(extension);
            }
            statusResponse.setExtensions(extensionsType);
        }
        SAML2Response saml2Response = new SAML2Response();
        return saml2Response.convert(statusResponse);
    } catch (ConfigurationException e) {
        throw new ProcessingException(e);
    } catch (ParsingException e) {
        throw new ProcessingException(e);
    }
}
Also used : ConfigurationException(org.keycloak.saml.common.exceptions.ConfigurationException) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType) ParsingException(org.keycloak.saml.common.exceptions.ParsingException) SAML2Response(org.keycloak.saml.processing.api.saml.v2.response.SAML2Response) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Aggregations

SAML2Response (org.keycloak.saml.processing.api.saml.v2.response.SAML2Response)8 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)3 ConfigurationException (org.keycloak.saml.common.exceptions.ConfigurationException)3 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)3 IOException (java.io.IOException)2 ExtensionsType (org.keycloak.dom.saml.v2.protocol.ExtensionsType)2 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)2 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)2 ParsingException (org.keycloak.saml.common.exceptions.ParsingException)2 Document (org.w3c.dom.Document)2 SAML2Object (org.keycloak.dom.saml.v2.SAML2Object)1 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)1 AudienceRestrictionType (org.keycloak.dom.saml.v2.assertion.AudienceRestrictionType)1 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)1 ConditionsType (org.keycloak.dom.saml.v2.assertion.ConditionsType)1 OneTimeUseType (org.keycloak.dom.saml.v2.assertion.OneTimeUseType)1 SubjectConfirmationDataType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType)1 SAMLDocumentHolder (org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder)1 IDPInfoHolder (org.keycloak.saml.processing.core.saml.v2.holders.IDPInfoHolder)1