Search in sources :

Example 1 with Pac4jSAMLResponse

use of org.pac4j.saml.transport.Pac4jSAMLResponse in project pac4j by pac4j.

the class SAML2ContextProvider method prepareOutboundMessageContext.

protected MessageContext<Pac4jSAMLResponse> prepareOutboundMessageContext(final WebContext webContext) {
    final Pac4jSAMLResponse outTransport = new DefaultPac4jSAMLResponse(webContext);
    final MessageContext<Pac4jSAMLResponse> outCtx = new MessageContext<>();
    outCtx.setMessage(outTransport);
    return outCtx;
}
Also used : DefaultPac4jSAMLResponse(org.pac4j.saml.transport.DefaultPac4jSAMLResponse) Pac4jSAMLResponse(org.pac4j.saml.transport.Pac4jSAMLResponse) DefaultPac4jSAMLResponse(org.pac4j.saml.transport.DefaultPac4jSAMLResponse) MessageContext(org.opensaml.messaging.context.MessageContext)

Example 2 with Pac4jSAMLResponse

use of org.pac4j.saml.transport.Pac4jSAMLResponse in project pac4j by pac4j.

the class SAML2LogoutMessageSender method getMessageEncoder.

/**
 * Build the WebSSO handler for sending and receiving SAML2 messages.
 * @param ctx
 * @return the encoder instance
 */
private MessageEncoder getMessageEncoder(final SAML2MessageContext ctx) {
    final Pac4jSAMLResponse adapter = ctx.getProfileRequestContextOutboundMessageTransportResponse();
    if (SAMLConstants.SAML2_POST_BINDING_URI.equals(destinationBindingType)) {
        final VelocityEngine velocityEngine = VelocityEngineFactory.getEngine();
        final Pac4jHTTPPostEncoder encoder = new Pac4jHTTPPostEncoder(adapter);
        encoder.setVelocityEngine(velocityEngine);
        return encoder;
    }
    if (SAMLConstants.SAML2_REDIRECT_BINDING_URI.equals(destinationBindingType)) {
        final Pac4jHTTPRedirectDeflateEncoder encoder = new Pac4jHTTPRedirectDeflateEncoder(adapter, forceSignRedirectBindingLogoutRequest);
        return encoder;
    }
    throw new UnsupportedOperationException("Binding type - " + destinationBindingType + " is not supported");
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) Pac4jSAMLResponse(org.pac4j.saml.transport.Pac4jSAMLResponse) Pac4jHTTPPostEncoder(org.pac4j.saml.transport.Pac4jHTTPPostEncoder) Pac4jHTTPRedirectDeflateEncoder(org.pac4j.saml.transport.Pac4jHTTPRedirectDeflateEncoder)

Example 3 with Pac4jSAMLResponse

use of org.pac4j.saml.transport.Pac4jSAMLResponse in project pac4j by pac4j.

the class SAML2WebSSOMessageSender method getMessageEncoder.

/**
 * Build the WebSSO handler for sending and receiving SAML2 messages.
 *
 * @param ctx the ctx
 * @return the encoder instance
 */
private MessageEncoder getMessageEncoder(final SAML2MessageContext ctx) {
    final Pac4jSAMLResponse adapter = ctx.getProfileRequestContextOutboundMessageTransportResponse();
    if (SAMLConstants.SAML2_POST_BINDING_URI.equals(destinationBindingType)) {
        final VelocityEngine velocityEngine = VelocityEngineFactory.getEngine();
        final Pac4jHTTPPostEncoder encoder = new Pac4jHTTPPostEncoder(adapter);
        encoder.setVelocityEngine(velocityEngine);
        return encoder;
    }
    if (SAMLConstants.SAML2_REDIRECT_BINDING_URI.equals(destinationBindingType)) {
        return new Pac4jHTTPRedirectDeflateEncoder(adapter, isAuthnRequestSigned);
    }
    throw new UnsupportedOperationException("Binding type - " + destinationBindingType + " is not supported");
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) Pac4jSAMLResponse(org.pac4j.saml.transport.Pac4jSAMLResponse) Pac4jHTTPPostEncoder(org.pac4j.saml.transport.Pac4jHTTPPostEncoder) Pac4jHTTPRedirectDeflateEncoder(org.pac4j.saml.transport.Pac4jHTTPRedirectDeflateEncoder)

Example 4 with Pac4jSAMLResponse

use of org.pac4j.saml.transport.Pac4jSAMLResponse 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 5 with Pac4jSAMLResponse

use of org.pac4j.saml.transport.Pac4jSAMLResponse 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

Pac4jSAMLResponse (org.pac4j.saml.transport.Pac4jSAMLResponse)5 VelocityEngine (org.apache.velocity.app.VelocityEngine)2 SAML2MessageContext (org.pac4j.saml.context.SAML2MessageContext)2 Pac4jHTTPPostEncoder (org.pac4j.saml.transport.Pac4jHTTPPostEncoder)2 Pac4jHTTPRedirectDeflateEncoder (org.pac4j.saml.transport.Pac4jHTTPRedirectDeflateEncoder)2 MessageContext (org.opensaml.messaging.context.MessageContext)1 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)1 DefaultPac4jSAMLResponse (org.pac4j.saml.transport.DefaultPac4jSAMLResponse)1