【发布时间】:2019-02-25 02:06:16
【问题描述】:
使用 org.springframework.security:spring-security-oauth2-resource-server5.1.0.RC2(通过 org.springframework.boot:spring-boot-starter-security:2.1.0.M3)我正在尝试为某些 http 路径启用安全性,但为其他路径禁用它,使用基于 JWT 的令牌安全性。
我尝试了以下方法,但它在各种路径和 http 方法上执行的安全性不一致:
- 在 GET /accounts?name=Checking 时强制执行
- 在 POST /accounts 上强制执行
- 未在 GET /customers?name=John 上强制执行
- 在 POST /customers 上强制执行
为什么它会在 POST 到 /customers 时强制执行?
@Configuration
public class SecurityConfig {
@Autowired
private ReactiveJwtDecoder jwtDecoder;
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
// @formatter:off
http
.authorizeExchange().pathMatchers("/customers").permitAll()
.and()
.authorizeExchange().pathMatchers("/customers/**").permitAll()
.and()
.authorizeExchange().pathMatchers("/accounts/**").authenticated()
.and()
.oauth2ResourceServer()
.jwt().jwtDecoder(this.jwtDecoder);
// @formatter:on
return http.build();
}
}
【问题讨论】:
-
我部分解决了这个问题。
标签: spring-boot spring-security spring-security-oauth2