• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restrict user

 
Nithish Yalamanchili
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I need a solution for this problem. Generally in any application when user logins from a browser, at the same time if the same user logins from different machine or browser, then it should display you are logged in some where ,please logout from tht. My code is in struts and JSP, please tell me the solution.

Nithish
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a application level hashmap, when user logged in, add it to the hashmap, when user logged out remove it from hashmap.whenever user is logging in check with hashmap whether user is already present in map,if so deny him.

There may be chance user has simply close the browser without logging off.

This is not optimized solution.
 
John Melton
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very similar solution I have used in the past is to store this information in the database. This allows for tracking of user sessions over a period of time. However, it is an extra DB call. It seems to work fairly well though. The point that Vidya makes is also true. You would have to write a session timeout listener to remove the user from either the hash map or the database in order to make sure they could login again. The timeout listener would be called whenever the session times out (configured in web.xml)
Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic