[英]How to get serialized tomcat HttpSession to repopulate spring SessionRegistry
我执行以下操作:
HttpSessionSecurityContextRepository.readSecurityContextFromSession
与存储的会话信息(它是一个UsernamePasswordAuthenticationToken,包含一个包含Principal等的Authentication对象,因此获得自定义User对象似乎是可能的)
但是,当尝试通过以下方式使用SessionRegistry
列出登录用户时:
for (Object principal : sessionRegistry.getAllPrincipals()) {
MyCustomUser myCustomUser = (MyCustomUser) principal;
ClientQueryDetails client = clientQuery.getDetails(myCustomUser
.getClientId()).get();
List<SessionInformation> sessions = sessionRegistry.getAllSessions(
principal, false);
for (SessionInformation sessionInformation : sessions) {
result.add(new SessionInfo(client.getName(), myCustomUser
.getUsername(), sessionInformation.getSessionId(),
sessionInformation.getLastRequest()));
}
}
正如我通常用来可视化当前活动的用户/会话那样,它为空 。
为什么Spring此时不将这些主体添加到SessionRegistry中? 我可以/应该以某种方式手动进行吗?
我已经阅读了https://github.com/spring-projects/spring-security/issues/2062 ,听起来像是个坏主意。
似乎也相关,手动进行身份验证时,使用sessionRegistry登录的用户无法正常工作
所以总结一下我的问题:
SessionRegistry
呢? SessionRegistry
以便向用户( SessionRegistry
登录的用户)显示所有活动会话是否是正确的方式? 编辑是的,这绝对是SessionRegisty的目的: https ://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#list-authenticated-principals 我应该将Principal
手动添加到SessionRegistry吗? 编辑 https://github.com/spring-projects/spring-security/issues/2062提供了将会话手动读取到SessionRegistry的不同方法,但是这样做似乎有些警告。
在哪里以及如何exactely从sessions.ser会话被反序列化为以及哪里春天获得它? 换句话说,会话信息如何从sessions.ser文件获取到spring的SecurityContext
中? 特别是它是如何从雄猫“移交给”春天的?
对于在SessionRegistry中看不到Session却具有有效Session(即已登录用户)的问题,我的解决方法是在服务器重启时简单地删除SESSIONS.ser文件 。
结果,所有用户都必须再次登录,并相应地填充SessionRegistry。 由于我没有迫切需要保持会议持续进行,因此这对我来说是一个很好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.