1.修改web.xml,需要在web.xml描述文件中配置中使得o.s.s.web.session.HttpSessionEventPublisher生效,这样servelt容器将会通知Spring Security session生命周期的事件(通过HttpSessionEventPublisher)
org.springframework.web.context.ContextLoaderListener
org.springframework.security.web.session.HttpSessionEventPublisher
2.修改spring-security.xml,借助于使用session注册跟踪(通过session并发控制),实现显示系统中当前活跃用户的数量。
error-if-maximum-exceeded="false" session-registry-ref="sessionRegistry"/>
class="org.springframework.security.core.session.SessionRegistryImpl" />
3.登录过滤器修改,登录验证通过后向sessionRegistry中添加在线session
sessionRegistry.registerNewSession(token, bean);
4.在controller中调用,获取sessionRegistry中存储的用户信息
List objlist = sessionRegistry.getAllPrincipals();
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。