views:

57

answers:

2
+1  Q: 

count active users

I'm using spring security 2.

1.may i know how to use securitycontextholder to get total number of active users?
2. can retrieve sessionregistry from securitycontextholder?

+3  A: 

extend AuthenticationProcessingFilter

override

@Override
    protected void onSuccessfulAuthentication(HttpServletRequest request,
            HttpServletResponse response, Authentication authResult)
            throws IOException {  

and here you can do the things you want to do by keeping a application variable .

org.life.java
+1  A: 

I do not know how to do with spring. But in servlets you need to implement a HttpSession Listener interface for a listener class . The interface has two methods namely sessionCreated() and sessionDestroyed() . Whenever a new session is created you can increment the static variable in the method sessionCreated.

Suresh S
sessionCreated will be invoked if user hit login page. where i think he needs the active user ,logged in users.
org.life.java
@org.life.java you create a session on login page or after user authentication is succesfull
Suresh S
As far as Spring Security is concern this is the proper place feel to track login event.
org.life.java
@org i didnt understand this sentence "this is the proper place feel to track login event"
Suresh S
Sorry I miss spelled in hurry :) , I meant the method from spring filter i have mentioned in my answer i feel this is the proper place to track login event in the system.
org.life.java
@org ok understood.
Suresh S
Yours answer is equally true.
org.life.java