通过注销弹出安全会话失效

时间:2012-05-02 07:50:43

标签: spring-security session-management

关于Spring Security和会话失效的问题。

当ConcurrentSessionControlStrategy使会话失效时,会话通过调用removeSessionInformation方法从SessionRegistry中删除,但是当通过手动注销使会话失效时,HttpSession无效,但没有调用SessionRegistry从那里删除条目

我已将HttpSessionEventPublisher添加为侦听器,该侦听器捕获HttpSessionDestroyedEvent事件,但再次没有调用SessionRegistry。

我通过创建我自己的LogoutFilter实现并添加一个处理程序来手动调用removeSessionInformation来解决这个问题,但我希望能够使用标准的spring注释(如果可能的话)。 (注意,我不能使用标准注销标记的success-handler-ref字段,因为会话已经失效,因此我无法访问会话ID)

我在这里缺少什么,或者这只是春天错过的东西?

顺便说一下,这是使用Spring Security 3.1.0。

1 个答案:

答案 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}}