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