You can either set the session timeout (say 60 minutes) for all sessions in web.xml:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
or on a per-session basis using
session.setMaxInactiveInterval(60*60);
the latter you might want to do in a authorizationSuccessHandler.
<form-login authentication-success-handler-ref="authenticationSuccessHandler"/>
My questions:
- Are the two approaches mentioned above same ?
- If not, how to set inactive timeout as described in second approach via Spring Configuration XML?
- What is the ideal approach to set set session timeout in spring framework?
Yes, only difference is in former case session timeout is set by servlet container e.g tomcat and in later case its done by Spring.
You have to write custom filter to set session timeout, as far as my knowledge goes there nothing where you can set session time out in Spring XML
Let the session timeout handle by container like one you define in web.xml, if you are changing session time a lot in running app, then you can consider Spring managed session timeout by using interceptor.