我目前正在将 REST 应用程序从 Spring Boot 2.7.5 迁移到 3.0.0-RC2。我希望除了 Open API URL 之外的所有内容都是安全的。在 Spring Boot 2.7.5 中,我们曾经这样做:
@Named
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/openapi/openapi.yml").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud)
效果很好。在 Spring Boot 3 中,我不得不将其更改为
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((requests) -> requests
.requestMatchers("/openapi/openapi.yml").permitAll()
.anyRequest()
.authenticated())
.httpBasic();
return http.build();
}
}
Run Code Online (Sandbox Code Playgroud)
由于 WebSecurityConfigurerAdapter 已被删除。但它不起作用。Open API URL 也通过基本身份验证得到保护。我在升级代码时是否犯了错误,或者这可能是 Spring Boot 3 RC 2 …