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
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.