我们使用“ConcurrentSessionControlAuthenticationStrategy”,具有以下配置:
<bean
class="org.springframework.security.web.authentication.session.ConcurrentSessionControlAuthenticationStrategy">
<constructor-arg ref="clusteredSessionRegistryImpl" />
<property name="maximumSessions" value="1" />
<property name="exceptionIfMaximumExceeded" value="false" />
</bean>
当用户登录,然后从不同的浏览器第二次登录时 - 我们可以看到调用以下代码(如预期):
protected void allowableSessionsExceeded(List<SessionInformation> sessions, int allowableSessions,
SessionRegistry registry) throws SessionAuthenticationException {
...
leastRecentlyUsed.expireNow();
}
“leastRecentlyUsed”是实际的较旧 session (如预期)。 现在,一切都很好,但事实是,此过期最终不会终止旧 session ,应该过期的其他浏览器 session 仍然可以与其他浏览器中的新 session 并发使用该应用程序。似乎 session 的实际销毁过程并未发生。
1) 谁\什么负责破坏 session ?
2)我们如何解决这个问题?
最佳答案
我也遇到过类似的问题,结果是浏览器缓存的问题。 看这个问题here
就我而言,我清除了缓存并注意到本应注销的浏览器最终无法访问我的网络应用程序的内容。
更新
最终发现我们在后端使用了两种配置来实现安全上下文。
我必须使 session 注册表静态并在两种配置中调用相同的实例。
private static final SessionRegistry SESSION_REGISTRY = new SessionRegistryImpl();
然后设置一个bean:
@Bean
public static SessionRegistry sessionRegistry() {
return SESSION_REGISTRY;
}
最后在两种配置中使用相同的实例:
httpSecurity
... // you configuration
.sessionManagement()
.maximumSessions(5)
.maxSessionsPreventsLogin(true)
.sessionRegistry(sessionRegistry()).and()
希望这对其他人有帮助:)
关于java - Spring security - session 上的 expireNow() 不执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32371045/