spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

New session for each call to the Spring Boot server with JWT problem

Open zerone123456 opened this issue 2 years ago • 0 comments

I'm working to limit the number of sessions per user in Spring Boot, so as to limit the number of devices it can connect. this is my WebSecurityConfigurerAdapter:

http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED).maximumSessions(10).maxSessionsPreventsLogin(true);

I tried to change SessionCreationPolicy in various states, or not declare it:

http.sessionManagement().maximumSessions(10).maxSessionsPreventsLogin(true);

every time I call the server, a new session is generated, up to exceeding the declared limit, so I am no longer authorized to make a call.

I noticed that the creation of the new session takes place in GenericFilterBean, exactly after running filterChain.doFilter (req, response)

I carry the file GenericFilterBean:

**@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) { ...

filterChain.doFilter(req, response); ... }**

do you know the way to avoid that every call to the server generates a new session? My goal is one session for each device. Thanks a lot for availability !!!

zerone123456 avatar Aug 11 '22 12:08 zerone123456