springboot3中security配置

渡星河
2023-05-11 / 0 评论 / 22 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年05月11日,已超过497天没有更新,若内容或图片失效,请留言反馈。

在Spring Boot 2.7.5中,我们曾经这样做:

@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();
  }
}

但是在springboot3中,我们得做调整

@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();
  }
}
0

评论 (0)

取消