Java 弹簧启动执行器-无法禁用/info端点
我尝试在Java 弹簧启动执行器-无法禁用/info端点,java,spring-boot,spring-boot-actuator,Java,Spring Boot,Spring Boot Actuator,我尝试在application.yml配置文件中禁用生产环境的所有执行器端点: endpoints.enabled: false 它适用于除/info之外的所有端点。 如何关闭给定环境的所有端点 更新: 我正在从事的项目也作为尤里卡的客户。 在Spring Cloud Netflix的文档中,状态页和健康指示器()部分指出“Eureka实例分别默认为“/info”和“/Health” 是否有任何解决方案来禁用这些端点 我可以使用端点禁用/health端点。enabled:false,但不能使用
application.yml
配置文件中禁用生产环境的所有执行器端点:
endpoints.enabled: false
它适用于除/info之外的所有端点。
如何关闭给定环境的所有端点
更新:
我正在从事的项目也作为尤里卡的客户。
在Spring Cloud Netflix的文档中,状态页和健康指示器()部分指出“Eureka实例分别默认为“/info”和“/Health”
是否有任何解决方案来禁用这些端点
我可以使用
端点禁用/health端点。enabled:false
,但不能使用/info端点 我觉得您的示例配置可疑。我想你是说
endpoints:
enabled: true
在任何情况下,我只是尝试将其添加到一个香草Spring Boot应用程序中(使用
1.3.1
),所有端点都被禁用(如预期的那样).最后,我设法解决了我的问题。我只在执行器中启用了/info和/health端点。为了只允许具有管理员角色的用户访问/info端点,我需要混合执行器管理安全和spring安全配置
因此,我的application.yml如下所示:
endpoints.enabled:false
端点:
info.enabled:true
health.enabled:true
management.security.role:管理员
spring安全配置如下(我需要更改ManagementSecurityConfig的顺序以获得更高的优先级):
保护终结点可能是您唯一的选择。在生产中禁用似乎是一个奇怪的选择,因为您正在关闭使用启动器的功能。我能够通过附加的web安全配置(在启动器的默认安全配置旁边工作)来保护/info终结点。我不喜欢的是,除了/info之外的所有执行器端点都可以通过执行器配置来保护,即
management.security.enabled:true
。但是为了保护/info端点,我需要仅为此端点创建单独的web安全配置。似乎我在代码中做了一些修改。我刚刚更新了我的问题n、 问题是项目中也使用了Eureka。无论如何,我需要禁用端点,所以我需要将端点设置为false,即endpoints.enabled:false
。问题是它适用于/health endpoint,但不适用于/info。
@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
}
}
}