Search in sources :

Example 61 with ResponseType

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

the class AssertionUtil method getSubTypeElement.

private static STSubType getSubTypeElement(final ResponseType responseType) {
    final List<ResponseType.RTChoiceType> assertions = responseType.getAssertions();
    if (assertions.isEmpty()) {
        return null;
    }
    final AssertionType assertion = assertions.get(0).getAssertion();
    if (assertion.getSubject() == null) {
        return null;
    }
    return assertion.getSubject().getSubType();
}
Also used : EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) SAML11AssertionType(org.keycloak.dom.saml.v1.assertion.SAML11AssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType)

Example 62 with ResponseType

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

the class SAMLParserTest method testEmptyAttributeValue.

@Test
public void testEmptyAttributeValue() throws Exception {
    ResponseType resp = assertParsed("KEYCLOAK-4790-Empty-attribute-value.xml", ResponseType.class);
    assertThat(resp.getAssertions(), hasSize(1));
    final AssertionType a = resp.getAssertions().get(0).getAssertion();
    assertThat(a, notNullValue());
    assertThat(a.getAttributeStatements(), hasSize(1));
    final List<ASTChoiceType> attributes = a.getAttributeStatements().iterator().next().getAttributes();
    assertThat(attributes, hasSize(3));
    assertThat(attributes, everyItem(notNullValue(ASTChoiceType.class)));
    final AttributeType attr0 = attributes.get(0).getAttribute();
    final AttributeType attr1 = attributes.get(1).getAttribute();
    final AttributeType attr2 = attributes.get(2).getAttribute();
    assertThat(attr0.getName(), is("urn:oid:0.9.2342.19200300.100.1.2"));
    assertThat(attr0.getAttributeValue(), hasSize(1));
    assertThat(attr0.getAttributeValue().get(0), instanceOf(String.class));
    assertThat((String) attr0.getAttributeValue().get(0), is(""));
    assertThat(attr1.getName(), is("urn:oid:0.9.2342.19200300.100.1.3"));
    assertThat(attr1.getAttributeValue(), hasSize(1));
    assertThat(attr1.getAttributeValue().get(0), instanceOf(String.class));
    assertThat((String) attr1.getAttributeValue().get(0), is("aa"));
    assertThat(attr2.getName(), is("urn:oid:0.9.2342.19200300.100.1.4"));
    assertThat(attr2.getAttributeValue(), hasSize(1));
    assertThat(attr2.getAttributeValue().get(0), instanceOf(String.class));
    assertThat((String) attr2.getAttributeValue().get(0), is(""));
}
Also used : RequestedAttributeType(org.keycloak.dom.saml.v2.metadata.RequestedAttributeType) AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType) EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) Matchers.containsString(org.hamcrest.Matchers.containsString) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 63 with ResponseType

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

the class SAMLParserTest method testSaml20EncryptedAssertionWithNewlines.

@Test
public void testSaml20EncryptedAssertionWithNewlines() throws Exception {
    SAMLDocumentHolder holder = assertParsed("KEYCLOAK-4489-encrypted-assertion-with-newlines.xml", SAMLDocumentHolder.class);
    assertThat(holder.getSamlObject(), instanceOf(ResponseType.class));
    ResponseType resp = (ResponseType) holder.getSamlObject();
    assertThat(resp.getAssertions().size(), is(1));
    ResponseType.RTChoiceType rtChoiceType = resp.getAssertions().get(0);
    assertNull(rtChoiceType.getAssertion());
    assertNotNull(rtChoiceType.getEncryptedAssertion());
    PrivateKey privateKey = DerUtils.decodePrivateKey(Base64.decode(PRIVATE_KEY));
    AssertionUtil.decryptAssertion(holder, resp, privateKey);
    rtChoiceType = resp.getAssertions().get(0);
    assertNotNull(rtChoiceType.getAssertion());
    assertNull(rtChoiceType.getEncryptedAssertion());
}
Also used : SAMLDocumentHolder(org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder) PrivateKey(java.security.PrivateKey) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 64 with ResponseType

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

the class SAMLParserTest method testSaml20EncryptedAssertionsSignedTwoExtensionsReceivedWithRedirectBinding.

@Test
public void testSaml20EncryptedAssertionsSignedTwoExtensionsReceivedWithRedirectBinding() throws Exception {
    Element el;
    ResponseType resp = assertParsed("saml20-encrypted-signed-redirect-response-two-extensions.xml", ResponseType.class);
    assertThat(resp.getSignature(), nullValue());
    assertThat(resp.getConsent(), nullValue());
    assertThat(resp.getIssuer(), not(nullValue()));
    assertThat(resp.getIssuer().getValue(), is("http://localhost:8081/auth/realms/saml-demo"));
    assertThat(resp.getExtensions(), not(nullValue()));
    assertThat(resp.getExtensions().getAny().size(), is(2));
    assertThat(resp.getExtensions().getAny().get(0), instanceOf(Element.class));
    el = (Element) resp.getExtensions().getAny().get(0);
    assertThat(el.getLocalName(), is("KeyInfo"));
    assertThat(el.getNamespaceURI(), is("urn:keycloak:ext:key:1.0"));
    assertThat(el.hasAttribute("MessageSigningKeyId"), is(true));
    assertThat(el.getAttribute("MessageSigningKeyId"), is("FJ86GcF3jTbNLOco4NvZkUCIUmfYCqoqtOQeMfbhNlE"));
    assertThat(resp.getExtensions().getAny().get(1), instanceOf(Element.class));
    el = (Element) resp.getExtensions().getAny().get(1);
    assertThat(el.getLocalName(), is("ever"));
    assertThat(el.getNamespaceURI(), is("urn:keycloak:ext:what:1.0"));
    assertThat(el.hasAttribute("what"), is(true));
    assertThat(el.getAttribute("what"), is("ever"));
    assertThat(resp.getAssertions(), not(nullValue()));
    assertThat(resp.getAssertions().size(), is(1));
}
Also used : Element(org.w3c.dom.Element) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 65 with ResponseType

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

the class SAMLParserTest method testSaml20EncryptedId.

@Test
public void testSaml20EncryptedId() throws Exception {
    ResponseType rt = assertParsed("saml20-encrypted-id-response.xml", ResponseType.class);
    assertThat(rt, notNullValue());
    assertThat(rt.getAssertions(), notNullValue());
    assertThat(rt.getAssertions().size(), is(1));
    assertThat(rt.getAssertions().get(0).getAssertion().getSubject(), notNullValue());
    assertThat(rt.getAssertions().get(0).getAssertion().getSubject().getSubType(), notNullValue());
    assertThat(rt.getAssertions().get(0).getAssertion().getSubject().getSubType().getEncryptedID(), notNullValue());
}
Also used : ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Aggregations

ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)75 Test (org.junit.Test)50 SamlClientBuilder (org.keycloak.testsuite.util.SamlClientBuilder)38 SAMLDocumentHolder (org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder)34 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)33 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)26 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)25 JBossSAMLURIConstants (org.keycloak.saml.common.constants.JBossSAMLURIConstants)16 Document (org.w3c.dom.Document)15 URI (java.net.URI)13 List (java.util.List)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 Assert.assertThat (org.junit.Assert.assertThat)12 AttributeStatementType (org.keycloak.dom.saml.v2.assertion.AttributeStatementType)12 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)12 StatementAbstractType (org.keycloak.dom.saml.v2.assertion.StatementAbstractType)12 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)12 IOException (java.io.IOException)11 Response (javax.ws.rs.core.Response)11 Matchers (org.keycloak.testsuite.util.Matchers)11