I am developing spring MVC application, in my project, i have login page where I can successfully log in, the problem is that if I open new tab and log in with different username it's logging in, means at a time in the same browser I am able to login in multiple users which I don't want ,I want my application to single user login per browser how to make it.
-
1Normally, sessions would give you a cookie which is persistent across all tabs. – Laur Ivan Jan 31 '17 at 06:54
-
2Possible duplicate of [How to differ sessions in browser-tabs?](http://stackoverflow.com/questions/368653/how-to-differ-sessions-in-browser-tabs) – Laur Ivan Jan 31 '17 at 06:55
-
I believe this is something you need to control via Javascript rather than via Spring. – Vishwas Shashidhar Jan 31 '17 at 07:01
2 Answers
While rendering login page, you check authentication. If you are using Spring security, you can check for principal auth present or not. If auth is present render home page else render login page. I think this can solve your issue neatly.
- 880
- 3
- 13
- 35
I suppose that Spring Security session management is what you're looking for:
Spring Security is able to prevent a principal from concurrently authenticating to the same application more than a specified number of times. Many ISVs take advantage of this to enforce licensing, whilst network administrators like this feature because it helps prevent people from sharing login names. You can, for example, stop user “Batman” from logging onto the web application from two different sessions. You can either expire their previous login or you can report an error when they try to log in again, preventing the second login.
For more information, read the following docs:
- 14,904
- 7
- 53
- 69