你如何注销所有登录用户在春天的安全性? [英] How do you log out all logged in users in spring-security?
本文介绍了你如何注销所有登录用户在春天的安全性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够注销所有已登录的用户编程。你如何强制注销的所有用户对某些事件?
I want to be able to log out all logged in users programmatically. How do you force logout all users on some event?
推荐答案
首先在web.xml中定义HttpSessionEventPublisher
First define HttpSessionEventPublisher in web.xml
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
然后定义&LT;会话管理方式&gt;
在Spring security.xml文件中
Then define <session-management>
in your spring security.xml file.
现在,使用的SessionRegistry
在你的控制器方法无效所有会话。低于code检索所有活动的会话。
Now, use SessionRegistry
in your controller method to invalidate all sessions. Below code retrieves all active sessions.
List<SessionInformation> activeSessions = new ArrayList<SessionInformation>();
for (Object principal : sessionRegistry.getAllPrincipals()) {
for (SessionInformation session : sessionRegistry.getAllSessions(principal, false)) {
activeSessions.add(session);
}
}
在每个活动会话,你可以叫 expireNow()
法到期或使它们无效。
On Each active session, you can call expireNow()
method to expire or invalidate them.
这篇关于你如何注销所有登录用户在春天的安全性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文