• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to invalidate a session in one browser when the same user login from any other browser?

 
Anshul K Jain
Greenhorn
Posts: 20
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,

Consider i have a user with User Id : - anshul@gmail.com .Now i am loggin with this id in firefox. At the same time i am open other browser IE and login again with the same id.

I need when the try to login with the same id in diffrent browser the session of first browser will removed automatically. So in this case user can remain logged in with IE. not FireFox.


Please help me ..

Thanks
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to maintain a mapping of Sessions to User's.

When a new session is being created for a user, if that user already has a session, invalidate the first session.
 
Anshul K Jain
Greenhorn
Posts: 20
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can you please provide me a sample code for it .
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Do you use any kind of Security framework? I know you can set Spring Security to do this in its configuration.
If not then as Chinna said, create a map of users to session IDs. If a user logs in and is already in the map, then invalidate the previous session and add their new one, otherwise add them to the map.

Sean
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to use HttpSessionListener for this functionality.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic