websecurityconfigureadapter 无法解析为类型

问题描述 投票:0回答:1

我正在尝试在 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();
}
}
java spring-boot spring-security spring-security-oauth2
1个回答
0
投票

您可以使用如下新的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();
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.