|
26 | 26 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
27 | 27 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
28 | 28 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
| 29 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; |
29 | 30 | import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
30 | 31 | import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
|
31 | 32 | import org.springframework.security.config.http.SessionCreationPolicy;
|
@@ -71,35 +72,39 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
|
71 | 72 | // 添加JWT filter
|
72 | 73 | .addFilterBefore(new JeeAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class)
|
73 | 74 | .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(); |
97 | 76 | });
|
98 | 77 |
|
99 | 78 | // 构建过滤链并返回
|
100 | 79 | return http.build();
|
101 | 80 | }
|
102 | 81 |
|
| 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 | + |
103 | 108 | @Bean
|
104 | 109 | public UserDetailsService userDetailsService() {
|
105 | 110 | return username -> userDetailsService.loadUserByUsername(username);
|
|
0 commit comments