diff --git a/src/main/java/com/nekolr/saber/config/WebSecurityConfig.java b/src/main/java/com/nekolr/saber/config/WebSecurityConfig.java index ec6d303..9e65dc3 100644 --- a/src/main/java/com/nekolr/saber/config/WebSecurityConfig.java +++ b/src/main/java/com/nekolr/saber/config/WebSecurityConfig.java @@ -1,6 +1,5 @@ package com.nekolr.saber.config; -import com.nekolr.saber.security.jwt.JwtAuthenticationEntryPoint; import com.nekolr.saber.security.jwt.JwtAuthenticationFilter; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; @@ -20,7 +19,6 @@ public class WebSecurityConfig { private final JwtAuthenticationFilter jwtAuthenticationFilter; - private final JwtAuthenticationEntryPoint authenticationEntryPoint; @Bean public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { @@ -38,9 +36,6 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti // X-XSS-Protection: 1; mode=block .headers(configurer -> configurer.xssProtection(config -> config.headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK))) - // 授权异常处理 - .exceptionHandling(configurer -> configurer.authenticationEntryPoint(authenticationEntryPoint)) - // 不需要 session .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) diff --git a/src/main/java/com/nekolr/saber/security/jwt/JwtAuthenticationEntryPoint.java b/src/main/java/com/nekolr/saber/security/jwt/JwtAuthenticationEntryPoint.java deleted file mode 100644 index d6922d9..0000000 --- a/src/main/java/com/nekolr/saber/security/jwt/JwtAuthenticationEntryPoint.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nekolr.saber.security.jwt; - -import com.nekolr.saber.support.I18nUtils; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.stereotype.Component; - -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.Serializable; - -@Component -public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable { - - @Resource - private I18nUtils i18nUtils; - - @Override - public void commence(HttpServletRequest request, HttpServletResponse response, - AuthenticationException exception) throws IOException { - - // This is invoked when user tries to access a secured REST resource without supplying any credentials - // We should just send a 401 Unauthorized response because there is no 'login page' to redirect to - // Here you can place any message you want - response.sendError(HttpServletResponse.SC_UNAUTHORIZED, - exception == null ? i18nUtils.getMessage("exceptions.unauthorized") : exception.getMessage()); - } -}