red*_*edi 19 java authentication spring spring-security logout
我希望能够以编程方式注销所有登录用户.如何在某些事件上强制注销所有用户?
Ket*_*tan 18
首先在web.xml中定义HttpSessionEventPublisher
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
然后<session-management>在spring security.xml文件中定义.
现在,SessionRegistry在您的控制器方法中使用以使所有会话无效.下面的代码检索所有活动会话.
List<SessionInformation> activeSessions = new ArrayList<SessionInformation>();
for (Object principal : sessionRegistry.getAllPrincipals()) {
for (SessionInformation session : sessionRegistry.getAllSessions(principal, false)) {
activeSessions.add(session);
}
}
Run Code Online (Sandbox Code Playgroud)
在每个活动会话中,您可以调用expireNow()方法使其过期或使其无效.
| 归档时间: |
|
| 查看次数: |
5461 次 |
| 最近记录: |