java - How can I have list of all users logged in my web application -


i use spring-mvc , each use logged in web app create session variable user object containing id, name , others info.

session.setattribute("user", user); 

what want have list of users logged in program.

i want list check simultaneous log in because must 1 access account.

ps : don't tell me use spring-security because want work mvc interceptor , prehandle()

1) use below code auto-wire servletcontext object in spring mvc

@autowired servletcontext context;  

2) need collect logged in users set in context.

...     public void login(user user) {         logins.add(user);     } ...         public void logout(user user) {         logins.remove(user);     } 

if you're storing logged-in users in session already

public void sessiondestroyed(httpsessionevent event) {     user user = (user) event.getsession().getattribute("user");     if (user != null) {         set<user> logins = (set<user>) event.getsession().getservletcontext().getattribute("logins");         logins.remove(user);     } } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -