I am using spring security 3 and would like to display the time when user logged in to current session.
Does Spring security provide any such token?
Thanks, - Akshay
I am using spring security 3 and would like to display the time when user logged in to current session.
Does Spring security provide any such token?
Thanks, - Akshay
According to the documentation, you can add your own filters to the Spring Security filter chain.
You could add a filter after
UsernamePasswordAuthenticationFilter
, if you are usinghttp/form-login
, or afterBasicAuthenticationFilter
, in case ofhttp/http-basic
, so we guarantee that the session is already created.To cover both, you can add a filter after the last one, and add the information to the session.
Declare your filter-bean:
Add it to the chain, right after
BasicAuthenticationFilter
:Your
doFilter
method should look like:Keep in mind that you can use other hooks. You can add it even to your AuthenticationProvider.
EDIT:
There is a easier way to do that, if you are using
form-login
.You can use a custom
AuthenticationSuccessHandler
. To define it, update yourform-login
tag, adding the attributeauthentication-success-handler-ref
.The most reliable option would be customizing your Spring Security filter chain to save a timestamp in the user's session when a successful login occurs. Then you would access it in the same way you access any session attribute.