无法保护Spring启动管理执行器端点

Wim*_*uwe 5 java spring-security spring-boot

我正在尝试保护Spring Boot执行器端点.我在/apiREST界面上有安全性,但尝试在内置端点上添加安全性似乎不起作用.

我在我的端点中设置了端点分组application.properties:

management.context-path=/management
Run Code Online (Sandbox Code Playgroud)

我在Java Config中有这个

@Override
protected void configure( HttpSecurity http ) throws Exception
{
    http.csrf().disable();
    http.sessionManagement().sessionCreationPolicy( SessionCreationPolicy.STATELESS );

    http.authorizeRequests()
        .antMatchers( "/api/**" ).hasRole( "READONLY" )
        .antMatchers( "/management/**" ).hasRole( "ADMIN" );


    SecurityConfigurer<DefaultSecurityFilterChain, HttpSecurity> securityConfigurer = new XAuthTokenConfigurer( userDetailsServiceBean() );
    http.apply( securityConfigurer );
}
Run Code Online (Sandbox Code Playgroud)

当我使用浏览器转到下面的任何内容时/api,我会按预期返回403.当去/ management/info例如,我看到JSON被返回,我也期望403.

我也尝试将其添加到我的application.properties文件中:

management.security.role=ADMIN
Run Code Online (Sandbox Code Playgroud)

但这也没有帮助.

DEBUG输出显示:

2014-05-02 10:15:30 DEBUG [localhost-startStop-1] ExpressionBasedFilterInvocationSecurityMetadataSource - 
Adding web access control expression 'hasRole('ROLE_READONLY')', for Ant [pattern='/api/**']

2014-05-02 10:15:30 DEBUG [localhost-startStop-1] ExpressionBasedFilterInvocationSecurityMetadataSource - 
Adding web access control expression 'hasRole('ROLE_ADMIN')', for Ant [pattern='/management/**']
Run Code Online (Sandbox Code Playgroud)

然后我尝试HTTP GET的原因:

2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/css/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/js/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/images/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/**/favicon.ico'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/management/info'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] FilterChainProxy - /management/info has an empty filter list
Run Code Online (Sandbox Code Playgroud)

Dav*_*yer 2

讲述这个故事的日志是:“/management/info 有一个空的过滤器列表”,因为它被明确标记为忽略(/info 应该始终可用)。尝试其他执行器端点之一,看看它们的行为是否符合您的预期。如果您确实需要保护信息端点,您可以设置endpoints.info.sensitive=true(我认为)。