Search in sources :

Example 1 with CustomOpenSamlObject

use of org.springframework.security.saml2.provider.service.authentication.TestCustomOpenSamlObjects.CustomOpenSamlObject in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProviderTests method authenticateWhenAssertionContainsCustomAttributesThenItSucceeds.

@Test
public void authenticateWhenAssertionContainsCustomAttributesThenItSucceeds() {
    Response response = response();
    Assertion assertion = assertion();
    AttributeStatement attribute = TestOpenSamlObjects.customAttributeStatement("Address", TestCustomOpenSamlObjects.instance());
    assertion.getAttributeStatements().add(attribute);
    TestOpenSamlObjects.signed(assertion, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    response.getAssertions().add(assertion);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    Authentication authentication = this.provider.authenticate(token);
    Saml2AuthenticatedPrincipal principal = (Saml2AuthenticatedPrincipal) authentication.getPrincipal();
    CustomOpenSamlObject address = (CustomOpenSamlObject) principal.getAttribute("Address").get(0);
    assertThat(address.getStreet()).isEqualTo("Test Street");
    assertThat(address.getStreetNumber()).isEqualTo("1");
    assertThat(address.getZIP()).isEqualTo("11111");
    assertThat(address.getCity()).isEqualTo("Test City");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) Authentication(org.springframework.security.core.Authentication) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) CustomOpenSamlObject(org.springframework.security.saml2.provider.service.authentication.TestCustomOpenSamlObjects.CustomOpenSamlObject) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 Assertion (org.opensaml.saml.saml2.core.Assertion)1 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)1 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)1 Response (org.opensaml.saml.saml2.core.Response)1 Authentication (org.springframework.security.core.Authentication)1 CustomOpenSamlObject (org.springframework.security.saml2.provider.service.authentication.TestCustomOpenSamlObjects.CustomOpenSamlObject)1