Java Spring Boot HttpSecurity fluent api订单?
弹簧2.0.3.1释放 目标:在所有端点上实现Spring引导安全性(启动器的基本身份验证),除了Java Spring Boot HttpSecurity fluent api订单?,java,spring,spring-boot,spring-security,spring-boot-actuator,Java,Spring,Spring Boot,Spring Security,Spring Boot Actuator,弹簧2.0.3.1释放 目标:在所有端点上实现Spring引导安全性(启动器的基本身份验证),除了/exactor/health、/exactor/info和/ping(一个只返回响应状态(HttpStatus.NO_CONTENT).build()之外 下面给了我一个401。任何组合似乎都可以让我完全匿名访问所有端点,或者401访问所有端点 我已经在application.yml中设置了spring.security.user.name和…password,它工作正常 我已经实现了 @Conf
/exactor/health
、/exactor/info
和/ping
(一个只返回响应状态(HttpStatus.NO_CONTENT).build()之外
下面给了我一个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();
}
}
下面的内容似乎仅限于执行器的/health
和/info
端点,但同时也打开了我的自定义/ping
端点(不在此列表中)
这个问题最终成为Spring工具套件中的一个bug。在Gradle项目中使用Boot Dashboard
,并不总能获得构建输出。它似乎在使用另一个目录,我想不出来
最终对我起作用的HttpSecurity配置是:
@Override
protected void configure(final HttpSecurity http) throws Exception {
// @formatter:off
http.
authorizeRequests().
antMatchers("/ping", "/actuator/health", "/actuator/info", "/login").permitAll().
anyRequest().authenticated().and().
httpBasic().and().
// CSRF tokens for API access
csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
// @formatter:on
}
你试过@Order(ManagementServerProperties.ACCESS\u OVERRIDE\u Order)吗?我试过了,但在end@YogenRai,该字段已在Spring Boot 2中删除。1.x版本有:,但2.x版本没有:
@Override
protected void configure(final HttpSecurity http) throws Exception {
// @formatter:off
http.
authorizeRequests().
antMatchers("/ping", "/actuator/health", "/actuator/info", "/login").permitAll().
anyRequest().authenticated().and().
httpBasic().and().
// CSRF tokens for API access
csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
// @formatter:on
}