Restricting the number of concurrent sessions per user
In the software industry, software is often sold on a per-user basis. This means that, as software developers, we have an interest in ensuring that only a single session per user exists, to combat the sharing of accounts. Spring Security’s concurrent session control ensures that a single user cannot have more than a fixed number of active sessions simultaneously (typically one). Ensuring that this maximum limit is enforced involves several components working in tandem to accurately track changes in user session activity.
Let’s configure the feature, review how it works, and then test it out!
Configuring concurrent session control
Now that we have understood the different components involved in concurrent session control, setting it up should make much more sense. Let’s take a look at the following steps to configure concurrent session control:
- Firstly, you update your
SecurityConfig.java
file...