loopback
This commit is contained in:
@ -11,6 +11,10 @@ public class ApiResponse<T> {
|
|||||||
//数据
|
//数据
|
||||||
private T data;
|
private T data;
|
||||||
|
|
||||||
|
//空构造函数
|
||||||
|
private ApiResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
private ApiResponse(ResultCode resultCode, T data) {
|
private ApiResponse(ResultCode resultCode, T data) {
|
||||||
this.code = resultCode.getCode();
|
this.code = resultCode.getCode();
|
||||||
this.message = resultCode.getMessage();
|
this.message = resultCode.getMessage();
|
||||||
|
@ -46,6 +46,7 @@ public class SecurityConfig {
|
|||||||
return authenticationConfiguration.getAuthenticationManager();
|
return authenticationConfiguration.getAuthenticationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http config
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http.csrf(AbstractHttpConfigurer::disable)
|
http.csrf(AbstractHttpConfigurer::disable)
|
||||||
|
@ -35,14 +35,17 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
final String jwt;
|
final String jwt;
|
||||||
final String username;
|
final String username;
|
||||||
|
|
||||||
|
//不需要token,直接返回Chain
|
||||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//透过token读取username
|
||||||
jwt = authHeader.substring(7);
|
jwt = authHeader.substring(7);
|
||||||
username = jwtService.extractUsername(jwt);
|
username = jwtService.extractUsername(jwt);
|
||||||
|
|
||||||
|
//如果username为空且认证为空
|
||||||
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
||||||
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
|
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
|
||||||
if (jwtService.isTokenValid(jwt, userDetails)) {
|
if (jwtService.isTokenValid(jwt, userDetails)) {
|
||||||
|
@ -23,7 +23,7 @@ import java.util.stream.Collectors;
|
|||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
// 日志记录器
|
// slf4j日志记录器
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||||
|
|
||||||
// 业务异常
|
// 业务异常
|
||||||
|
Reference in New Issue
Block a user