Results 1 to 3 of 3

Thread: Session timeout handling

  1. #1

    Exclamation Session timeout handling

    I am using spring security and i have a custom logout filter.

    Code:
     public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        
        UserSessionMap sessionMap = UserSessionMap.getInstance();
          String userId = authentication.getName();    
          sessionMap.invalidateUserSession(userId);
          notifyUserLogout(userId);
          sessionMap.printMap();    
    }
    Now the issue is i haven't set any timeout in web.xml and if i keep the screen logged in for some time around 2 hrs or so and click logout i got NULL POINTER EXCEPTION in

    Code:
    String userId = authentication.getName();
    which i guess is due to automatic timeout authentication object becomes null and name couldn't be found. But in that case i will not be able to do DB clean up as required. Can someone please tell me how do i capture a timeout even and call the above method to do DB clean up.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    There is always a session timeout, if there wouldn't be your servers would be cluttered with old session data causing serious issues in the end. The default for tomcat is 30 minutes I believe but it can differ from container to container.

    You will need to create a HttpSessionListener and probably implement the sessionDestoyed method. That however does not give you the user etc. but if gives you the sessionId, so if you have some way of determing which sessionId is tied to which user you can still cleanup the data.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Hi Marten,

    Thanks for your reply. I guess i have a singleton hashmap in the application where i am maintaining the user session for all the users who have logged in along with their userId, and even if i got the session Id it will work for me. Thanks again for your valuable suggestion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •