Java 对特定URL进行Spring安全授权并拒绝所有其他URL

Java 对特定URL进行Spring安全授权并拒绝所有其他URL,java,spring,spring-boot,spring-security,Java,Spring,Spring Boot,Spring Security,我有下面的配置类,我想授权某些请求并拒绝所有其他请求 @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .httpBasic()

我有下面的配置类,我想授权某些请求并拒绝所有其他请求

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .httpBasic()
                .and()
            .authorizeRequests()
                .antMatchers("/phx-config-rest/dev/master").hasRole("DEV")
                .anyRequest().authenticated()
                .and()
            .csrf()
                .disable();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.
            inMemoryAuthentication()
                .withUser("devuser")
                .password("dev")
                .roles("DEV"); 
    }
}
根据这段代码,我的印象是,Spring只允许我使用用户“devuser”访问/phx config rest/dev/master,如果我尝试访问/phx config rest/prod/master或任何其他url,请求将被视为未经授权的访问。顺便说一句,这段代码是关于SpringCloudConfigServer的。有什么想法吗?

改变主意

.anyRequest().authenticated()

 .anyRequest().denyAll()
您仅将URL/phx config rest/dev/master限制为具有角色dev的用户,但所有其他URL对于每个登录用户都是可访问的,包括具有任何角色的用户devuser, 见:

指定任何经过身份验证的用户都允许URL

您必须使用而不是经过身份验证的:

指定任何人都不允许URL