Solved

Finding If a Session  is Valid using the Session ID

Posted on 2002-03-18
3
173 Views
Last Modified: 2010-04-01
Hello All,
     I am currently working on a web application where in
a user is allowed to edit a particular record. I will have
to restrict 2 users from editing the same record, for this
reason i am using the Session Id of the user to know which
user is editing a particular record.

     I have a seperate table which stores the entries like
the record (unique identified) and the session id. Each
time a person is about to edit or delete a particular
record i go and see if  that particular record is being
edited by another user.

    Now the problem is if the session has expired, i don't
have a control of the record which i had created. So if
another user tries to update or delete he is still not able to edit or delete that particular record.

    Now i have the Session Id of the user who started
editing that particular record, now i will have to find
out if the session is valid.

    Can any one help me out to solve the above problem.
I am current using tomcat 3.2.3 on Red Hat Linux .


V. Ramkumar.

any other user
0
Comment
Question by:V_Ram
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
kotan earned 100 total points
ID: 6879091
You can use event/listener method to delete the record which had created. Here is the steps:

Create an object which implement HttpSessionBindingListener. This object will be stored in a session.
Then, you should implement the valueBound() and valueUnBound() method. The valueUnbound() method will
be trigger if this object being unbound (This happen when the object is being replaced and session  
is invalid). In here, you can get the invalid session and delete away the record from the database.

public class BoundObj implements HttpSessionBindingListener {
   public BoundObj() {}
   public void valueBound(HttpSessionBindingEvent be) {
        // Will be trigger when this object being bound.
   }

   public void valueUnBound(HttpSessionBindingEvent be) {
       HttpSession hs = be.getSession();
       String userid = hs.getAttribute("userid");
       String sessionid = hs.getID();
       ....
       // Delete database record.
   }
}
At the time the user login which you create a new session, put the bound object in that session.
session.setAttribute("boundobj", new boundObj());
0
 

Author Comment

by:V_Ram
ID: 6882031
Hello Kotan,
   It Did Work , thanks for you timely help. By the way
does this class gets a message when the Browser is closed.

V. Ramkumar.


     
0
 
LVL 6

Expert Comment

by:kotan
ID: 6882038
if the browser is closed,then it will wait until the session expire to get the message.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
A Short Story about the Best File Recovery Software – Acronis True Image 2017
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now