Skip to content

Commit 3eda4f1

Browse files
author
zhuxiao
committedJan 7, 2025
优化静态资源和ignore路径不进过滤器
1 parent c10b401 commit 3eda4f1

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed
 

‎jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/secruity/WebSecurityConfig.java

+28-23
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
2727
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2828
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
29+
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
2930
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
3031
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
3132
import org.springframework.security.config.http.SessionCreationPolicy;
@@ -71,35 +72,39 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
7172
// 添加JWT filter
7273
.addFilterBefore(new JeeAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class)
7374
.authorizeHttpRequests((auth) -> {
74-
auth
75-
.requestMatchers(HttpMethod.GET,
76-
"/",
77-
"/*.html",
78-
"/favicon.ico",
79-
"/*/*.html",
80-
"/*/*.css",
81-
"/*/*.js",
82-
"/*/*.png",
83-
"/*/*.jpg",
84-
"/*/*.jpeg",
85-
"/*/*.svg",
86-
"/*/*.ico",
87-
"/*/*.webp",
88-
"/*.txt",
89-
"/*/*.xls",
90-
"/*/*.mp4" //支持mp4格式的文件匿名访问
91-
).permitAll()
92-
.requestMatchers(
93-
"/api/anon/**", //匿名访问接口
94-
"/webjars/**","/v3/api-docs/**", "/doc.html", "/knife4j/**", "/swagger-ui/**", "/swagger-resources/**" // swagger相关
95-
).permitAll()
96-
.anyRequest().authenticated();
75+
auth.anyRequest().authenticated();
9776
});
9877

9978
// 构建过滤链并返回
10079
return http.build();
10180
}
10281

82+
@Bean
83+
public WebSecurityCustomizer ignoringCustomizer() {
84+
return (web) -> web.ignoring()
85+
.requestMatchers(HttpMethod.GET,
86+
"/",
87+
"/*.html",
88+
"/favicon.ico",
89+
"/*/*.html",
90+
"/*/*.css",
91+
"/*/*.js",
92+
"/*/*.png",
93+
"/*/*.jpg",
94+
"/*/*.jpeg",
95+
"/*/*.svg",
96+
"/*/*.ico",
97+
"/*/*.webp",
98+
"/*.txt",
99+
"/*/*.xls",
100+
"/*/*.mp4" //支持mp4格式的文件匿名访问
101+
)
102+
.requestMatchers(
103+
"/api/anon/**", //匿名访问接口
104+
"/webjars/**","/v3/api-docs/**", "/doc.html", "/knife4j/**", "/swagger-ui/**", "/swagger-resources/**" // swagger相关
105+
);
106+
}
107+
103108
@Bean
104109
public UserDetailsService userDetailsService() {
105110
return username -> userDetailsService.loadUserByUsername(username);

‎jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/secruity/WebSecurityConfig.java

+28-23
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
2727
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2828
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
29+
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
2930
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
3031
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
3132
import org.springframework.security.config.http.SessionCreationPolicy;
@@ -71,35 +72,39 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
7172
// 添加JWT filter
7273
.addFilterBefore(new JeeAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class)
7374
.authorizeHttpRequests((auth) -> {
74-
auth
75-
.requestMatchers(HttpMethod.GET,
76-
"/",
77-
"/*.html",
78-
"/favicon.ico",
79-
"/*/*.html",
80-
"/*/*.css",
81-
"/*/*.js",
82-
"/*/*.png",
83-
"/*/*.jpg",
84-
"/*/*.jpeg",
85-
"/*/*.svg",
86-
"/*/*.ico",
87-
"/*/*.webp",
88-
"/*.txt",
89-
"/*/*.xls",
90-
"/*/*.mp4" //支持mp4格式的文件匿名访问
91-
).permitAll()
92-
.requestMatchers(
93-
"/api/anon/**", //匿名访问接口
94-
"/webjars/**","/v3/api-docs/**", "/doc.html", "/knife4j/**", "/swagger-ui/**", "/swagger-resources/**" // swagger相关
95-
).permitAll()
96-
.anyRequest().authenticated();
75+
auth.anyRequest().authenticated();
9776
});
9877

9978
// 构建过滤链并返回
10079
return http.build();
10180
}
10281

82+
@Bean
83+
public WebSecurityCustomizer ignoringCustomizer() {
84+
return (web) -> web.ignoring()
85+
.requestMatchers(HttpMethod.GET,
86+
"/",
87+
"/*.html",
88+
"/favicon.ico",
89+
"/*/*.html",
90+
"/*/*.css",
91+
"/*/*.js",
92+
"/*/*.png",
93+
"/*/*.jpg",
94+
"/*/*.jpeg",
95+
"/*/*.svg",
96+
"/*/*.ico",
97+
"/*/*.webp",
98+
"/*.txt",
99+
"/*/*.xls",
100+
"/*/*.mp4" //支持mp4格式的文件匿名访问
101+
)
102+
.requestMatchers(
103+
"/api/anon/**", //匿名访问接口
104+
"/webjars/**","/v3/api-docs/**", "/doc.html", "/knife4j/**", "/swagger-ui/**", "/swagger-resources/**" // swagger相关
105+
);
106+
}
107+
103108
@Bean
104109
public UserDetailsService userDetailsService() {
105110
return username -> userDetailsService.loadUserByUsername(username);

0 commit comments

Comments
 (0)
Please sign in to comment.