2012-04-11 51 views
1

我使用Spring 3.1.1.Release,Security 3.1.0.Release。安全SessionFixationProtectionStrategy干扰会话scoped bean

我已将登录/注销添加到我的Web应用程序,但会话范围的bean未按照原样运行。该bean用于连接到名为CMSConnector的CMS。

为了验证用户,我实现了一个AuthenticationProvider,并且在authenticate()调用中,我获得了会话范围的CMSConnector并调用了CMSConnector.login()。如果CMS登录失败,则登录失败。

的问题 -

如果登录成功,@PreDestroy注销()在成功登录后立即调用。然后我发现SessionFixationProtectionStrategy正在调用前一个会话的无效并为其分配一个新的会话。

session.invalidate(); 
session = request.getSession(true); // we now have a new session 

invalidate()正在调用会话范围的bean的@predestroy方法。

因此,我暂时删除了@predestroy注释,导致连接未关闭。 (非常糟糕的做法)。

什么是解决此问题的方法?

我试着创建一个@PostConstruct并将登录过程放在那里,但是在调用request.getSession(true)时不会调用@PostConstruct。

谢谢!

杰森

回答

0

我并没有解决我原来的问题,但我实现了一个解决方法 - 在会话过期会话过期对象,而不是用@PreDestroy连接。

0

我认为它不是SessionFixationProtectionStrategy但ConcurrentSessionControlStrategy。

设置最大的会话=“ - 1”此代码snippet

+0

Thanks Ravi,在调试会话中,我的preDestroy被SessionFixationProtectionStrategy进程调用。 – Jason 2012-04-17 15:21:34