Logout/Session timeout catching with spring security

后端 未结 3 1739
一向
一向 2020-11-28 21:16

I\'m using spring/spring-security 3.1 and want to take some action whenever the user logs out (or if the session is timed out). I managed to get the action done for logout b

3条回答
  •  孤独总比滥情好
    2020-11-28 21:59

    I've got a simpler solution. This works for both logout and session timeout.

    @Component
    public class LogoutListener implements ApplicationListener {
    
        @Override
        public void onApplicationEvent(SessionDestroyedEvent event)
        {
            List lstSecurityContext = event.getSecurityContexts();
            UserDetails ud;
            for (SecurityContext securityContext : lstSecurityContext)
            {
                ud = (UserDetails) securityContext.getAuthentication().getPrincipal();
                // ...
            }
        }
    
    }
    

    web.xml:

    
        org.springframework.security.web.session.HttpSessionEventPublisher
    
    

提交回复
热议问题