I am using Spring security within a Spring Boot Webflux application to serve traffic primarily on HTTPS
port. However as an operational requirement I need to support couple of non-secure REST API paths in my Spring Boot application for health check etc that need to be exposed on HTTP
as well.
So how do I enforce all the requests to HTTPS except for a known path using SecurityWebFilterChain
bean?
This is how I have defined my 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();
}
}
This obviously won't work as intended because it is allowing all requests to use HTTP
and HTTPS
schemes whereas I want to always enforce HTTPS
except for a path e.g. /health
.
Please suggest what changes would I need in above code to get this done.