How does Spring Security handle session management, and what are the options for handling concurrent sessions?

Spring Security creates a session upon successful login by default and offers explicit configuration for limiting and controlling concurrent sessions per user, preventing account sharing or stale sessions from lingering.

Key Points

Example

A banking app configures maximumSessions(1) with maxSessionsPreventsLogin(false), so logging in on a new device automatically invalidates the session on the old device rather than blocking the new login.

http.sessionManagement(session -> session
    .maximumSessions(1)
    .maxSessionsPreventsLogin(false)
    .expiredUrl("/login?expired"));

Interview Tip

A concise interview answer is

Spring Security creates a session at login and lets me control concurrency through sessionManagement().maximumSessions(), which caps how many active sessions a user can have and decides whether a new login blocks or the oldest session gets expired. SessionRegistry lets me inspect or force-expire specific sessions if needed.

Last updated: 16 July 2026

Previous question: What is the purpose of the Spring Security filter chain, and how do you add or customize a filter in it?

Next question: You've encountered an issue where users are being unexpectedly denied access to a resource they should have access to. Describe your approach to debugging this issue in a Spring Security-enabled application.

More Spring Security - Level I interview questions

All Spring Security - Level I questions