Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ensure the same account is not used to log in two different people at the same time in Spring Security?

I have a Spring MVC app that does not protect updates of user data with transactions.

It assumes that only a single user is accessing the account data for that account at any one time.

However, if two users were to log in using the same authentication credentials, it is theoretically possible, although unlikely, for two database updates on the same user data to overlap and conflict.

Is there a simple way to protect against this in Spring Security?

like image 488
cheese Avatar asked Dec 06 '25 20:12

cheese


2 Answers

Spring Security supports protection against concurrent logins. See 2.3.3 Session Management for instructions of how to enable it.

like image 181
axtavt Avatar answered Dec 08 '25 14:12

axtavt


Add a column to the user database called "logged in". If that value is set, then refuse a second login.

like image 45
Aaron Digulla Avatar answered Dec 08 '25 16:12

Aaron Digulla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!