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…
1) For the numer of logins the best way is to plug in to Spring Security using AuthenticationSuccessHandler, as
@user395072said and hold the result in user table innumOfSuccessfulLoginsadding +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_TIMEdoesn’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_TIMEvalue 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_TIMEto session and updating the newest one every other time. Or You can have 2 fields in user table:cumulativeTimeandcurrentSessionTime, and You add updatecumulativeTime += currentSessionTimeandcurrentSessionTime = 0when settin$MY_TIMEto session, and on any other request updatecurrentSessionTime = System.currentTimeMillis() - $MY_TIME.