使 Spring 安全会话无效
我需要使用户会话无效(或踢掉)。该应用程序仅限制每个容器只有一个用户登录。
我尝试从会话注册表中调用removeSessionInformation,它完成了解锁用户的操作。这样其他用户就可以使用被踢出的会话用户名登录。
但被踢出的用户的 SessionContextHolder 仍然存在。因此他们仍然具有相同的权限来访问受保护的页面。
如何从指定的会话注册表信息中使SessionContextHolder的Principal失效或删除?
ps:在我的旧应用程序中,我在 UserDomain (UserDetails) 中给出了一个保存 HttpSession 的变量。当他们需要踢用户时,我只是使指定 UserDomain 的 HttpSession 无效。但我不知道如何在春季执行此操作(与 HttpSession 相比,更有可能删除 SessionContextHolder 的主体)。实现与Spring中SessionRegistryImpl的实现几乎相同。
i need to invalidate ( or kick ) user session. the application only limit user login only one user per container.
i try to call removeSessionInformation from session registry, its done to unlock the user. so the other user can login with the kicked session user name.
but SessionContextHolder at that user that been kicked is still. so they still have the same authority to access the protected page.
how to invalidate or remove Principal of SessionContextHolder from specified session registry information?
ps : in my old application, i give one variable in UserDomain (UserDetails) that hold HttpSession. and when they need to kick the user, i just invalidate HttpSession from specified UserDomain. the but i don't know how to do it in spring (its more likey to remove Principal of SessionContextHolder than HttpSession). implementation is almost the same with how SessionRegistryImpl do in spring.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能想考虑 Spring Security 并发控制。您可以配置此选项以限制每个用户的并发会话数,并在超过该数量时使现有会话过期(踢出)。
Spring Security 会话管理
是我们的配置片段(Spring 3):
You may like to consider Spring Security Concurrency Control. You can configure this to limit the number of concurrent sessions per user and expire (kick) existing sessions if that number is exceeded.
Spring Security Session Management
This is a snippet of our configuration (Spring 3):
我猜这是这样做的方法:
来自
SecurityContext.setAuthentication(Authentication)
Javadocs:I'd guess this is the way to do it:
From the
SecurityContext.setAuthentication(Authentication)
Javadocs:您还可以执行以下操作来清除 SpringSecurity Session:
You can also do the following to clear the SpringSecurity Session:
这是从我的 application-security.xml 中提取的,
尝试在最大会话数之后添加粗体字行
This is extracted from my application-security.xml
try adding the line in bold letters after the maximum sessions number