Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default session timeout and how to configure it when using the Spring Session with Redis as the backend

Tags:

My application currently use Spring Session together with Redis as the backend.

I searched into the official documentation for Spring Session but was not able to find what the default session timeout is when using that module.

Also I am not sure how to change that default timeout if necessary.

Can someone please advise?

like image 908
balteo Avatar asked Sep 10 '15 12:09

balteo


People also ask

What is session What is the default time for session?

The default is 20 minutes. Session Timeout property cannot be set to a value greater than 525,600 minutes (1 year). The default value is 20 minutes. default session time for asp.net is 20 minutes.

What is the default expire time of session?

The Default Expiration Period for Session is 20 Minutes. The Default Expiration Period for Cookie is 30 Minutes.

What is the default session timeout in Java?

Session timeout determines how long the server maintains a session if a user does not explicitly invalidate the session. The default value is 30 minutes.

How do I set session timeout in spring boot 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.


1 Answers

The easiest way to configure session timeout when using redis repository is

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60)

OR @EnableRedissonHttpSession(maxInactiveIntervalInSeconds = 1200) if redisson dependency is there.

The session expires when it is no longer available in the repository. Timeout can be configured with setDefaultMaxInactiveInterval(int) on both RedisOperationsSessionRepository and MapSessionRepository. Default value is 30 minutes.

If you are using spring boot, then as of version 1.3 it will automatically sync the value with the server.session.timeout property from the application configuration.

Note that one of the shortcomings when using spring session is that javax.servlet.http.HttpSessionListeners are not invoked.

If you need to react on session expiration events you can subscribe to SessionDestroyedEvent application event of your spring application.

like image 87
tsachev Avatar answered Sep 21 '22 09:09

tsachev