I am developing a webapp that uses Spring Security as security layer.
One important feature for us is to know which user is accessing the application, and how many time they are spending on it.
I’m not sure how to deal with it. Is there some other framework that deals with this kind of usage statistics?
Is there some way to use Spring Security itself to deal with it?
// I’m reading more about Spring Security and it seems that its filters can help me. Any progress will be shared here.
I think one of the solutions I can think of is using a HttpSessionListener, If you implement a Session listener you could capture the time as and when a new user session is created and destroyed, You could leverage your spring security context holder to get a hold of the uniquename/userid of the logged in user
I am thinking some thing like this
That being said there are few down sides to this approach, If the HTTP Session never gets invalidated then you will end up with some sessions with no end time.
UPDATE
You are right I think you could use spring application event mechanism, to do that add this to your web.xml, This listener publishes HTTP session events other wise you won’t be able to access session events even if you implement ApplicationListener
Now add a new class that implements ApplicationListener
There is another event if you would like to capture logout by itself, You can implement LogoutHandler that gives you access to logut event.