You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Response status code is incorrect when using multiple SecurityFilterChain(s).
It seems like the changes done in cedd553 for removing the ErrorPageSecurityFilter have lead to the use of multiple security filter chains not working correctly.
This might be linked to spring-projects/spring-security#12771, and perhaps that is how Spring Security worked before. However, I do not agree that we need to add something additional to get the correct error code if we have configured it like that.
I have created a example repo with some tests and configuration.
The security configuration looks like:
@EnableWebSecurity@ConfigurationpublicclassSecurityConfiguration {
@Bean@Order(1)
publicSecurityFilterChainfirstSecurityFilterChain(HttpSecurityhttp) throwsException {
returnhttp.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(AbstractHttpConfigurer::disable)
// Comment out line below for Spring Boot 2.7//.antMatcher("/ignored-api/*")// Comment line below for Spring Boot 2.7
.securityMatcher(AntPathRequestMatcher.antMatcher("/ignored-api/*"))
.authorizeHttpRequests(configurer -> configurer.anyRequest().denyAll())
.httpBasic(Customizer.withDefaults())
.build();
}
@Bean@Order(2)
publicSecurityFilterChainsecondSecurityFilterChain(HttpSecurityhttp) throwsException {
returnhttp.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(AbstractHttpConfigurer::disable)
.exceptionHandling(exceptionHandling -> exceptionHandling.defaultAuthenticationEntryPointFor(newHttpStatusEntryPoint(HttpStatus.UNAUTHORIZED),
AnyRequestMatcher.INSTANCE))
.securityContext(securityContext -> securityContext.securityContextRepository(newNullSecurityContextRepository()))
.authorizeHttpRequests(configurer -> configurer.anyRequest().authenticated())
.httpBasic(Customizer.withDefaults())
.build();
}
}
Thanks for checking @philwebb. I'll add a comment to the Spring Security issue. It is slightly different than error pages, but it isn't much logical to me what Spring Security is doing.
Response status code is incorrect when using multiple
SecurityFilterChain
(s).It seems like the changes done in cedd553 for removing the
ErrorPageSecurityFilter
have lead to the use of multiple security filter chains not working correctly.This might be linked to spring-projects/spring-security#12771, and perhaps that is how Spring Security worked before. However, I do not agree that we need to add something additional to get the correct error code if we have configured it like that.
I have created a example repo with some tests and configuration.
The security configuration looks like:
My rest controller looks like:
and the tests look like:
In Spring Boot 2.7 all the tests are green. With Spring Boot 3.1 the following ones are failing:
ignoredUnknownAuthenticated
- in 2.7 the status code is HTTP 403, with 3.1 it is HTTP 401ignoredForbiddenAuthenticated
- in 2.7 the status code is HTTP 403, with 3.1 it is HTTP 401ignoredOkAuthenticated
- in 2.7 the status code is HTTP 403, with 3.1 it is HTTP 401allowedUnknownAuthenticated
- in 2.7 the status code is HTTP 404, with 3.1 it is HTTP 401The text was updated successfully, but these errors were encountered: