Search in sources :

Example 1 with StatusResponseType

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

the class SAMLParserTest method testLogoutResponseStatusDetail.

@Test
public void testLogoutResponseStatusDetail() throws Exception {
    StatusResponseType resp = assertParsed("saml20-logout-response-status-detail.xml", StatusResponseType.class);
    assertThat(resp.getIssuer(), notNullValue());
    assertThat(resp.getIssuer().getValue(), is("http://idp.example.com/metadata.php"));
    assertThat(resp.getIssuer().getFormat(), is(JBossSAMLURIConstants.NAMEID_FORMAT_ENTITY.getUri()));
    assertThat(resp.getStatus(), notNullValue());
    assertThat(resp.getStatus().getStatusDetail(), notNullValue());
    assertThat(resp.getStatus().getStatusDetail().getAny(), notNullValue());
    assertThat(resp.getStatus().getStatusDetail().getAny().size(), is(2));
    assertThat(resp.getStatus().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:Responder")));
    assertThat(resp.getStatus().getStatusCode().getStatusCode(), nullValue());
}
Also used : StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 2 with StatusResponseType

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

the class SAMLParserTest method testLogoutResponseSimpleStatus.

@Test
public void testLogoutResponseSimpleStatus() throws Exception {
    StatusResponseType resp = assertParsed("saml20-logout-response-status.xml", StatusResponseType.class);
    assertThat(resp.getStatus(), notNullValue());
    assertThat(resp.getStatus().getStatusMessage(), is("Status Message"));
    assertThat(resp.getStatus().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:Responder")));
    assertThat(resp.getStatus().getStatusCode().getStatusCode(), nullValue());
}
Also used : StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 3 with StatusResponseType

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

the class SAMLParserTest method testLogoutResponseDeepNestedStatus.

@Test
public void testLogoutResponseDeepNestedStatus() throws Exception {
    StatusResponseType resp = assertParsed("saml20-logout-response-nested-status-deep.xml", StatusResponseType.class);
    assertThat(resp.getStatus(), notNullValue());
    assertThat(resp.getStatus().getStatusDetail(), notNullValue());
    assertThat(resp.getStatus().getStatusDetail().getAny(), notNullValue());
    assertThat(resp.getStatus().getStatusDetail().getAny().size(), is(2));
    assertThat(resp.getStatus().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:Responder")));
    assertThat(resp.getStatus().getStatusCode().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:AuthnFailed")));
    assertThat(resp.getStatus().getStatusCode().getStatusCode().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getStatusCode().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:VersionMismatch")));
}
Also used : StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 4 with StatusResponseType

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

the class SAMLParserTest method testLogoutResponseNestedStatus.

@Test
public void testLogoutResponseNestedStatus() throws Exception {
    StatusResponseType resp = assertParsed("saml20-logout-response-nested-status.xml", StatusResponseType.class);
    assertThat(resp.getStatus(), notNullValue());
    assertThat(resp.getStatus().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:Responder")));
    assertThat(resp.getStatus().getStatusCode().getStatusCode(), notNullValue());
    assertThat(resp.getStatus().getStatusCode().getStatusCode().getValue(), is(URI.create("urn:oasis:names:tc:SAML:2.0:status:AuthnFailed")));
    assertThat(resp.getStatus().getStatusCode().getStatusCode().getStatusCode(), nullValue());
}
Also used : StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 5 with StatusResponseType

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

the class SAML2Response method convert.

/**
 * Convert a SAML2 Response into a Document
 *
 * @param responseType
 *
 * @return
 *
 * @throws ParsingException
 * @throws ConfigurationException
 * @throws ProcessingException
 */
public Document convert(StatusResponseType responseType) throws ProcessingException, ConfigurationException, ParsingException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    SAMLResponseWriter writer = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(bos));
    if (responseType instanceof ResponseType) {
        ResponseType response = (ResponseType) responseType;
        writer.write(response);
    } else {
        writer.write(responseType, new QName(PROTOCOL_NSURI.get(), JBossSAMLConstants.LOGOUT_RESPONSE.get(), "samlp"));
    }
    return DocumentUtil.getDocument(new ByteArrayInputStream(bos.toByteArray()));
}
Also used : SAMLResponseWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType)

Aggregations

StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)22 Test (org.junit.Test)13 SAMLDocumentHolder (org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder)9 SamlClientBuilder (org.keycloak.testsuite.util.SamlClientBuilder)7 ArtifactResponseType (org.keycloak.dom.saml.v2.protocol.ArtifactResponseType)6 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)6 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)5 QName (javax.xml.namespace.QName)4 SAML2Object (org.keycloak.dom.saml.v2.SAML2Object)4 ExtensionsType (org.keycloak.dom.saml.v2.protocol.ExtensionsType)4 LogoutRequestType (org.keycloak.dom.saml.v2.protocol.LogoutRequestType)4 ParsingException (org.keycloak.saml.common.exceptions.ParsingException)4 Document (org.w3c.dom.Document)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Response (javax.ws.rs.core.Response)3 StatusCodeType (org.keycloak.dom.saml.v2.protocol.StatusCodeType)3 StatusType (org.keycloak.dom.saml.v2.protocol.StatusType)3 UserSessionModel (org.keycloak.models.UserSessionModel)3 ConfigurationException (org.keycloak.saml.common.exceptions.ConfigurationException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2