加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Spring Boot Actuator – 无法禁用/ info端点

发布时间:2020-12-14 05:38:59 所属栏目:Java 来源:网络整理
导读:我尝试在application.yml配置文件中禁用生产环境的所有执行器端点: endpoints.enabled: false 它适用于除/ info之外的所有端点. 如何关闭给定环境的所有端点? 更新: 我正在做的项目也是Eureka的客户. 在状态页面和健康指标(http://cloud.spring.io/spring
我尝试在application.yml配置文件中禁用生产环境的所有执行器端点:
endpoints.enabled: false

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

更新:

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

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

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

解决方法

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

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

endpoints.enabled: false

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

management.security.role: ADMIN

像这样的spring安全配置(我需要将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
        }

    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读