Spring Security 弃用 WebSecurityConfigurerAdapter 重写登录接口 前后端分离 返回json数据格式

springboot 版本高于 2.7 之后 弃用了 WebSecurityConfigurerAdapter  推荐使用组件化配置安全组件。

原版本的2.7版本的登录接口  

功能: 通过/api/doLogin 进行登录 

package cn.devops.config;

import cn.devops.model.User;
import cn.devops.response.RespBean;
import cn.devops.service.DevopsService;
import cn.devops.service.UserService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.*;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
imp

你可能感兴趣的:(spring,java,后端)