Try WSO2 Cloud for Free
Sign in

All docs This doc
||
Skip to end of metadata
Go to start of metadata

This section includes the following key concepts that are pertaining to the WSO2 Identity Cloud.



Introducing single sign-on

Single sign-on (SSO) is one of the key features of the WSO2 Identity Cloud that enables users to provide their credentials once and obtain access to multiple applications. The users are not prompted for their credentials when accessing each application until their session is terminated. Additionally, the user can access all these applications without having to log into each and every one of them individually. So, if users log into application A, for example, they would automatically have access to application B as well for the duration of that session without having to re-enter their credentials.

The following are some of the advantages you can have with SSO:

  • Users need only a single username/password pair to access multiple services. Thus they do not have the issue of remembering multiple username/password pairs.
  • Users are authenticated only once at the identity provider and then they are automatically logged into all services within that "trust-domain". This process is more convenient to users since they do not have to provide their username/password at every service provider.
  • Service providers do not have the overhead of managing user identities, which is more convenient for them.
  • User identities are managed at a central point. This is more secure, less complex and easily manageable.

How single sign-on works

To understand how single sign-on works, it is useful to first examine how authentication works in a non SSO environment. The following diagram depicts this flow.

Figure: Authentication in a non SSO environment

In the above figure, the users access Application 1 first and then Application 2 using the same browser. The user is authenticated in Application 1 first and can access this application. When the users attempt to access Application 2, they must enter their credentials again and get access to Application 2 separately. There is no way for Application 2 to access the cookie stored in the browser for Application 1 and authenticate the user by that means.

The following diagram depicts how this story differs in a SSO environment.

Figure: Authentication in a SSO environment

In this second figure, the users access Application 1 first followed by Application 2. Once again, the users use the same browser to access these applications. The users are redirected to the WSO2 Identity Cloud (or any authentication server that is configured for this task). If the users are already logged in to the Identity Cloud, the user is authenticated in Application 1 via an authentication token sent by the Identity Cloud to Application 1. When Application 2 is accessed, the same thing happens and the users are redirected to the Identity Cloud and authenticated. This is how SSO works.


SSO in reality

Single sign-on is widely used in web technologies. Google is one of the best examples. Try this simple exercise.

  1. Visit www.google.com from your web browser.
  2. Click the SIGN IN button on the top right of the page.
  3. Once you sign in, you are redirected to https://accounts.google.com/ServiceLogin. There you are requested to enter your Username and Password. Enter your Google credentials there.
  4. Once you enter your Username and Password, you are directed back to www.google.com where you started.
  5. Next visit www.gmail.com, the Google mail server.
  6. Notice that you are automatically signed in and you directly access your Gmail Inbox. You did not have to enter your Username and Password at Gmail.
  7. In addition to that; now try www.youtube.com.
  8. You are automatically signed in. You do not have to enter your username and password at YouTube.

    Tip: Notice the URL of the web browser. Each time you access an application, you see that you are being redirected to https://accounts.google.com/ServiceLogin and return immediately back to the website.

Single Sign-On (SSO) allows you to sign in only once but provides access to multiple resources without having to re-enter your username and password.


Supported protocols for agent-based SSO

The following are the supported protocols for agent-based single sign-on.

  • SAML 2.0
  • WS-Federation
  • OpenID Connect

The following sections in this topic expand on these protocols and provide details pertaining to them.

Recommended reading

See Configuring Standards-based SSO for more information on how to configure each of these protocols for agent-based SSO in the WSO2 Identity Cloud.



SAML 2.0 SSO

SAML stands for Security Assertion Markup Language, which is an XML-based data format for exchanging authentication and authorization data between an identity provider and a service provider. The single most important requirement that SAML addresses is web browser single sign-on (SSO). Three main roles are defined in SAML Specification.

  • The Principal: This is typically the user who requires a service from a service provider entity.
  • The Identity Provider: The SAML authority that provides the identity assertion to authenticate a principal.
  • The Service Provider: The SAML consumer that provides the service for principals.

The main use case scenario covered by SAML is the principal (the user) requesting access to a resource or service from the service provider. Then the service provider, using SAML, communicates with the identity provider to obtain identity assertion. The service provider makes the access control decision, depending on this assertion.

SAML 2.0 is the latest version of SAML, which uses security tokens containing assertions to pass information about a user between an identity provider and a service provider.

SAML 2.0 provides five main specifications:

  • Core
  • Bindings
  • Profiles
  • Metadata
  • Conformances

SAML 2.0 web browser-based SSO profile

SAML 2.0 Web Browser based SSO profile is defined under the SAML 2.0 Profiles specification.

In a web browser based SSO system, the flow can be started by the user either by attempting to access a service at the service provider or by directly accessing the identity provider itself.

If the user accesses a service at a service provider:

  1. The service provider determines which identity provider to use (this is the case when there are multiple identity providers. SAML identity provider discovery profile may be used).
  2. The service provider generates a SAML message and then redirects the web browser to the identity provider along with the message.
  3. Identity provider authenticates the user.
  4. The identity provider generates a SAML message and then redirects the web browser back to the service provider.
  5. The service provider processes the SAML message and decides to grant or deny access to the user.

If the user accesses the identity provider directly, then only the steps 3, 4 and 5 are in the flow.

The following diagram depicts this flow.

Figure: SAML 2.0 authentication flow

The message MUST contain an element that uniquely identifies the service provider who created the message. Optionally the message may contain elements such as Issuer, NameIDPolicy, etc. More information regarding the message can be found in SAML Core Specification.

 Click here for more information on assertion consumers, the authentication request and response.

SAML 2.0 SSO assertion consumers

Service providers act as SAML assertion consumers. They have two basic functions:

  • Create messages and redirect users to the identity provider with the created message.
  • Process messages from the identity provider and make decisions based on them.

The following code is a sketch of a sample service provider servlet in a SAML 2.0 web browser-based SSO system.

public class Resource extends HttpServlet 
{             
     private static SamlConsumer consumer = new SamlConsumer();           
     public void doGet(HttpServletRequest request, HttpServletResponse response) 
	 { 
             requestMessage = consumer.buildRequestMessage();
             response.sendRedirect(requestMessage);
     }            
     public void doPost(HttpServletRequest request, HttpServletResponse response) 
	 { 
             responseMessage = request.getParameter("SAMLResponse").toString();  
             result = consumer.processResponseMessage(responseMessage);
     }
}

When a web user attempts to access the above servlet, its doGet() method is called. Inside the doGet() method, it generates an message and then redirects the user to the identity provider.

After authentication is completed by the identity provider, it does a POST callback to the above servlet with a message. Then the doPost() method of the servlet gets called and inside the doPost() method, it retrieves the message from the request and then the message is passed to the SamlConsumer instance for processing.

<AuthnRequest> message

To create an <AuthnRequest> message using the OpenSAML library, do the following.

  1. Add the OpenSAML library to the build path of the project. You can download the OpenSAML .jar file from here.
  2. A sample <AuthnRequest> message can be found here.
  3. According to SAML 2.0 specifications, the message must contain an element. Create the Issuer element first.

    String issuerId = "saml2.sso.demo";
    IssuerBuilder issuerBuilder = new IssuerBuilder();
    Issuer issuer = issuerBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:assertion", "Issuer", "samlp");
    issuer.setValue(issuerId);
  4. Create the <AuthnRequest> next.

    // the issuerUrl is the url of the service provider who generates the  message
    String issuerUrl = "http://localhost:8080/saml2.sso.demo/consumer";
    DateTime issueInstant = new DateTime();
    AuthnRequestBuilder authnRequestBuilder = new AuthnRequestBuilder();
    AuthnRequest authnRequest = authnRequestBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest", "samlp");
    authnRequest.setForceAuthn(false);
    authnRequest.setIsPassive(false);
    authnRequest.setIssueInstant(issueInstant);
    authnRequest.setProtocolBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
    authnRequest.setAssertionConsumerServiceURL(issuerUrl);
    authnRequest.setIssuer(issuer);
    authnRequest.setID(aRandomId);
    authnRequest.setVersion(SAMLVersion.VERSION_20); 

    The message may contain many other elements like "," etc. those elements can be created and added to the message in the same way.

  5. Next encode the message.

    Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(authnRequest);
    Element authDOM = marshaller.marshall(authnRequest);
    
    StringWriter rspWrt = new StringWriter();
    XMLHelper.writeNode(authDOM, rspWrt);
    String requestMessage = rspWrt.toString();
    	     
    Deflater deflater = new Deflater(Deflater.DEFLATED, true);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater);
    deflaterOutputStream.write(requestMessage.getBytes());
    deflaterOutputStream.close();
    	     
    /* Encoding the compressed message */
    String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES);
    String encodedAuthnRequest = URLEncoder.encode(encodedRequestMessage,"UTF-8").trim();
  6. Construct the redirection URL.

    redirectionUrl = identitypProviderUrl+ "?SAMLRequest=" + encodedRequestMessage;
  7. Redirect the user to the identity provider.

    response.sendRedirect(redirectionUrl);

<Response> message

To read the <Response> message issued by the WSO2 Identity Cloud:

  1. A sample <Response> message can be found here.
  2. The response message must be fetched from the request.

    responseMessage = request.getParameter("SAMLResponse").toString();
  3. The fetched responseMessage is unmarshaled and the SAML message is retrieved.

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
     
    byte[] base64DecodedResponse = Base64.decode(responseMessage);
    ByteArrayInputStream is = new ByteArrayInputStream(base64DecodedResponse);
    Document document = docBuilder.parse(is);
    Element element = document.getDocumentElement();
    UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
    Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
    Response response = (Response) unmarshaller.unmarshall(element);
  4. The retrieved SAML 2.0 response message can be easily processed. For example, let's take the username or the subject's NameID.

    String subject = response.getAssertions().get(0).getSubject() .getNameID().getValue();
  5. Alternatively, if the response is signed by the identity provider, you can retrieve the certificate.

    String certificate = response.getSignature().getKeyInfo().getX509Datas().get(0).getX509Certificates().get(0).getValue();
Recommended reading

See SAML 2.0 specification documentation for more information.



WS-Federation

WS-Federation (Web Services Federation) describes the management and brokering of trust relationships and security token exchange across Web services and organizational boundaries. WS-Federation is a part of the larger WS-Security framework. For example, WS-Federation builds on the Security Token Service (STS) by providing mechanisms that facilitate interactions. In the WS-Federation Model, an Identity Provider is a Security Token Service (STS).

Recommended reading

See WS-Federation specification documentation for more information.



OpenID Connect

OpenID Connect is a simple identity layer on top of the OAuth 2.0 protocol. It allows Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about the End-User in an interoperable and REST-like manner.

OpenID Connect allows clients of all types, including Web-based, mobile, and JavaScript clients, to request and receive information about authenticated sessions and end-users. The specification suite is extensible, allowing participants to use optional features such as encryption of identity data, discovery of OpenID Providers, and session management, when it makes sense for them.

Recommended reading

See OpenID Connect specification documentation for more information. 

  • No labels