Using HTTP Redirect binding in OpenSAML 4

This article discusses singing and sending in OpenSAML 4. If you're looking for an article on OpenSAML 3, you will find it here and if you're looking for an article on OpenSAML 2, you will find it here

SAML messages can be sent using different methods, called bindings. There are four main standard bindings being used today, HTTP Redirect, HTTP POST, HTTP Artifact and SOAP.

This tutorial will walk you through how to send a message, specifically a authentication request, using HTTP Redirect in OpenSAML.

The HTTP Redirect binding

The Redirect binding uses the function of HTTP Redirects the transport messages between SP and IdP with the use of the user browser.

Diagram of redirect binding

  1. When the SP or IdP want to send a message it responds to the current user with a HTTP Redirect to the receiver, with the encoded message in an URL parameter.
  2. When the browser receives the redirect, it redirects the user to the receiver.
  3. When the user arrives at the receiver of the message, the receiver will pick the message from the URL parameter and parses the message.

URL parameters explained

A typical redirect URL can look like this.


There are four URL parameters used in the binding

  • SAMLRequest/SAMResponse - The encoded, unsigned message
  • RelayState - The relaystate, sent in the original request and send back in the response
  • SigAlg - The algorithm used for signing
  • Signature - Calculated signature

The authentication request is often the first message send when authenticating a user user SAML. This is true when the recommended approach of SP initiated SSO is used and the SP is the one that requests a user to be authenticated by the IdP.

Sending a message using OpenSAML 4

Creating message contexts to set the message, relaystate and receiving endpoint.
1MessageContext context = new MessageContext();
4SAMLBindingContext bindingContext = context.getSubcontext(SAMLBindingContext.class, true);
7SAMLPeerEntityContext peerEntityContext = context.getSubcontext(SAMLPeerEntityContext.class, true);
8SAMLEndpointContext endpointContext = peerEntityContext.getSubcontext(SAMLEndpointContext.class, true);

Creating, initializing and sending the message using HTTPRedirectDeflateEncoder.

1HTTPRedirectDeflateEncoder encoder = new HTTPRedirectDeflateEncoder();

Receiving a message using OpenSAML 4

Using HTTPRedirectDeflateDecoder to decode the received message from the HTTPServletRequest

1HTTPRedirectDeflateDecoder decoder = new HTTPRedirectDeflateDecoder();
6MessageContext messageContext = decoder.getMessageContext();
7authnRequest = (AuthnRequest) messageContext.getMessage();

Get it on Github!

The full running sample is availible on Github at under opensaml-http-redirect

Just clone it, run it, go nuts!

1git clone
2cd opensaml-http-redirect
3mvn tomcat:run

All messages are printed in the console

Browse to http://localhost:8080/opensaml-http-redirect/redirectPage


In this post we have looked on.

  • The basics of the HTTP redirect binding
  • Sending a message using OpenSAML 4,
  • Receiving a message using OpenSAML 4