Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security SAML assertion expiry with Application Session Expiry

I'm getting confused with the SAML assertion expiry vs Application session expiry.

In simple words, when we have an application deployed in a container, there is a session created. This session expiry can be controlled with the below entry in web.xml

<session-config>
    <session-timeout>60</session-timeout>
</session-config>

Moving on, when I have Spring Security with SAML extension, obviously the same session concept applies. (I'm deploying the application in WildFly 8.2, if that matters)

Further, when the application session expires, the logout behaviour seems to be equivalent to Local Logout concept.

So far so good. Now lets say that the SAML assertion is good for 2 hours and the user has been actively working for 2 hours. What should happen to the subsequent request then? Should it re-login to the IDP? But, wouldnt that be inconvenient to the user? If the application redirects to IDP for logging in again after 2 hours of assertion expiry, How should AJAX requests be handled?

This is in reference to the question here

like image 468
rakpan Avatar asked Apr 29 '15 21:04

rakpan


People also ask

What happens when a SAML token expires?

You can still configure access, SAML, and ID token lifetimes after the refresh and session token configuration retirement. Existing token's lifetime will not be changed. After they expire, a new token will be issued based on the default value.

How long is a SAML response valid?

Saml response has a token lifetime of 1 hour for SAML token or it is valid till the certificate used for sign in is valid.

What is SAML assertion timeout?

This means that the SAML assertion is only valid for the specified time period. This helps detect replay attacks. Make sure that the times are correct on both the identity provider server and service provider server. If they're off by too much then this will cause the error you see.

Can a SAML assertion be reused?

Identifies the principal about which the token asserts information, such as the user of an application. This value is immutable and cannot be reassigned or reused, so it can be used to perform authorization checks safely.

Does spring security make use of session creation options?

But if the application creates one, Spring Security will make use of it. Finally, the strictest session creation option, “ stateless “, is a guarantee that the application won't create any session at all.

How does Spring Security SAML work with IDP?

We finished our Spring Security SAML configuration that allows the user to log in to the IdP and then receive the user's authentication details in XML format from the IdP. Last, it authenticates the user token to allow access to our web app. 6. HomeController

What is Spring Security SAML with Okta?

Overview In this tutorial, we'll explore Spring Security SAML with Okta as an identity provider (IdP). 2. What Is SAML? Security Assertion Markup Language ( SAML) is an open standard that allows an IdP to securely send the user's authentication and authorization details to the Service Provider (SP).

What is stateless session in Spring Security?

For a more stateless application, the “ never ” option will ensure that Spring Security itself won't create any session. But if the application creates one, Spring Security will make use of it. Finally, the strictest session creation option, “ stateless “, is a guarantee that the application won't create any session at all.


1 Answers

Spring SAML issues an ExpiringUsernameAuthenticationToken for authenticated users. The token starts returning false in its isAuthenticated() method once the SAML Assertion used to authenticate the user reaches its sessionNotOnOrAfter time.

This behavior can be disabled by overriding SAMLAuthenticationProvider and changing method getExpirationDate(credential), which returns time when the Assertion expires, or null in case it never does. Application will then fully rely on session expiration configured in the container.

Once the ExpiringUsernameAuthenticationToken expires, Spring Security will pass the current token to the AuthenticationManager (configured in securityContext.xml under <security:authentication-manager>).

You can affect what happens next, by adding your own AuthenticationProvider able to handle the ExpiringUsernameAuthenticationToken. Otherwise system fails with ProviderNotFoundException or some other AuthenticationException like BadCredentialsException (in case you're using username/password authentication at the same time).

The exception is subsequently handled by ExceptionTranslationFilter, which start new authentication process by invoking the configured authentication EntryPoint - e.g. SAMLEntryPoint which either starts authentication with default IDP or displays IDP selection page. The process will also essentially perform local logout, as you say.

System by default behaves the same for all HTTP calls - AJAX or not. You can define different behavior by splitting your API and normal URLs into separate <security:http> elements and use different EntryPoints (interface AuthenticationEntryPoint) for each. For example Http403ForbiddenEntryPoint might be suitable for your AJAX calls.

like image 175
Vladimír Schäfer Avatar answered Sep 18 '22 01:09

Vladimír Schäfer