Spring 用于API安全的AntMatcher和contextPath

Spring 用于API安全的AntMatcher和contextPath,spring,spring-boot,spring-security,spring-oauth2,Spring,Spring Boot,Spring Security,Spring Oauth2,我有spring启动应用程序。我已经配置了OAuth2——授权服务器和资源服务器(分开)。在资源服务器(application.properties)中,我有: 以及: @Configuration @EnableResourceServer public class ResourceServerConfig extends ResourceServerConfigurerAdapter { (...) @Override public void configure(H

我有spring启动应用程序。我已经配置了OAuth2——授权服务器和资源服务器(分开)。在资源服务器(
application.properties
)中,我有:

以及:

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
    (...)

    @Override
    public void configure(HttpSecurity http) throws Exception {
                http
                .requestMatchers()
                .and()
                .authorizeRequests()
                .antMatchers("/actuator/**", "/api-docs/**").permitAll()
                .antMatchers("/api/**" ).authenticated();
    }
}
问题是,api实际上根本不安全。多亏了博士,我知道这一点

模式不能包含上下文路径

事实上,从:

.antMatchers("/api/**" ).authenticated();
致:


很好。但问题是:在这个用例中是否可以使用上下文路径,而不是使用
/**
?我可以为每个控制器重复
.antMatchers()
(或使用
/**
),但也许有一种方法可以使用上下文路径?

2.0.5。发布
为什么需要上下文路径?你为什么认为它更好?但是,您始终可以实现自己的
请求匹配程序
。我认为,当您使用特定的上下文
/api/**
时,它比任何东西都更具可读性。它让我感觉到我并没有意外地影响到
/api/**
之外的东西。第二个原因可能是我有多个上下文,并且希望对每个上下文应用不同的安全逻辑。
.antMatchers("/api/**" ).authenticated();
.antMatchers("/**" ).authenticated();