spring-boot - Spring-Boot 执行器/关闭端点被禁止
问题描述
我第一次使用 Spring Boot 应用程序时,执行器是不安全的,因此很容易通过 /actuator/shutdown 端点远程关闭。最近,我使用 Spring security 保护了我的执行器,并且它有效。现在我需要提供 http 基本凭据来访问端点,但现在 curl 对 /actuator/shutdown 端点的调用失败并出现 Forbidden 错误。我必须在某处配置不正确。
我的卷曲命令:
curl -XPOST -u 执行器:密码http://host:port/actuator/shutdown -k
我可以调用其他端点,似乎只有关闭端点是被禁止的。
我的配置:
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.info.git.mode=full
management.endpoint.shutdown.enabled=true
management.server.port=8081
spring.security.user.name=actuator
spring.security.user.roles=ACTUATOR
spring.security.user.password=password
编辑:
@Configuration
public static class ActuatorWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
.anyRequest().hasRole("ACTUATOR")
.and()
.httpBasic();
}
}
解决方案
解决方案是在 WebSecurityConfigureAdapter 配置方法中禁用 csrf。
http.csrf().disable();
推荐阅读
- java - 没有代码重复的 Java Entity 和 BusinessObject
- php - 为什么我在不使用 get 方法时不断收到“The GET method...”?
- amazon-web-services - 为什么 terraform 试图重建已经提供的基础设施?
- javascript - 按图标从顶部滑入下拉移动菜单
- python - 问题是球循环一直在循环,你无法控制角色,因为循环一直在运行
- ej2-syncfusion - 如何在电子 js 应用程序中添加 Syncfusion EJ2 网格控件
- c# - 不和谐的SDK错误ue4
- javascript - 使用正则表达式更改文件夹中的监视文件
- reactjs - 反应如何使用历史推送将 id 传递给路由器
- python - 转到章节/问题的第一页