Endpoint authorization enforces access rules by matching incoming requests at web application endpoints. In a reactive Spring application, configure these rules with a SecurityWebFilterChain bean rather than SecurityFilterChain. section 17.3.1
Independent endpoint policies
A reactive controller can expose /hello, which returns a greeting containing the authenticated user name, and /ciao, which returns "Ciao!" without requiring authentication. Calling /hello with john's credentials returns "Hello john".
Listing 17.7 Configuring endpoint authorization for reactive apps
@Configuration
public class ProjectConfig {
// Omitted code
@Bean
public SecurityWebFilterChain securityWebFilterChain(
ServerHttpSecurity http) {
http.httpBasic(Customizer.withDefaults());
http.authorizeExchange( #1
c -> c.pathMatchers(HttpMethod.GET, "/hello") #2
.authenticated() #3
.anyExchange() #4
.permitAll() #5
);
return http.build(); #6
}
}
Use the complete reactive SecurityWebFilterChain configuration to connect HTTP Basic authentication, path matching, authorization decisions, and application startup. section 17.3.1
