是的,您可以使用SessionDestroyedEvent做到这一点。
@Componentpublic class SessionEndedListener implements ApplicationListener<SessionDestroyedEvent> { @Override public void onApplicationEvent(SessionDestroyedEvent event) { for (SecurityContext securityContext : event.getSecurityContexts()) { Authentication authentication = securityContext.getAuthentication(); YourPrincipalClass user = (YourPrincipalClass) authentication.getPrincipal(); // do something } }}
并在web.xml中:
<listener> <listener-class> org.springframework.security.web.session.HttpSessionEventPublisher </listener-class></listener>
常规注销和会话超时都会触发此事件。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)