Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Explain the SAML 2.0 web browser SSO flow between a Spring Boot service provider and an identity provider. What does Spring Security's saml2Login need?

In SAML 2.0 web browser SSO, the user opens the service provider, which redirects the browser to the identity provider with an AuthnRequest; after login the identity provider posts a signed SAML Response with an assertion back to the service provider's assertion consumer service. The service provider checks the signature with the identity provider's certificate, the audience, the time conditions and InResponseTo before creating the authentication. Spring Security's saml2Login() needs a RelyingPartyRegistration, which Spring Boot builds from spring.security.saml2.relyingparty.registration properties such as the metadata URI, entity id and ACS location.

Why this question is asked

SAML 2.0 is older than OIDC and uses XML, but it is still everywhere in enterprise software, and many Spring applications must log users in through a corporate SAML identity provider. Interviewers ask about the flow because SAML's security depends on a series of checks that are easy to misunderstand, and about the Spring configuration because it has changed between versions. In this answer, we will recap the vocabulary, follow the browser flow step by step, list what the service provider must validate, configure saml2Login in Spring Boot, and map assertion attributes to authorities.

1A Quick Recap of the SAML Vocabulary

SAML has two main parties. The identity provider (IdP), sometimes called the asserting party, authenticates users. The service provider (SP), called the relying party in Spring Security, is our application. Each side has an entity id, a unique name usually written as a URL, and publishes metadata: an XML document with its entity id, its endpoints and its certificates.

The IdP tells the SP who the user is with an assertion, an XML document that contains the subject (the user's identifier), conditions such as the audience and validity times, and attributes such as email and groups. The assertion travels inside a SAML Response, and the IdP signs it with its private key so the SP can verify it with the IdP's certificate. The SP's endpoint that receives responses is the assertion consumer service (ACS).

2Following the Browser SSO Flow

In the common SP-initiated flow, the user opens a protected page of our application. Spring Security sees no authentication and redirects the browser to the IdP with an AuthnRequest, a small XML message saying who is asking and where to send the answer, usually encoded in the URL or posted in a form. The IdP shows its login page, or recognises an existing IdP session, authenticates the user and builds a signed Response. It returns a page with an auto-submitting form that posts the Response to our ACS URL. Spring Security validates it, creates the authentication, and redirects the user to the page they first asked for.

Notice that the IdP and SP never talk to each other directly during login. Everything travels through the user's browser, which is why the signature and the other checks are essential: the browser, and anyone who controls it, could change the messages.

Step throughSP-initiated SAML login
BrowserSpring app (SP)Identity provider
GET /reports
redirect with AuthnRequest (ID=_a1b2)
AuthnRequest
login page, or existing IdP session
credentials and MFA
auto-posting form with signed Response (InResponseTo=_a1b2)
POST /login/saml2/sso/corp with SAMLResponse
validate signature, issuer, audience, times, InResponseTo
authenticated, redirect to /reports

9 messages in order. Play them, or step through them one at a time.

3What the Service Provider Must Validate

The SP must not trust the Response just because it arrived. Spring Security, through its OpenSAML-based authentication provider, performs the checks for us, and it is worth knowing what they are. The signature on the Response or the assertion must be valid for the IdP's certificate from the registration. The issuer must be the expected IdP. The audience restriction must name our SP entity id, so an assertion issued for another application cannot be replayed here. The time conditions, NotBefore and NotOnOrAfter, must hold, allowing a small clock skew. The InResponseTo value must match the id of an AuthnRequest we actually sent, which stops an attacker from injecting an unsolicited response. If the assertion is encrypted, it must be decrypted with our private key first.

Checks on a SAML Response
CheckWhat it stops
Signature with the IdP certificateforged or modified assertions
Issuer is the expected IdPassertions from another IdP
Audience is our entity idreplaying an assertion meant for another app
NotBefore and NotOnOrAfterold or captured assertions
InResponseTo matches our requestunsolicited or injected responses
Destination and recipient are our ACSresponses aimed at another endpoint

4Configuring saml2Login in Spring Boot

Spring Security represents each IdP connection as a RelyingPartyRegistration: our entity id and ACS location, our signing and decryption credentials if any, and the IdP's entity id, single sign-on URL and verification certificates. The easiest way to get the IdP details is its metadata URL, which Spring reads at startup. Spring Boot builds the registration from properties.

Java
# application.properties, registration id "corp"
spring.security.saml2.relyingparty.registration.corp.assertingparty.metadata-uri=https://idp.example.com/saml/metadata
spring.security.saml2.relyingparty.registration.corp.entity-id={baseUrl}/saml2/service-provider-metadata/{registrationId}
spring.security.saml2.relyingparty.registration.corp.acs.location={baseUrl}/login/saml2/sso/{registrationId}
spring.security.saml2.relyingparty.registration.corp.signing.credentials[0].private-key-location=classpath:saml/sp-key.pem
spring.security.saml2.relyingparty.registration.corp.signing.credentials[0].certificate-location=classpath:saml/sp-cert.pem
// Security configuration
http.authorizeHttpRequests(a -> a.anyRequest().authenticated())
.saml2Login(Customizer.withDefaults()) // login entry: /saml2/authenticate/corp
.saml2Metadata(Customizer.withDefaults()); // our SP metadata for the IdP administrators

The entity-id and acs.location values shown are the defaults, with placeholders that Spring fills in, so they are often left out. Our own signing credentials are needed if the IdP requires signed AuthnRequests or if we use single logout. Under the hood Spring Security uses OpenSAML: Spring Security 6.x works with OpenSAML 4, newer versions add or require OpenSAML 5, and the class names of the authentication provider follow the OpenSAML version, so check your version.

5Mapping Attributes to Authorities

After validation, Spring Security creates a Saml2Authentication whose principal holds the subject and the assertion's attributes. By default the authorities are minimal, so we map attributes such as groups to the application's roles. We do that by customising the authentication provider's response authentication converter: we start from the default converter, read the attributes, and return an authentication with our own authorities.

Java
// Spring Security 6.x with OpenSAML 4 (class names differ with OpenSAML 5, check your version)
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
var defaults = OpenSaml4AuthenticationProvider.createDefaultResponseAuthenticationConverter();
provider.setResponseAuthenticationConverter(token -> {
Saml2Authentication auth = defaults.convert(token);
var principal = (Saml2AuthenticatedPrincipal) auth.getPrincipal();
List<String> groups = principal.getAttribute("groups"); // e.g. [reports-admins, staff]
var roles = groups == null ? List.<GrantedAuthority>of() : groups.stream()
.filter(GROUP_TO_ROLE::containsKey)
.map(g -> (GrantedAuthority) new SimpleGrantedAuthority(GROUP_TO_ROLE.get(g)))
.toList();
return new Saml2Authentication(principal, auth.getSaml2Response(), roles); // [ROLE_ADMIN]
});
http.saml2Login(s -> s.authenticationManager(new ProviderManager(provider)));

The attribute names depend on the IdP: some send groups, others a long URI such as http://schemas.microsoft.com/ws/2008/06/identity/claims/groups, and email may arrive as an attribute or as the subject. We confirm the names with the IdP's administrators or by logging the attributes once in a test environment.

6Follow-up questions

What is IdP-initiated login and why is it riskier?

In IdP-initiated login the user starts at the IdP's portal, which posts a Response to our ACS without any AuthnRequest from us. There is no InResponseTo to check, so an attacker who obtains a valid response has a better chance of injecting it. Many applications disable it or accept it only with extra checks.

What happens when the IdP rotates its certificate?

If the registration reads the IdP's metadata URL, the new certificate appears in the metadata, often alongside the old one during a transition, and the application picks it up when it reloads the metadata. With a hard-coded certificate, logins fail on the rotation day until we update the configuration.

How is SAML different from OIDC for a Spring application?

Both give browser single sign-on. SAML uses signed XML posted through the browser and suits enterprise IdPs and vendor products; OIDC uses JSON tokens and also covers single-page apps, mobile apps and APIs. In Spring, saml2Login() and oauth2Login() play the same role for each protocol.

7Conclusion

In this answer, we followed SAML 2.0 web browser SSO: the SP redirects with an AuthnRequest, the IdP authenticates the user and posts a signed Response with an assertion to the SP's assertion consumer service, and the SP validates the signature, issuer, audience, times and InResponseTo before creating the authentication. In Spring Boot, saml2Login() uses a RelyingPartyRegistration built from spring.security.saml2.relyingparty.registration properties, Spring Security relies on OpenSAML 4 or 5 depending on the version, and a custom response converter maps attributes such as groups to authorities.

What to say in the interviewAbout 80 seconds aloud

Open with

In SAML web browser SSO there is the identity provider, which authenticates users, and the service provider, our Spring app. When a user opens a protected page, Spring redirects the browser to the IdP with an AuthnRequest that has an id and says where to send the answer.

Then, if they want more

The IdP logs the user in and returns an auto-submitting form that posts a signed SAML Response, containing an assertion with the subject, conditions and attributes, to our assertion consumer service, by default /login/saml2/sso/{registrationId}.

Spring then validates it: the signature against the IdP's certificate, the issuer, the audience being our entity id, the NotBefore and NotOnOrAfter times, and InResponseTo matching the request we sent, plus decryption if the assertion is encrypted. Only then does it create a Saml2Authentication.

For configuration, saml2Login needs a RelyingPartyRegistration, which Spring Boot builds from spring.security.saml2.relyingparty.registration properties: the IdP metadata URI, our entity id and ACS location, which have sensible defaults, and our signing credentials if the IdP wants signed requests. Spring Security uses OpenSAML underneath, version 4 or 5 depending on the Spring Security version, so I would check the exact provider class.

Finally I would customise the response authentication converter to map attributes like groups and email to the application's authorities.

About this answer

Last updated
12 November 2026
Versions it names
Spring Security 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain the SAML 2.0 web browser SSO flow between a Spring Boot service provider and an...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/871282e7b5/