【发布时间】:2018-12-18 19:44:17
【问题描述】:
春季 2.0.3.RELEASE
目标:在除 /actuator/health、/actuator/info 和 /ping(只返回 ResponseEntity.status(HttpStatus.NO_CONTENT).build() 的自定义控制器)之外的所有端点上实现 Spring Boot Security(初学者的基本身份验证)。
下面给了我一个401。任何组合似乎都可以让我完全匿名访问所有端点或401 对所有端点。
我已经在application.yml 中设置了spring.security.user.name 和...password,它工作正常。
我已经实现了...
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
super.configure(http);
// just trying to get health working for starters
http.authorizeRequests().antMatchers("/actuator/health").permitAll()
.anyRequest().authenticated()
.and().formLogin().permitAll();
}
}
以下内容似乎仅限于 Actuator 的 /health 和 /info 端点,但同时也打开了我的自定义 /ping 端点(不在此列表中)。
http.requestMatcher(EndpointRequest.to("health", "info"))
.authorizeRequests().anyRequest().permitAll();
【问题讨论】:
-
你试过@Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER)吗?
-
我做了,但最后没必要
-
@YogenRai,该字段已在 Spring Boot 2 中删除。1.x 版本有它:docs.spring.io/spring-boot/docs/1.5.10.RELEASE/api/org/…,但 2.x 版本没有:docs.spring.io/spring-boot/docs/current/api/org/springframework/…
标签: java spring spring-boot spring-security spring-boot-actuator