Q:

Monitor Platform access and spend time of the system in java

How can I implement following functionality in a project using or without using spring-security.
1. LoggedIn Count: Number of times the user has logged into the system.
2. Time Spend: Total time spent by user.
As of now, I have thought about the solution using javascript, in which one request will be sent to the server periodically. And inside the server it will increment the spendtime variable.
Still would like to know that, is there anything coming alongwith spring-security itself or not. Or any other idea to handle such functionality.
Any idea/suggestion would be highly appreciated...

A:

1) For the numer of logins the best way is to plug in to Spring Security using AuthenticationSuccessHandler, as @user395072 said and hold the result in user table in numOfSuccessfulLogins adding +1 on every successful login.
2) For the time spent on the site all You need is a session variable, lets'a call it $MY_TIME. Then on every request if $MY_TIME doesn't exist in session, you set it to the current date (i.e. System.currentTimeMillis()). If it does exist, than You take the current time and substract the $MY_TIME value and You have the time spent so far in current session. On the same request You need need to persist it. You can have a separete table for it adding a new record when You set the $MY_TIME to session and updating the newest one every other time. Or You can have 2 fields in user table: cumulativeTime and currentSessionTime, and You add update cumulativeTime += currentSessionTime and currentSessionTime = 0 when settin $MY_TIME to session, and on any other request update currentSessionTime = System.currentTimeMillis() - $MY_TIME.

