use of org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext in project cas by apereo.
the class SamlIdPUtils method preparePeerEntitySamlEndpointContext.
/**
* Prepare peer entity saml endpoint.
*
* @param outboundContext the outbound context
* @param adaptor the adaptor
* @throws SamlException the saml exception
*/
public static void preparePeerEntitySamlEndpointContext(final MessageContext outboundContext, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) throws SamlException {
final List<AssertionConsumerService> assertionConsumerServices = adaptor.getAssertionConsumerServices();
if (assertionConsumerServices.isEmpty()) {
throw new SamlException("No assertion consumer service could be found for entity " + adaptor.getEntityId());
}
final SAMLPeerEntityContext peerEntityContext = outboundContext.getSubcontext(SAMLPeerEntityContext.class, true);
if (peerEntityContext == null) {
throw new SamlException("SAMLPeerEntityContext could not be defined for entity " + adaptor.getEntityId());
}
final SAMLEndpointContext endpointContext = peerEntityContext.getSubcontext(SAMLEndpointContext.class, true);
if (endpointContext == null) {
throw new SamlException("SAMLEndpointContext could not be defined for entity " + adaptor.getEntityId());
}
final Endpoint endpoint = assertionConsumerServices.get(0);
if (StringUtils.isBlank(endpoint.getBinding()) || StringUtils.isBlank(endpoint.getLocation())) {
throw new SamlException("Assertion consumer service does not define a binding or location for " + adaptor.getEntityId());
}
LOGGER.debug("Configured peer entity endpoint to be [{}] with binding [{}]", endpoint.getLocation(), endpoint.getBinding());
endpointContext.setEndpoint(endpoint);
}
use of org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext in project pac4j by pac4j.
the class SAML2DefaultResponseValidator method validateAssertionSignature.
/**
* Validate assertion signature. If none is found and the SAML response did not have one and the SP requires
* the assertions to be signed, the validation fails.
*
* @param signature the signature
* @param context the context
* @param engine the engine
*/
protected final void validateAssertionSignature(final Signature signature, final SAML2MessageContext context, final SignatureTrustEngine engine) {
final SAMLPeerEntityContext peerContext = context.getSAMLPeerEntityContext();
if (signature != null) {
final String entityId = peerContext.getEntityId();
validateSignature(signature, entityId, engine);
} else {
if (wantsAssertionsSigned(context) && !peerContext.isAuthenticated()) {
throw new SAMLSignatureRequiredException("Assertion or response must be signed");
}
}
}
use of org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext in project pac4j by pac4j.
the class SAML2DefaultResponseValidatorTests method testAssertionWithoutSignatureThrowsException.
@Test(expected = SAMLException.class)
public void testAssertionWithoutSignatureThrowsException() {
SAML2DefaultResponseValidator validator = createResponseValidatorWithSigningValidationOf(true);
SAML2MessageContext context = new SAML2MessageContext();
SAMLPeerEntityContext peerEntityContext = new SAMLPeerEntityContext();
peerEntityContext.setAuthenticated(false);
context.addSubcontext(peerEntityContext);
validator.validateAssertionSignature(null, context, null);
}
use of org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext in project pac4j by pac4j.
the class SAML2DefaultResponseValidatorTests method testAssertionWithoutSignatureDoesNotThrowException.
@Test
public void testAssertionWithoutSignatureDoesNotThrowException() {
SAML2DefaultResponseValidator validator = createResponseValidatorWithSigningValidationOf(false);
SAML2MessageContext context = new SAML2MessageContext();
SAMLPeerEntityContext peerEntityContext = new SAMLPeerEntityContext();
peerEntityContext.setAuthenticated(false);
context.addSubcontext(peerEntityContext);
validator.validateAssertionSignature(null, context, null);
// expected no exceptions
}
use of org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext in project pac4j by pac4j.
the class SAML2ContextProvider method addIDPContext.
protected final void addIDPContext(final SAML2MessageContext context) {
final SAMLPeerEntityContext peerContext = context.getSAMLPeerEntityContext();
peerContext.setEntityId(this.idpEntityId.getEntityId());
peerContext.setRole(IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
addContext(this.idpEntityId, peerContext, IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
}
Aggregations