Search in sources :

Example 1 with EncryptedDataBuilder

use of org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder in project spring-security by spring-projects.

the class OpenSamlAuthenticationProviderTests method authenticateWhenCustomAssertionElementsDecrypterThenDecryptsAssertion.

@Test
public void authenticateWhenCustomAssertionElementsDecrypterThenDecryptsAssertion() {
    Response response = response();
    Assertion assertion = assertion();
    EncryptedID id = new EncryptedIDBuilder().buildObject();
    id.setEncryptedData(new EncryptedDataBuilder().buildObject());
    assertion.getSubject().setEncryptedID(id);
    TestOpenSamlObjects.signed(assertion, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    response.getAssertions().add(assertion);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    this.provider.setAssertionElementsDecrypter((tuple) -> {
        NameID name = new NameIDBuilder().buildObject();
        name.setValue("decrypted name");
        tuple.getAssertion().getSubject().setNameID(name);
    });
    Authentication authentication = this.provider.authenticate(token);
    assertThat(authentication.getName()).isEqualTo("decrypted name");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) NameIDBuilder(org.opensaml.saml.saml2.core.impl.NameIDBuilder) EncryptedIDBuilder(org.opensaml.saml.saml2.core.impl.EncryptedIDBuilder) EncryptedDataBuilder(org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder) NameID(org.opensaml.saml.saml2.core.NameID) Authentication(org.springframework.security.core.Authentication) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) EncryptedID(org.opensaml.saml.saml2.core.EncryptedID) Test(org.junit.jupiter.api.Test)

Example 2 with EncryptedDataBuilder

use of org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProviderTests method authenticateWhenCustomAssertionElementsDecrypterThenDecryptsAssertion.

@Test
public void authenticateWhenCustomAssertionElementsDecrypterThenDecryptsAssertion() {
    Response response = response();
    Assertion assertion = assertion();
    EncryptedID id = new EncryptedIDBuilder().buildObject();
    id.setEncryptedData(new EncryptedDataBuilder().buildObject());
    assertion.getSubject().setEncryptedID(id);
    TestOpenSamlObjects.signed(assertion, TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
    response.getAssertions().add(assertion);
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    this.provider.setAssertionElementsDecrypter((tuple) -> {
        NameID name = new NameIDBuilder().buildObject();
        name.setValue("decrypted name");
        tuple.getAssertion().getSubject().setNameID(name);
    });
    Authentication authentication = this.provider.authenticate(token);
    assertThat(authentication.getName()).isEqualTo("decrypted name");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) NameIDBuilder(org.opensaml.saml.saml2.core.impl.NameIDBuilder) EncryptedIDBuilder(org.opensaml.saml.saml2.core.impl.EncryptedIDBuilder) EncryptedDataBuilder(org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder) NameID(org.opensaml.saml.saml2.core.NameID) Authentication(org.springframework.security.core.Authentication) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) EncryptedID(org.opensaml.saml.saml2.core.EncryptedID) 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 EncryptedID (org.opensaml.saml.saml2.core.EncryptedID)2 NameID (org.opensaml.saml.saml2.core.NameID)2 Response (org.opensaml.saml.saml2.core.Response)2 EncryptedIDBuilder (org.opensaml.saml.saml2.core.impl.EncryptedIDBuilder)2 NameIDBuilder (org.opensaml.saml.saml2.core.impl.NameIDBuilder)2 EncryptedDataBuilder (org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder)2 Authentication (org.springframework.security.core.Authentication)2