feat(security): 配置安全过滤器链支持异步请求

- 添加 DispatcherType.ASYNC 类型匹配以允许异步请求通过
- 添加 Order 注解确保安全过滤器链正确排序
- 导入必要的 jakarta.servlet.DispatcherType 和 org.springframework.core.annotation.Order 依赖
This commit is contained in:
zkh
2026-02-04 01:15:08 +08:00
parent 01d29e6ec3
commit f152b1e655
@@ -1,6 +1,7 @@
package vip.jcfd.web.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.http.HttpHeaders;
@@ -110,8 +112,10 @@ public class WebSecurityConfig {
}
@Bean
@Order
public SecurityFilterChain security(HttpSecurity http, TokenFilter tokenFilter, AuthenticationManager authenticationManager) throws Exception {
http.authorizeHttpRequests(config -> {
config.dispatcherTypeMatchers(DispatcherType.ASYNC).permitAll();
config.requestMatchers(securityProps.getIgnoreUrls()).permitAll();
config.anyRequest().authenticated();
});