我执行以下操作:
HttpSessionSecurityContextRepository.readSecurityContextFromSession
使用存储的Session-Information(它是一个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此时不会将这些Principal添加到SessionRegistry? 可以/我应该以某种方式手动完成吗?
我读过https://github.com/spring-projects/spring-security/issues/2062这听起来像这样做是个坏主意。
似乎还有Getting logged in users with sessionRegistry not work when manually authenticate
总结一下我的问题:
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会话的不同方法,但似乎有一些注意事项。
来自 sessions.ser 的会话在何处以及如何被反序列化以及Spring获取它的位置?或者换句话说,会话信息如何从sessions.ser文件进入春天的SecurityContext
?特别是如何移交&#34;从tomcat到spring?
答案 0 :(得分:0)
我在SessionRegistry中没有看到Sessions但是拥有有效Sessions(即登录用户)的问题的解决方案是,只需删除服务器重启时的SESSIONS.ser文件。
因此,所有用户都必须再次登录,并相应地填充SessionRegistry。由于我没有迫切需要保持会议活着,这对我来说是一个很好的解决方案。