gstackoverflow
gstackoverflow

Reputation: 37098

Use sessionRegistry without session count limit for user?

To use

@Autovired
SessionRegistry sessionRegistry

in my code I have added following configuration:

http.sessionManagement()
        .maximumSessions(1)
        .sessionRegistry(sessionRegistry());

But I don't want to limit maximum sessions.

Can I achieve it?

Upvotes: 2

Views: 225

Answers (2)

gstackoverflow
gstackoverflow

Reputation: 37098

-1 - special value to say spring don't limit user sessions

http.sessionManagement()
        .maximumSessions(-1)
        .sessionRegistry(sessionRegistry());

https://docs.spring.io/spring-security/site/docs/5.0.0.BUILD-SNAPSHOT/reference/htmlsingle/#list-authenticated-principals

Upvotes: 1

moonberry
moonberry

Reputation: 103

Add this to enable multiple logins of same user with different sessions but invalidates the old session with the start of the new.

http.sessionManagement()
        .maximumSessions(1)
        .sessionRegistry(sessionRegistry()).and().enableSessionUrlRewriting(false)
.sessionFixation().newSession()

Upvotes: 0

Related Questions