无法解析“ExpressionInterceptUrlRegistry”中的“antMatchers”方法

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

我有以下 Spring Security 配置,我想将其迁移到 Spring Cloud 3/Spring Security 6:

public class SecurityConfig extends ResourceServerConfigurerAdapter {
  
  @Override
  public void configure(final HttpSecurity http) throws Exception {

    http.authorizeRequests()
        .antMatchers(permittedAntMatchers())
        .permitAll();

    http.authorizeRequests().antMatchers("/**").authenticated();

    final OAuth2AuthenticationEntryPoint obj =
        new OneplatformOAuth2AuthenticationEntryPoint();

    http.exceptionHandling().authenticationEntryPoint(obj);
  }
}

我收到多个错误:

'org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter' is deprecated 

Cannot resolve method 'antMatchers' in 'ExpressionInterceptUrlRegistry'

'org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint' is deprecated 

你知道我如何正确迁移这段代码吗?

spring spring-boot spring-security-oauth2
1个回答
0
投票
@Configuration
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
        return httpSecurity
                .authorizeHttpRequests(auth -> {
                    auth.requestMatchers("/patterns").permitAll();
                    auth.anyRequest().authenticated();
                })
                .build();
    }
}

这就是在没有configurerAdaptor和ant匹配器的情况下进行基本配置的方法。不幸的是,我对异常处理部分不太了解,但我想你可以在构建之前添加它,它仍然可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.