【发布时间】:2013-12-22 09:16:00
【问题描述】:
我正在使用 Spring Security,我想遍历所有打开的会话并使用 HttpSession.setMaxInactiveInterval(timeout); 更改超时
我考虑过使用SessionRegistry.getAllSessions(),但它只返回SessionInformation 实例而不是HttpSession 对象。
【问题讨论】:
我正在使用 Spring Security,我想遍历所有打开的会话并使用 HttpSession.setMaxInactiveInterval(timeout); 更改超时
我考虑过使用SessionRegistry.getAllSessions(),但它只返回SessionInformation 实例而不是HttpSession 对象。
【问题讨论】:
Spring Security 中没有任何东西可以做到这一点 - 正如您所观察到的,SessionRegistry 不保留 HttpSession 实例。
因此,您必须维护自己的活动会话图,使用HttpSessionListener 记录会话创建和销毁(与your question from yesterday 的答案中描述的差不多。
它可能是Map<String,HttpSession>,其中键是会话 ID。
然后,您可以随时迭代该映射并修改会话对象。不要忘记使用线程安全映射并在会话过期时删除它们(在sessionDestroyed 方法中)。
【讨论】: