Search in sources :

Example 6 with SAMLDataMarshaller

use of org.keycloak.broker.saml.SAMLDataMarshaller in project keycloak by keycloak.

the class SAMLDataMarshallerTest method testSerializeWithNamespaceNotInSignatureElement.

@Test
public void testSerializeWithNamespaceNotInSignatureElement() throws Exception {
    SAMLParser parser = SAMLParser.getInstance();
    try (InputStream st = SAMLDataMarshallerTest.class.getResourceAsStream("saml-response-ds-ns-above-signature.xml")) {
        Object parsedObject = parser.parse(st);
        assertThat(parsedObject, instanceOf(ResponseType.class));
        ResponseType response = (ResponseType) parsedObject;
        SAMLDataMarshaller serializer = new SAMLDataMarshaller();
        String serializedResponse = serializer.serialize(response);
        String serializedAssertion = serializer.serialize(response.getAssertions().get(0).getAssertion());
        ResponseType deserializedResponse = serializer.deserialize(serializedResponse, ResponseType.class);
        assertThat(deserializedResponse, CoreMatchers.notNullValue());
        assertThat(deserializedResponse.getID(), CoreMatchers.is("id-EYgqtumZ-P-Ph7t37f-brUKMwB5MKix0sNjr-0YV"));
        AssertionType deserializedAssertion = serializer.deserialize(serializedAssertion, AssertionType.class);
        assertThat(deserializedAssertion, CoreMatchers.notNullValue());
        assertThat(deserializedAssertion.getID(), CoreMatchers.is("id-4r-Xj702KQsM0gJyu3Fqpuwfe-LvDrEcQZpxKrhC"));
    }
}
Also used : InputStream(java.io.InputStream) SAMLParser(org.keycloak.saml.processing.core.parsers.saml.SAMLParser) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) SAMLDataMarshaller(org.keycloak.broker.saml.SAMLDataMarshaller) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) Test(org.junit.Test)

Example 7 with SAMLDataMarshaller

use of org.keycloak.broker.saml.SAMLDataMarshaller in project keycloak by keycloak.

the class SAMLDataMarshallerTest method testParseAuthnType.

@Test
public void testParseAuthnType() {
    SAMLDataMarshaller serializer = new SAMLDataMarshaller();
    AuthnStatementType authnStatement = serializer.deserialize(TEST_AUTHN_TYPE, AuthnStatementType.class);
    // test authnStatement
    Assert.assertEquals("fa0f4fd3-8a11-44f4-9acb-ee30c5bb8fe5", authnStatement.getSessionIndex());
    // back to String
    String serialized = serializer.serialize(authnStatement);
    Assert.assertEquals(TEST_AUTHN_TYPE, serialized);
}
Also used : AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) SAMLDataMarshaller(org.keycloak.broker.saml.SAMLDataMarshaller) Test(org.junit.Test)

Example 8 with SAMLDataMarshaller

use of org.keycloak.broker.saml.SAMLDataMarshaller in project keycloak by keycloak.

the class SamlProtocol method buildArtifactAndStoreResponse.

protected String buildArtifactAndStoreResponse(SAML2Object saml2Object, AuthenticatedClientSessionModel clientSessionModel) throws ArtifactResolverProcessingException, ProcessingException, ConfigurationException {
    String entityId = RealmsResource.realmBaseUrl(uriInfo).build(realm.getName()).toString();
    ArtifactResponseType artifactResponseType = SamlProtocolUtils.buildArtifactResponse(saml2Object, SAML2NameIDBuilder.value(getResponseIssuer(realm)).build());
    // Create artifact and store session mapping
    SAMLDataMarshaller marshaller = new SAMLDataMarshaller();
    String artifact = getArtifactResolver().buildArtifact(clientSessionModel, entityId, marshaller.serialize(artifactResponseType));
    getArtifactSessionMappingStore().put(artifact, realm.getAccessCodeLifespan(), clientSessionModel);
    return artifact;
}
Also used : ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) SAMLDataMarshaller(org.keycloak.broker.saml.SAMLDataMarshaller)

Aggregations

SAMLDataMarshaller (org.keycloak.broker.saml.SAMLDataMarshaller)8 Test (org.junit.Test)6 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)4 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)3 InputStream (java.io.InputStream)2 ArtifactResponseType (org.keycloak.dom.saml.v2.protocol.ArtifactResponseType)2 SAMLParser (org.keycloak.saml.processing.core.parsers.saml.SAMLParser)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 VerificationException (org.keycloak.common.VerificationException)1 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)1 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)1 AuthenticatedClientSessionModel (org.keycloak.models.AuthenticatedClientSessionModel)1 ClientModel (org.keycloak.models.ClientModel)1 SamlArtifactSessionMappingModel (org.keycloak.models.SamlArtifactSessionMappingModel)1 UserSessionModel (org.keycloak.models.UserSessionModel)1 ConfigurationException (org.keycloak.saml.common.exceptions.ConfigurationException)1 ParsingException (org.keycloak.saml.common.exceptions.ParsingException)1 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)1 Document (org.w3c.dom.Document)1