我在 Spring Boot Webflux 应用程序中使用 Spring 安全性主要在HTTPS
端口上提供流量。但是,作为一项操作要求,我需要在我的 Spring Boot 应用程序中支持几个非安全的 REST API 路径,以进行健康检查等也需要公开HTTP
。
SecurityWebFilterChain
那么,除了使用bean的已知路径之外,如何强制对 HTTPS 的所有请求?
这就是我定义我的SecurityWebFilterChain
bean的方式:
@Configuration
@EnableWebFluxSecurity
public class SecurityConfig {
@Bean
SecurityWebFilterChain webFilterChain( ServerHttpSecurity http )
throws Exception {
return http
.authorizeExchange(exchanges -> exchanges
.anyExchange().permitAll()
.and()
.exceptionHandling()
.authenticationEntryPoint((exchange, exception) ->
Mono.error(exception))
)
.csrf().disable()
.headers().disable()
.logout().disable()
.build();
}
}
这显然不会按预期工作,因为它允许所有请求使用HTTP
和HTTPS
方案,而我希望始终强制执行HTTPS
,但路径除外,例如/health
.
请建议我需要在上面的代码中进行哪些更改才能完成此操作。