6

application.yml我尝试在配置文件中禁用生产环境的所有执行器端点:

endpoints.enabled: false

它适用于除 /info 之外的所有端点。如何关闭给定环境的所有端点?

更新:

我正在做的项目也是 Eureka 的客户。在 Spring Cloud Netflix 文档中的状态页面和运行状况指示器( http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html ) 部分中,它说“Eureka 实例默认为”/info“和“/健康”分别“。

是否有任何解决方案可以禁用这些端点?

我能够使用 禁用/health端点endpoints.enabled: false,但不能禁用/info端点。

4

2 回答 2

13

最后我设法解决了我的问题。我在执行器中仅启用了 /info 和 /health 端点。为了只允许具有 ADMIN 角色的用户访问 /info 端点,我需要混合执行器管理安全性和弹簧安全性配置。

所以我的application.yml看起来像这样:

endpoints.enabled: false

endpoints:
    info.enabled: true
    health.enabled: true

management.security.role: ADMIN

和这样的弹簧安全配置(我需要更改ManagementSecurityConfig的顺序以获得更高的优先级):

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {


    @Configuration
    protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

        @Autowired
        private AuthenticationProvider authenticationProvider;

        public AuthenticationSecurity() {
            super();
        }

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
             auth.inMemoryAuthentication().withUser("admin").password("secret").roles("ADMIN");
        }
    }

    @Configuration
    @Order(Ordered.HIGHEST_PRECEDENCE + 2)
    public static class ManagementSecurityConfig extends WebSecurityConfigurerAdapter {


        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable()
                    .requestMatchers()
                    .antMatchers("/info/**")
                    .and()
                    .authorizeRequests()
                    .anyRequest().hasRole("ADMIN")
                    .and()
                    .httpBasic();
        }
    }

    @Configuration
    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

        protected void configure(HttpSecurity http) throws Exception {
            // API security configuration
        }

    }
}
于 2015-12-24T09:56:14.913 回答
0

您的示例配置对我来说看起来很可疑。我猜你的意思是

endpoints:
  enabled: true

无论如何,我只是试图将它添加到一个普通的 Spring Boot 应用程序(使用1.3.1并且所有端点都被禁用(如预期的那样)。

于 2015-12-22T06:23:26.633 回答