Spring security: save sessions status and get sessions after restart app

Viewed 713

I use spring security, that create sessions if user has authorized. I want to get all active sessions if I restart my app. This means that if the user is authorized and I reloaded my application, the user should not be authorized again, he should continue to work in his session. How can i did this?

1 Answers

Store all the session details either in the database or Cache.

  <dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-jdbc</artifactId>
  </dependency>

or

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
</dependency>

Refer to the below documentation,

Cache: https://spring.io/projects/spring-session-data-redis

Database: https://spring.io/projects/spring-session-jdbc

Session Properties: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#security-properties

Related