用java监控系统的平台访问和花费时间
如何使用或不使用 spring-security 在项目中实现以下功能。
1. LoggedIn Count:用户登录系统的次数。
2.花费时间:用户花费的总时间。
到目前为止,我已经考虑过使用javascript的解决方案,其中定期向服务器发送一个请求。在服务器内部,它将增加花费时间变量。
仍然想知道,spring-security 本身是否有任何东西。或者任何其他处理此类功能的想法。
任何想法/建议将不胜感激......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我过去使用过完全相同的技术(只是不是 SpringSecurity)并且做了类似的事情,我想我可以让你知道如何做到这一点。我认为它会起作用:
1
要计算成功登录的名称,您将需要实体中的变量。
当用户成功登录时,该变量需要加一。我认为增加该值的最佳时机是验证正确并且授予访问权限(您可以在验证方法中实现)。
因此,您要做的就是使用 Hibernate 查询语言获取该用户的变量的当前值,加 1,然后更新该行。
2
对于这个,我不确定 100%,但你可以尝试一下:
User 表中名为 loginTime 的变量需要以 @ApplicationState 形式存在。
然后在注销函数中,您将创建一个 tempVariable 来保存当前时间的时间(一个长变量)。
您将执行减法操作(logOutTime - logInTime),您将获得该会话花费的时间(以毫秒为单位)。
因此,在擦除会话并真正注销之前,只需使用结果更新要注销的用户的数据库中的列即可。
另外我想提一下,这两个想法可能会使用编程方法解决问题,但我确信,如果您调查 Spring Security,您可能会找到在某种日志或类似日志中查找该信息的方法(从未使用过) Spring Security之前)
我希望我正确地解释了我的自我。
祝你好运
I worked with those exactly same technologies in the past(just not SpringSecurity) and i did a similar thing, i think i can give you an idea of how you could do that. I think it will work:
1
To count the name of successful logins, you will need a variable in an entity.
That variable needs to increase by one when the user successfully logs. I think the best time to increase that value is if the validation is correct and the access is granted(You could implement that in the validation method).
So what you do is get the current value of the variable for that user using the Hibernate Query Language, add 1 and then update the row.
2
For this one i am not sure at 100% but you can give it a try:
A variable in the User table called loginTime needs to exist as @ApplicationState.
Then in your logout function you will create a tempVariable that will hold the time(a long variable) at that current time.
You will do a substract operation(logOutTime - logInTime) and you will get the time in milliseconds expend on that session.
So just before erasing the session and loging out for real, just update a column in the DB for the user that is going to logout with the result.
Also i would like to mention that this 2 ideas might solve the problem using a programmatical approach, but i am sure that if you investigate about Spring Security, you might find the way of finding that info in some kind of logs or similar(Never used Spring Security before)
I hope i explained my self correctly.
Good Luck
1) 对于登录次数,最好的方法是使用 AuthenticationSuccessHandler 插入 Spring Security,如
@user395072
所说,并将结果保存在numOfSuccessfulLogins
的用户表中,添加 +1每次成功登录时。2) 对于在网站上花费的时间,您需要的只是一个会话变量,我们将其称为
$MY_TIME
。然后,在每个请求上,如果会话中不存在$MY_TIME
,则将其设置为当前日期(即System.currentTimeMillis()
) 。如果它确实存在,那么您将获取当前时间并减去$MY_TIME
值,您将获得当前会话到目前为止所花费的时间。对于同样的请求,您需要坚持下去。当您将$MY_TIME
设置为会话并每隔一段时间更新最新记录时,您可以有一个单独的表来添加新记录。或者您可以在用户表中有2个字段:cumulativeTime
和currentSessionTime
,并且您添加更新cumulativeTime += currentSessionTime
和currentSessionTime = 0
将$MY_TIME
设置为会话时,以及在任何其他请求时更新currentSessionTime = System.currentTimeMillis() - $MY_TIME
。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 innumOfSuccessfulLogins
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
andcurrentSessionTime
, and You add updatecumulativeTime += currentSessionTime
andcurrentSessionTime = 0
when settin$MY_TIME
to session, and on any other request updatecurrentSessionTime = System.currentTimeMillis() - $MY_TIME
.有很多方法可以做到这一点,这取决于您所遵循的架构。
您可以使用以下
或
使用 Spring Security
或使用任何自定义过滤器
人们通常用于用户跟踪/分析的更多指针
一旦所有这些信息都存储在持久存储中,他们通常会在其之上创建一个报告/过程以获取所有这些信息,例如一天中有多少用户,或者用户有多少次一个月内或多长时间内登录过他是否在该网站上度过了一个月等等...
There are many ways you can do this, it depends on the architecture that you are following.
you can use following
or
of using spring security
or using any custom filters
Few more pointers which people generally use for user tracking/analysis
Once all this information is stored in a persistent store, they usually create a report / procedure on top of it to get all those information like how many users in a single day, or how many times a user have logged-in during a month or how long did he spent on the site during a month etc...