use of org.opensaml.saml.common.messaging.context.SAMLSelfEntityContext in project cas by apereo.
the class BaseSamlResponseEncoder method getEncoderMessageContext.
/**
* Build encoder message context.
*
* @param samlResponse the saml response
* @param relayState the relay state
* @return the message context
*/
protected MessageContext getEncoderMessageContext(final Response samlResponse, final String relayState) {
final MessageContext ctx = new MessageContext<>();
ctx.setMessage(samlResponse);
SAMLBindingSupport.setRelayState(ctx, relayState);
SamlIdPUtils.preparePeerEntitySamlEndpointContext(ctx, adaptor, getBinding());
final SAMLSelfEntityContext self = ctx.getSubcontext(SAMLSelfEntityContext.class, true);
self.setEntityId(samlResponse.getIssuer().getValue());
return ctx;
}
use of org.opensaml.saml.common.messaging.context.SAMLSelfEntityContext in project pac4j by pac4j.
the class SAML2LogoutRequestBuilder method buildLogoutRequest.
@SuppressWarnings("unchecked")
protected final LogoutRequest buildLogoutRequest(final SAML2MessageContext context, final AssertionConsumerService assertionConsumerService, final SingleLogoutService ssoService) {
final SAMLObjectBuilder<LogoutRequest> builder = (SAMLObjectBuilder<LogoutRequest>) this.builderFactory.getBuilder(LogoutRequest.DEFAULT_ELEMENT_NAME);
final LogoutRequest request = builder.buildObject();
final SAMLSelfEntityContext selfContext = context.getSAMLSelfEntityContext();
request.setID(generateID());
request.setIssuer(getIssuer(selfContext.getEntityId()));
request.setIssueInstant(DateTime.now(DateTimeZone.UTC).plusSeconds(this.issueInstantSkewSeconds));
request.setVersion(SAMLVersion.VERSION_20);
request.setDestination(ssoService.getLocation());
// very very bad...
ProfileManager manager = new ProfileManager(context.getWebContext());
Optional<UserProfile> p = manager.get(true);
if (p.isPresent() && p.get() instanceof SAML2Profile) {
final SAML2Profile samlP = (SAML2Profile) p.get();
// name id added (id of profile)
final SAMLObjectBuilder<NameID> nameIdBuilder = (SAMLObjectBuilder<NameID>) this.builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME);
final NameID nameId = nameIdBuilder.buildObject();
nameId.setValue(samlP.getId());
nameId.setFormat(samlP.getSamlNameIdFormat());
nameId.setNameQualifier(samlP.getSamlNameIdNameQualifier());
nameId.setSPNameQualifier(samlP.getSamlNameIdSpNameQualifier());
nameId.setSPProvidedID(samlP.getSamlNameIdSpProviderId());
request.setNameID(nameId);
// session index added
final String sessIdx = (String) samlP.getAttribute("sessionindex");
final SAMLObjectBuilder<SessionIndex> sessionIndexBuilder = (SAMLObjectBuilder<SessionIndex>) this.builderFactory.getBuilder(SessionIndex.DEFAULT_ELEMENT_NAME);
final SessionIndex sessionIdx = sessionIndexBuilder.buildObject();
sessionIdx.setSessionIndex(sessIdx);
request.getSessionIndexes().add(sessionIdx);
}
return request;
}
use of org.opensaml.saml.common.messaging.context.SAMLSelfEntityContext in project pac4j by pac4j.
the class SAML2AuthnRequestBuilder method buildAuthnRequest.
@SuppressWarnings("unchecked")
protected final AuthnRequest buildAuthnRequest(final SAML2MessageContext context, final AssertionConsumerService assertionConsumerService, final SingleSignOnService ssoService) {
final SAMLObjectBuilder<AuthnRequest> builder = (SAMLObjectBuilder<AuthnRequest>) this.builderFactory.getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
final AuthnRequest request = builder.buildObject();
if (comparisonType != null) {
final RequestedAuthnContext authnContext = new RequestedAuthnContextBuilder().buildObject();
authnContext.setComparison(comparisonType);
if (authnContextClassRef != null) {
final AuthnContextClassRef classRef = new AuthnContextClassRefBuilder().buildObject();
classRef.setAuthnContextClassRef(authnContextClassRef);
authnContext.getAuthnContextClassRefs().add(classRef);
}
request.setRequestedAuthnContext(authnContext);
}
final SAMLSelfEntityContext selfContext = context.getSAMLSelfEntityContext();
request.setID(generateID());
request.setIssuer(getIssuer(selfContext.getEntityId()));
request.setIssueInstant(DateTime.now(DateTimeZone.UTC).plusSeconds(this.issueInstantSkewSeconds));
request.setVersion(SAMLVersion.VERSION_20);
request.setIsPassive(this.passive);
request.setForceAuthn(this.forceAuth);
request.setProviderName("pac4j-saml");
if (nameIdPolicyFormat != null) {
final NameIDPolicy nameIdPolicy = new NameIDPolicyBuilder().buildObject();
nameIdPolicy.setAllowCreate(true);
nameIdPolicy.setFormat(nameIdPolicyFormat);
request.setNameIDPolicy(nameIdPolicy);
}
request.setDestination(ssoService.getLocation());
if (assertionConsumerServiceIndex >= 0) {
request.setAssertionConsumerServiceIndex(assertionConsumerServiceIndex);
} else {
request.setAssertionConsumerServiceURL(assertionConsumerService.getLocation());
}
request.setProtocolBinding(assertionConsumerService.getBinding());
if (attributeConsumingServiceIndex >= 0) {
request.setAttributeConsumingServiceIndex(attributeConsumingServiceIndex);
}
return request;
}
use of org.opensaml.saml.common.messaging.context.SAMLSelfEntityContext in project pac4j by pac4j.
the class SAML2ContextProvider method addSPContext.
protected final void addSPContext(final SAML2MessageContext context) {
final SAMLSelfEntityContext selfContext = context.getSAMLSelfEntityContext();
selfContext.setEntityId(this.spEntityId.getEntityId());
selfContext.setRole(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
addContext(this.spEntityId, selfContext, SPSSODescriptor.DEFAULT_ELEMENT_NAME);
}
Aggregations