Search in sources :

Example 11 with SAML2MessageContext

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

the class SAML2RedirectActionBuilder method redirect.

@Override
public RedirectAction redirect(final WebContext wc) {
    final SAML2MessageContext context = this.client.getContextProvider().buildContext(wc);
    final String relayState = this.client.getStateParameter(wc);
    final AuthnRequest authnRequest = this.saml2ObjectBuilder.build(context);
    this.client.getProfileHandler().send(context, authnRequest, relayState);
    final Pac4jSAMLResponse adapter = context.getProfileRequestContextOutboundMessageTransportResponse();
    if (this.client.getConfiguration().getDestinationBindingType().equalsIgnoreCase(SAMLConstants.SAML2_POST_BINDING_URI)) {
        final String content = adapter.getOutgoingContent();
        return RedirectAction.success(content);
    }
    final String location = adapter.getRedirectUrl();
    return RedirectAction.redirect(location);
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) Pac4jSAMLResponse(org.pac4j.saml.transport.Pac4jSAMLResponse) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest)

Example 12 with SAML2MessageContext

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

the class SAML2LogoutActionBuilder method getLogoutAction.

@Override
public RedirectAction getLogoutAction(final WebContext context, final U currentProfile, final String targetUrl) {
    final SAML2MessageContext samlContext = this.client.getContextProvider().buildContext(context);
    final String relayState = this.client.getStateParameter(context);
    final LogoutRequest logoutRequest = this.saml2LogoutObjectBuilder.build(samlContext);
    this.logoutProfileHandler.send(samlContext, logoutRequest, relayState);
    final Pac4jSAMLResponse adapter = samlContext.getProfileRequestContextOutboundMessageTransportResponse();
    if (this.client.getConfiguration().getDestinationBindingType().equalsIgnoreCase(SAMLConstants.SAML2_POST_BINDING_URI)) {
        final String content = adapter.getOutgoingContent();
        return RedirectAction.success(content);
    }
    final String location = adapter.getRedirectUrl();
    return RedirectAction.redirect(location);
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) Pac4jSAMLResponse(org.pac4j.saml.transport.Pac4jSAMLResponse) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest)

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