java在JBoss AS 6中侦听登录事件
我有一个在JBossAS6中运行的应用程序。身份验证正在使用“表单”身份验证方法工作,并且用户正在正确登录
每当用户成功登录时,我希望能够调用一段自定义的静态代码
不幸的是,我找不到任何监听器、钩子或回调,它们将在成功登录时执行代码。HttpSessionListener确实有一个“sessionCreated”事件,但一旦用户访问任何页面,就会调用该事件,即使用户尚未成功登录。这意味着,即使查看登录表单也会触发事件
有人能给我介绍一些JBossAS6(或同等版本)的文档吗?这些文档展示了如何在用户首次成功登录时运行自定义代码
提前谢谢
# 1 楼答案
我能想到的解决办法是使用一个
CustomFormAuthenticator
扩展org.apache.catalina.authenticator.FormAuthenticator
并将其注册到/server/default/deployers/jbossweb.deployer/META-INF/war-deployers-jboss-beans.xml
。 现在在JBossAS7中,他们引入了阀的概念,您可以在jboss-web.xml
iteself中注册CustomAuthenticator
类似于
现在,需要在
/server/default/deployers/jbossweb.deployer/META-INF/war-deployers-jboss-beans.xml
中的server
注册这个 将以下entry
添加到authenticators
部分然后,在网络上。xml将
CUSTOM-FORM
作为auth-method
希望这有帮助
# 2 楼答案
您可以在安全Servlet前面添加
ServletFilter
实现在每次调用时,过滤器将测试
HttpSession
中的布尔标志notFirstCall
如果该标志不存在,则该请求是用户登录后的第一个请求。它可以调用指定的作业,然后设置标志
notFirstCall
,将该作业标记为此会话完成# 3 楼答案
像javax.servlet.http.HttpSessionBindingListener这样的东西怎么样? 创建一个对象,在用户成功登录时按您喜欢的方式填充该对象,并将其作为属性添加到用户会话中。因此:
要绑定对象,请执行以下操作:
设置属性时,它将调用valueBound方法 这对于跟踪用户也很方便(将登录/注销信息保存到db等)