JCN*_*JCN 1 curl spring-boot spring-boot-actuator
我第一次使用 Spring Boot 应用程序时,执行器没有受到保护,因此很容易通过 /actuator/shutdown 端点远程关闭。最近,我使用 Spring security 保护了我的执行器,并且它起作用了。现在我需要提供 http 基本凭据来访问端点,但现在对 /actuator/shutdown 端点的curl 调用失败并出现禁止错误。我一定是某个地方配置不正确。
我的卷曲命令:
curl -XPOST -u 执行器:密码http://主机:端口/执行器/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
Run Code Online (Sandbox Code Playgroud)
编辑:
@Configuration
public static class ActuatorWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
.anyRequest().hasRole("ACTUATOR")
.and()
.httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud)
解决方案是在 WebSecurityConfigureAdapter 配置方法中禁用 csrf。
http.csrf().disable();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3779 次 |
| 最近记录: |