content: package com.spring4all.config;
  
  import com.alibaba.fastjson.JSON;
  import com.spring4all.bean.WebResponse;
  import org.springframework.http.MediaType;
  import org.springframework.security.core.Authentication;
  import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  import java.nio.charset.StandardCharsets;
  
  /**
   * 认证成功处理器
   */
  public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
  
      @Override
      public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
          WebResponse response = WebResponse.success("登录成功");
          httpServletResponse.setStatus(HttpServletResponse.SC_OK);
          httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
          httpServletResponse.setCharacterEncoding(StandardCharsets.UTF_8.toString());
          httpServletResponse.getWriter().write(JSON.toJSONString(response));
      }
  
  }