I am building a struts 2 application with JPA. A user can login into the application multiple times. I want
- user to be able to view all his session in a grid and probably highlight the current session and optionally the user can select a session and terminate it.
- An administrator should also be able to see all the logged in users and can also view all the sessions of each logged in user and also can optionally terminate any of the sessions.
Thanks
I think
HttpSessionBindingListeneris what are you looking for.I won’t write down the complete code, just suggest you a way you can do it:
You can add a static field (Map) to your
User class (DTO)where you will store all activesessions of users. :e.g
private static Map<User, HttpSession> usersSessions= new HashMap<User, HttpSession>();Then make
User classimplemetsHttpSessionBindingListener. This way you can specifyvalueBound(HttpSessionBindingEvent event)method in which you can grab actually createdsessionand put it into yourusersSessionslike this :usersSessions.put(this, event.getSession());In
valueUnbound(HttpSessionBindingEvent event)method then :usersSessions.remove(this);to removeusers sessionafterlogout.This way you have
Mapof all of youractive sessionsalso with information to which user it belongs to. IMO you can figure out your other problems easily with this.