File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to prevent login by the same user from different machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to prevent login by the same user from different machine" Watch "How to prevent login by the same user from different machine" New topic
Author

How to prevent login by the same user from different machine

Shriram Pandit
Greenhorn

Joined: Apr 08, 2011
Posts: 11
Hi,

I am developing web app in struts 2 and I have requirement where if user is trying to login from different machine only one session (recent) should be allowed and all other session should invalidated.


Please help me in this regard,

Really appreciate your help.

Thanks,
Shriram.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

You 'll need to keep track of which users are logged in and a reference to their session (say by putting a random number in it that you then store in the database.) That way you know if the user comes in with a new session.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shriram Pandit
Greenhorn

Joined: Apr 08, 2011
Posts: 11
Thanks Jeanne for the reply but real problem is we never know if client closes browser without properly logging out. Also do you think if it would be a overhead on database becuase every request there will database call.

Please suggest.

Thanks in advance.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Shriram Pandit wrote:Thanks Jeanne for the reply but real problem is we never know if client closes browser without properly logging out.

Right. But that problem isn't solvable.

Shriram Pandit wrote: Also do you think if it would be a overhead on database becuase every request there will database call.

You can cache in memory for X seconds rather than check every request. Or if you are only running on one clone/JVM, you can do the whole thing in memory. If not, what alternatives do you have? You could write to the file system, but that's not going to better.
Shriram Pandit
Greenhorn

Joined: Apr 08, 2011
Posts: 11
Thanks Jeanne for the Reply.

Now I am trying to convince my manager to implement this functionality using database. That would be easy as well as reliable.

Will let you know once this is done. Appreciate your help.

Cheers.
 
jQuery in Action, 2nd edition
 
subject: How to prevent login by the same user from different machine