File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to invalidate a session in one browser when the same user login from any other browser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to invalidate a session in one browser when the same user login from any other browser?" Watch "How to invalidate a session in one browser when the same user login from any other browser?" New topic
Author

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

Anshul K Jain
Greenhorn

Joined: Jul 24, 2010
Posts: 20

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

Joined: Dec 08, 2009
Posts: 174

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.


- Chinna
Anshul K Jain
Greenhorn

Joined: Jul 24, 2010
Posts: 20

Hi,
Can you please provide me a sample code for it .
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

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


I love this place!
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

You may want to use HttpSessionListener for this functionality.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to invalidate a session in one browser when the same user login from any other browser?