
It's finally here:
>> The Road to Membership and Baeldung Pro.
Going into ads, no-ads reading, and bit about how Baeldung works if you're curious :)
Last updated: March 18, 2024
Security Assertion Markup Language (SAML) is an open federation identity standard for exchanging authorization and authentication data between providers. The data can be shared between many SAML-enabled applications and security domains. Thus, SAML is mainly used for SSO purposes. In this article, we’ll dive deeply into SAML fundamental concepts. We’ll relate to the latest version SAML 2.0.
SAML is an XML-based markup language for sharing security data between an identity provider and a service provider. An identity provider is a party that authenticates the user and sends the user’s identity with its authorization level data to the service provider.
On the other hand, the service provider trusts the identity provider and allows the user to access the resources based on its authorization level. Therefore, SAML provides a standardized way of exchanging security data between providers.
SAML contains security assertions that are used by providers to make access-control decisions. Moreover, SAML can provide protocol messages, protocol messages bindings, and profiles. We’ll elaborate on them in later sections.
As we’ve already noted, the main use case of SAML is SSO. Thus, the user can log in once and get access to many independent services without a need to log in separately to them. Let’s see an example of SAML workflow:
<form method="post" action="some-action-url" ...>
<input type="hidden" name="SAMLResponse" value="some-response-value" />
...
<input type="submit" value="Submit" />
</form>
The value of SAMLResponse is an encoded <samlp:Response> element.
Now, let’s see a visual representation of the workflow:
To summarize, the service provider needs a security context from the identity provider to see if the user can access a specific resource. If the context is present, the resource can be returned immediately. Otherwise, a SAML-specified request is sent to the identity provider to create the security context.
With the security context, the user can access multiple services that trust this specific identity provider without having to log in separately.
In this section, we’ll briefly introduce SAML elements. The full specification can be found on the official SAML Specifications page. Here, we’ll focus on four elements — assertions, protocols, bindings, and profiles. Those are the core elements that SAML can use.
First of all, as we can read in the official specification:
An assertion is a package of information that supplies zero or more statements made by a SAML authority.
Assertion data is placed between the following tags:
<saml:Assertion ...>
..
</saml:Assertion>
There are three types of SAML 2.0 assertion statements:
An assertion can contain one or more of the above elements. Based on these elements, providers can perform control-access decisions.
The second type of SAML element is protocols. They describe how specific elements should be packed and consumed within a request and response. SAML 2.0 provides a variety of protocols:
Each of the protocols is elaborated in the specification. Thus, we won’t go into the details here.
The third important type of element is bindings. They inform about the mechanism and mapping of SAML messages. For example, a SAML message can be encapsulated in a SOAP envelope. SAML 2.0 provides several bindings:
Last, but not least, there are SAML profiles. A profile represents how assertions, bindings, and protocols cooperate to handle a specific use case. We can read in the specification:
Generally, a profile of SAML defines constraints and/or extensions in support of the usage of SAML for a particular application – the goal being to enhance interoperability by removing some of the flexibility inevitable in a general-use standard.
There are a variety of SAML profiles, although the primary one is Web Browser SSO.
In this article, we talked about the SAML 2.0 standard. We described its workflow and core architecture. To sum up, the most important use case of the SAML standard is the SSO mechanism.