Search in sources :

Example 1 with SAMLMetadataContext

use of org.opensaml.saml.common.messaging.context.SAMLMetadataContext in project pac4j by pac4j.

the class SAML2ContextProvider method addContext.

protected final void addContext(final SAML2MetadataResolver entityId, final BaseContext parentContext, final QName elementName) {
    final EntityDescriptor entityDescriptor;
    final RoleDescriptor roleDescriptor;
    try {
        final CriteriaSet set = new CriteriaSet();
        set.add(new EntityIdCriterion(entityId.getEntityId()));
        entityDescriptor = this.metadata.resolveSingle(set);
        if (entityDescriptor == null) {
            throw new SAMLException("Cannot find entity " + entityId + " in metadata provider");
        }
        final List<RoleDescriptor> list = entityDescriptor.getRoleDescriptors(elementName, SAMLConstants.SAML20P_NS);
        roleDescriptor = CommonHelper.isNotEmpty(list) ? list.get(0) : null;
        if (roleDescriptor == null) {
            throw new SAMLException("Cannot find entity " + entityId + " or role " + elementName + " in metadata provider");
        }
    } catch (final ResolverException e) {
        throw new SAMLException("An error occured while getting IDP descriptors", e);
    }
    final SAMLMetadataContext mdCtx = parentContext.getSubcontext(SAMLMetadataContext.class, true);
    mdCtx.setEntityDescriptor(entityDescriptor);
    mdCtx.setRoleDescriptor(roleDescriptor);
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) RoleDescriptor(org.opensaml.saml.saml2.metadata.RoleDescriptor) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SAMLMetadataContext(org.opensaml.saml.common.messaging.context.SAMLMetadataContext) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Example 2 with SAMLMetadataContext

use of org.opensaml.saml.common.messaging.context.SAMLMetadataContext in project pac4j by pac4j.

the class SAML2MessageContext method getIDPSSODescriptor.

public final IDPSSODescriptor getIDPSSODescriptor() {
    final SAMLMetadataContext peerContext = getSAMLPeerMetadataContext();
    final IDPSSODescriptor idpssoDescriptor = (IDPSSODescriptor) peerContext.getRoleDescriptor();
    return idpssoDescriptor;
}
Also used : IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) SAMLMetadataContext(org.opensaml.saml.common.messaging.context.SAMLMetadataContext)

Example 3 with SAMLMetadataContext

use of org.opensaml.saml.common.messaging.context.SAMLMetadataContext 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 4 with SAMLMetadataContext

use of org.opensaml.saml.common.messaging.context.SAMLMetadataContext 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 5 with SAMLMetadataContext

use of org.opensaml.saml.common.messaging.context.SAMLMetadataContext in project pac4j by pac4j.

the class SAML2MessageContext method getSPSSODescriptor.

public final SPSSODescriptor getSPSSODescriptor() {
    final SAMLMetadataContext selfContext = getSAMLSelfMetadataContext();
    final SPSSODescriptor spDescriptor = (SPSSODescriptor) selfContext.getRoleDescriptor();
    return spDescriptor;
}
Also used : SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) SAMLMetadataContext(org.opensaml.saml.common.messaging.context.SAMLMetadataContext)

Aggregations

SAMLMetadataContext (org.opensaml.saml.common.messaging.context.SAMLMetadataContext)5 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)3 Test (org.junit.Test)2 SAML2MessageContext (org.pac4j.saml.context.SAML2MessageContext)2 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)1 ResolverException (net.shibboleth.utilities.java.support.resolver.ResolverException)1 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)1 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)1 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)1 RoleDescriptor (org.opensaml.saml.saml2.metadata.RoleDescriptor)1 SAMLException (org.pac4j.saml.exceptions.SAMLException)1