关于Spring Security和会话失效的问题。
当ConcurrentSessionControlStrategy使会话失效时,会话通过调用removeSessionInformation方法从SessionRegistry中删除,但是当通过手动注销使会话失效时,HttpSession无效,但没有调用SessionRegistry从那里删除条目
我已将HttpSessionEventPublisher添加为侦听器,该侦听器捕获HttpSessionDestroyedEvent事件,但再次没有调用SessionRegistry。
我通过创建我自己的LogoutFilter实现并添加一个处理程序来手动调用removeSessionInformation来解决这个问题,但我希望能够使用标准的spring注释(如果可能的话)。 (注意,我不能使用标准注销标记的success-handler-ref字段,因为会话已经失效,因此我无法访问会话ID)
我在这里缺少什么,或者这只是春天错过的东西?
顺便说一下,这是使用Spring Security 3.1.0。
答案 0 :(得分:2)
我遇到了同样的问题。在我的例子中,解决方案是创建SessionRegistry
作为单独的spring bean。 ConcurrentSessionControlStrategy
包含指向注册表的链接,因此它可以直接从中删除无效会话。但SecurityContextLogoutHandler
使用session.invalidate()
,因此sessionDestroyed
servlet事件由HttpSessionEventPublisher
提供给HttpSessionDestroyedEvent
,但由HttpSessionEventPublisher
SessionRegistry
...
SessionRegistry sessionRegistry = new SessionRegistryImpl();
ConcurrentSessionControlStrategy concurrentSessionControlStrategy = new ConcurrentSessionControlStrategy(sessionRegistry);
...
发布到Spring上下文当它不是一个春天豆时,来到@Bean
public SessionRegistry sessionRegistry() {
return new SessionRegistryImpl();
}
...
ConcurrentSessionControlStrategy concurrentSessionControlStrategy = new ConcurrentSessionControlStrategy(sessionRegistry())
...
。
此安全配置不起作用:
{{1}}
这个很好用:
{{1}}