Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting session timeout period with Spring Security 3.0

I am using Spring Security 3.0 to authenticate with an LDAP server and I cannot figure out to set my own session timeout period. I believe that the default is 30 minutes but I need to set it to longer than that

like image 462
Benoit Martin Avatar asked Mar 22 '11 00:03

Benoit Martin


People also ask

How do I set session timeout in Spring Security?

Spring Security Session Timeout In the case of Tomcat we can set the session timeout by configuring the maxInactiveInterval attribute on the manager element in server. xml or using the session-timeout element in web. xml. Note that the first option will affect every app that's deployed to the Tomcat instance.

What is Spring session timeout?

If we don't specify the duration unit, Spring will assume it's seconds. In a nutshell, with this configuration, the session will expire after 15 minutes of inactivity. The session is considered invalid after this period of time.


2 Answers

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"/> 
like image 97
sourcedelica Avatar answered Sep 21 '22 08:09

sourcedelica


If you are using Spring Boot you can do so by adding the following to the application.properties file:

server.session.cookie.max-age=<your_value_in_seconds> 
like image 41
Mohammed Fathi Avatar answered Sep 20 '22 08:09

Mohammed Fathi