1.新建成功、失败工具类:DemoAuthenticationSuccessHandler、DemoAuthenticationFailureHandler:
/**
* 认证成功处理
* SavedRequestAwareAuthenticationSuccessHandler Spring对AuthenticationSuccessHandler的简单实现
* @author zhaohaibin
*/
@Slf4j
@Component("demoAuthenticationSuccessHandler")
public class DemoAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private SecurityProperties securityProperties;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
log.info("登录成功");
if(LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){
response.setContentType("application/json;charset=UTF-8")