Search in sources :

Example 6 with SAML2MessageContext

use of org.pac4j.saml.context.SAML2MessageContext in project pac4j by pac4j.

the class SAML2DefaultResponseValidatorTests method testWantsAssertionsSignedWithValidSPSSODescriptor.

@Test
public void testWantsAssertionsSignedWithValidSPSSODescriptor() {
    SAML2DefaultResponseValidator validator = createResponseValidatorWithSigningValidationOf(true);
    SAML2MessageContext context = new SAML2MessageContext();
    SAMLMetadataContext samlSelfMetadataContext = context.getSAMLSelfMetadataContext();
    SPSSODescriptor roleDescriptor = mock(SPSSODescriptor.class);
    when(roleDescriptor.getWantAssertionsSigned()).thenReturn(true);
    samlSelfMetadataContext.setRoleDescriptor(roleDescriptor);
    assertNotNull("Expected SPSSODescriptor to not be null", context.getSPSSODescriptor());
    assertTrue("Expected wantAssertionsSigned == true", validator.wantsAssertionsSigned(context));
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) SAMLMetadataContext(org.opensaml.saml.common.messaging.context.SAMLMetadataContext) Test(org.junit.Test)

Example 7 with SAML2MessageContext

use of org.pac4j.saml.context.SAML2MessageContext in project pac4j by pac4j.

the class SAML2DefaultResponseValidatorTests method testDoesNotWantAssertionsSignedWithValidSPSSODescriptor.

@Test
public void testDoesNotWantAssertionsSignedWithValidSPSSODescriptor() {
    SAML2DefaultResponseValidator validator = createResponseValidatorWithSigningValidationOf(false);
    SAML2MessageContext context = new SAML2MessageContext();
    SAMLMetadataContext samlSelfMetadataContext = context.getSAMLSelfMetadataContext();
    SPSSODescriptor roleDescriptor = mock(SPSSODescriptor.class);
    when(roleDescriptor.getWantAssertionsSigned()).thenReturn(false);
    samlSelfMetadataContext.setRoleDescriptor(roleDescriptor);
    assertNotNull("Expected SPSSODescriptor to not be null", context.getSPSSODescriptor());
    assertFalse("Expected wantAssertionsSigned == false", validator.wantsAssertionsSigned(context));
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) SAMLMetadataContext(org.opensaml.saml.common.messaging.context.SAMLMetadataContext) Test(org.junit.Test)

Example 8 with SAML2MessageContext

use of org.pac4j.saml.context.SAML2MessageContext in project pac4j by pac4j.

the class SAML2DefaultResponseValidatorTests method testDoesNotWantAssertionsSignedWithNullSPSSODescriptor.

@Test
public void testDoesNotWantAssertionsSignedWithNullSPSSODescriptor() {
    SAML2DefaultResponseValidator validator = createResponseValidatorWithSigningValidationOf(false);
    SAML2MessageContext context = new SAML2MessageContext();
    assertNull("Expected SPSSODescriptor to be null", context.getSPSSODescriptor());
    assertFalse("Expected wantAssertionsSigned == false", validator.wantsAssertionsSigned(context));
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) Test(org.junit.Test)

Example 9 with SAML2MessageContext

use of org.pac4j.saml.context.SAML2MessageContext in project pac4j by pac4j.

the class SAML2DefaultResponseValidatorTests method testWantsAssertionsSignedWithNullSPSSODescriptor.

@Test
public void testWantsAssertionsSignedWithNullSPSSODescriptor() {
    SAML2DefaultResponseValidator validator = createResponseValidatorWithSigningValidationOf(true);
    SAML2MessageContext context = new SAML2MessageContext();
    assertNull("Expected SPSSODescriptor to be null", context.getSPSSODescriptor());
    assertTrue("Expected wantAssertionsSigned == true", validator.wantsAssertionsSigned(context));
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) Test(org.junit.Test)

Example 10 with SAML2MessageContext

use of org.pac4j.saml.context.SAML2MessageContext in project pac4j by pac4j.

the class SAML2Client method clientInit.

@Override
protected void clientInit() {
    CommonHelper.assertNotNull("configuration", this.configuration);
    // First of all, initialize the configuration. It may dynamically load some properties, if it is not a static one.
    this.configuration.init(getName());
    initCredentialProvider();
    initDecrypter();
    initSignatureSigningParametersProvider();
    final MetadataResolver metadataManager = initChainingMetadataResolver(initIdentityProviderMetadataResolver(), initServiceProviderMetadataResolver());
    initSAMLContextProvider(metadataManager);
    initSignatureTrustEngineProvider(metadataManager);
    initSAMLResponseValidator();
    initSAMLProfileHandler();
    defaultRedirectActionBuilder(new SAML2RedirectActionBuilder(this));
    defaultCredentialsExtractor(ctx -> {
        final SAML2MessageContext samlContext = this.contextProvider.buildContext(ctx);
        final SAML2Credentials credentials = (SAML2Credentials) this.profileHandler.receive(samlContext);
        return credentials;
    });
    defaultAuthenticator(new SAML2Authenticator());
    defaultLogoutActionBuilder(new SAML2LogoutActionBuilder<>(this));
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) SAML2RedirectActionBuilder(org.pac4j.saml.redirect.SAML2RedirectActionBuilder) SAML2Credentials(org.pac4j.saml.credentials.SAML2Credentials) SAML2IdentityProviderMetadataResolver(org.pac4j.saml.metadata.SAML2IdentityProviderMetadataResolver) SAML2ServiceProviderMetadataResolver(org.pac4j.saml.metadata.SAML2ServiceProviderMetadataResolver) SAML2MetadataResolver(org.pac4j.saml.metadata.SAML2MetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) SAML2Authenticator(org.pac4j.saml.credentials.authenticator.SAML2Authenticator)

Aggregations

SAML2MessageContext (org.pac4j.saml.context.SAML2MessageContext)12 Test (org.junit.Test)6 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)4 SAMLPeerEntityContext (org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext)3 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)3 SAMLException (org.pac4j.saml.exceptions.SAMLException)3 ComponentInitializationException (net.shibboleth.utilities.java.support.component.ComponentInitializationException)2 MessageEncoder (org.opensaml.messaging.encoder.MessageEncoder)2 MessageEncodingException (org.opensaml.messaging.encoder.MessageEncodingException)2 SAMLMetadataContext (org.opensaml.saml.common.messaging.context.SAMLMetadataContext)2 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)2 SAMLMessageStorage (org.pac4j.saml.storage.SAMLMessageStorage)2 Pac4jSAMLResponse (org.pac4j.saml.transport.Pac4jSAMLResponse)2 SAMLBindingContext (org.opensaml.saml.common.messaging.context.SAMLBindingContext)1 ChainingMetadataResolver (org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)1 MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)1 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)1 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)1 SingleLogoutService (org.opensaml.saml.saml2.metadata.SingleLogoutService)1