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);
}
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;
}
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));
}
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));
}
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;
}
Aggregations