Spring 引导 HttpSecurity 流畅 api 命令?
Spring Boot HttpSecurity fluent api order?
Spring 2.0.3.RELEASE
目标:在除 /actuator/health
、/actuator/info
和 /ping
(仅 returns ResponseEntity.status(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();
}
}
下面似乎仅限于 Actuator 的 /health
和 /info
端点,但同时也打开了我的自定义 /ping
端点(它不在此列表中) .
http.requestMatcher(EndpointRequest.to("health", "info"))
.authorizeRequests().anyRequest().permitAll();
该问题最终成为 Spring 工具套件中的错误。将 Boot Dashboard
与 Gradle 项目一起使用并不总是会获取构建输出。它似乎使用了不同的目录,我无法弄清楚。
最终对我有用的 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
}
Spring 2.0.3.RELEASE
目标:在除 /actuator/health
、/actuator/info
和 /ping
(仅 returns ResponseEntity.status(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();
}
}
下面似乎仅限于 Actuator 的 /health
和 /info
端点,但同时也打开了我的自定义 /ping
端点(它不在此列表中) .
http.requestMatcher(EndpointRequest.to("health", "info"))
.authorizeRequests().anyRequest().permitAll();
该问题最终成为 Spring 工具套件中的错误。将 Boot Dashboard
与 Gradle 项目一起使用并不总是会获取构建输出。它似乎使用了不同的目录,我无法弄清楚。
最终对我有用的 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
}