Spring-Security: Call method after authentication

后端 未结 7 1331
一整个雨季
一整个雨季 2021-02-01 04:52

I\'d like to track when users are logging in to my application. I have some code that I would like to execute right after the user is authenticated. The problem is, I can\'t fig

7条回答
  •  礼貌的吻别
    2021-02-01 05:22

    probably will be usefull for someone... In case of Spring 3, configure security:

    
        
        
        
        
    
    
    
    
    
    

    and implement an appropriate class:

    public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {
    
        @Override
        public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
            //do what you want with 
            response.getOutputStream().write("success".getBytes());
        }
    }
    

    You can link resources via that xml config.

提交回复
热议问题