spring 安全过滤器链-在一个SecurityFilterChain中有两个.authorizeHttpRequest

ruyhziif  于 2024-01-05  发布在  Spring
关注(0)|答案(1)|浏览(147)

如果我在同一个securityConfig中有两个.authorizeHttpRequests,像这样:

  1. @Configuration
  2. @EnableWebSecurity
  3. public class SecurityConfig {
  4. @Bean
  5. public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
  6. http
  7. .csrf(Customizer.withDefaults())
  8. .authorizeHttpRequests(authorize -> blahblahblah
  9. )
  10. .httpBasic(Customizer.withDefaults())
  11. .formLogin(Customizer.withDefaults())
  12. .authorizeHttpRequests(authorize -> blahblahblah
  13. )
  14. return http.build();
  15. }
  16. }

字符串
我的问题是,第二个.authorizeHttpRequest会取代第一个吗?

qybjjes1

qybjjes11#

第二个授权对象使用第一个授权对象。
下面的源代码广告

  1. private <C extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>> C getOrApply(C configurer)
  2. throws Exception {
  3. C existingConfig = (C) getConfigurer(configurer.getClass());
  4. if (existingConfig != null) {//If it already existed, return the previous configurer
  5. return existingConfig;
  6. }
  7. return apply(configurer);
  8. }

字符串

相关问题