aspose file tools*
The moose likes Performance and the fly likes Session Management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Session Management" Watch "Session Management" New topic
Author

Session Management

Shunmuga Raj
Greenhorn

Joined: Jul 22, 2011
Posts: 5
hi,
i'm creating a web application to ensure multiple users can concurrently feed data for report generation. i need to make one user can login to oly one system at a time. he cant create new session from any other system or same system itself. any idea? hav any tutorial or sample codes?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I don't see how this is related to performance but I don't know where to move it as you didn't provide us with much information. Could you explain why you want this, what technologies/frameworks you're using etc...


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Shunmuga Raj
Greenhorn

Joined: Jul 22, 2011
Posts: 5
i'm using jsp with ajax for frontend and mysql for backend. not for such performance related, one user shouldnt hav multiple session at a time that was the constraint. giv me some ideas?
mohana krishna
Greenhorn

Joined: Apr 12, 2005
Posts: 8
Creata a table in database.
When a user login ener the data in into the table.
If the same user tries to login check data is already presest for that user in Data base.
If data alreday data is present display message to user stating that you have already loged in.
When user log off from session delete data from data base.
When session is expired delete data in data base using Session Listener.
If the user close the session abnormally use a separate application to unlock(delete the data from data base) the appplication.

--Mohan
mohana krishna
Greenhorn

Joined: Apr 12, 2005
Posts: 8
Issue 1 : Session time out case

Create class UserSessionListener which implements HttpSessionListener
In UserSessionListener Class give the implementation for method

sessionDestroyed(HttpSessionEvent objHttpSessionEvent) in this method write code to delete data from data base.

Configure session listener in Web.xml file.

<listener>

<description>UserSession Listiner</description>

<display-name>UserSessionListener</display-name>

<listener-class>com.user.oci.applicationlock.listener.UserSessionListener</listener-class>

</listener>

Case 2 : Abnormal termination of session.


Write a small JSP page which accepts USER id (One which you want to unlock )as input may be admin may have rights to unlock the user.

When user enters the user name submits the page then you delete the data for that user from Data base.

For all these cases
You may create one USER object and store it in session when user is loged in.
When user id loged off , session time out or unlocking using the application delete the object from the session.


Regards,
Mohan.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

mohana krishna wrote:Creata a table in database.
When a user login ener the data in into the table.
If the same user tries to login check data is already presest for that user in Data base.
If data alreday data is present display message to user stating that you have already loged in.
When user log off from session delete data from data base.
When session is expired delete data in data base using Session Listener.
If the user close the session abnormally use a separate application to unlock(delete the data from data base) the appplication.

--Mohan

This is a nice design. However, it can be modified slightly to avoid special unlocking application:

  • Add an autoincrement field in the table called eg. SESSIONID.
  • When the user logs in, remember the generated SESSIONID in the applicaton.
  • Modify every database operation to verify that the SESSIONID stored in the application still exists in the table. If it does not, throw an exception ("User session was terminated").
  • When the user logs in, verify that he is not already logged. If he is, offer him to remove the old login record and add a new one, thus killing the previous session.
  • Logging off and session expiration without change.

  • This way, every user can 'kill' his own sessions. Since the user has been authenticated (I presume), he cannot do harm to any other user. No need to have a special application or privileged user to unlock accounts. Care needs to be taken with database locking while modifying the login table to make this work.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Session Management