我正在尝试在 Spring Boot 应用程序中实现 OAuth 2.0。但我需要扩展的类已被弃用。而且,如果参数中没有定制器,我们就无法使用authorizeHttpRequests。
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizedRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login();
}
}
您可以使用如下新的API
@EnableWebSecurity
public class SecurityConfig{
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests(c->c
.requestMatchers("/").permitAll()
.anyRequest().authenticated())
.oauth2Login(Customizer.withDefaults())
.build();
}
}