Search in sources :

Example 1 with EncryptedAssertionBuilder

use of org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProviderTests method authenticateWhenCustomResponseElementsDecrypterThenDecryptsResponse.

@Test
public void authenticateWhenCustomResponseElementsDecrypterThenDecryptsResponse() {
    Response response = response();
    Assertion assertion = assertion();
    TestOpenSamlObjects.signed(assertion, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    response.getEncryptedAssertions().add(new EncryptedAssertionBuilder().buildObject());
    TestOpenSamlObjects.signed(response, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    this.provider.setResponseElementsDecrypter((tuple) -> tuple.getResponse().getAssertions().add(assertion));
    Authentication authentication = this.provider.authenticate(token);
    assertThat(authentication.getName()).isEqualTo("test@saml.user");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) Authentication(org.springframework.security.core.Authentication) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) EncryptedAssertionBuilder(org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with EncryptedAssertionBuilder

use of org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder in project spring-security by spring-projects.

the class OpenSamlAuthenticationProviderTests method authenticateWhenCustomResponseElementsDecrypterThenDecryptsResponse.

@Test
public void authenticateWhenCustomResponseElementsDecrypterThenDecryptsResponse() {
    Response response = response();
    Assertion assertion = assertion();
    TestOpenSamlObjects.signed(assertion, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    response.getEncryptedAssertions().add(new EncryptedAssertionBuilder().buildObject());
    TestOpenSamlObjects.signed(response, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    this.provider.setResponseElementsDecrypter((tuple) -> tuple.getResponse().getAssertions().add(assertion));
    Authentication authentication = this.provider.authenticate(token);
    assertThat(authentication.getName()).isEqualTo("test@saml.user");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) Authentication(org.springframework.security.core.Authentication) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) EncryptedAssertionBuilder(org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 Assertion (org.opensaml.saml.saml2.core.Assertion)2 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)2 Response (org.opensaml.saml.saml2.core.Response)2 EncryptedAssertionBuilder (org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder)2 Authentication (org.springframework.security.core.Authentication)2