This commit is contained in:
2025-05-14 15:06:02 +09:00
parent 30281a40b5
commit dcc6821d10
4 changed files with 9 additions and 1 deletions

View File

@ -11,6 +11,10 @@ public class ApiResponse<T> {
//数据
private T data;
//空构造函数
private ApiResponse() {
}
private ApiResponse(ResultCode resultCode, T data) {
this.code = resultCode.getCode();
this.message = resultCode.getMessage();

View File

@ -46,6 +46,7 @@ public class SecurityConfig {
return authenticationConfiguration.getAuthenticationManager();
}
// http config
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)

View File

@ -35,14 +35,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)) {

View File

@ -23,7 +23,7 @@ import java.util.stream.Collectors;
@RestControllerAdvice
public class GlobalExceptionHandler {
// 日志记录器
// slf4j日志记录器
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
// 业务异常