Closed
Description
Describe the bug
We get an NPE when we try to add a new filter using standard DSL relative to another filter that was registered via custom DSL.
This looks like a different scenario than #9787
To Reproduce
Spring Security version: 5.8.1
// here we have to use a custom DSL because getting AuthenticationManager is really painful now
private class CustomConfigurer extends AbstractHttpConfigurer<CustomConfigurer, HttpSecurity> {
@Override
public void configure(HttpSecurity http) throws Exception {
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
http.addFilterBefore(new CustomFilter(authenticationManager), LogoutFilter.class);
}
}
@Bean SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.apply(new CustomConfigurer());
httpSecurity.addFilterBefore(new Filter2(), CustomFilter.class); // NPE here inside addFilterBefore
return http.build();
}
Expected behavior
- I would expect it's possible to mix registration of filters via standard and custom DSL.
- In any case
org.springframework.security.config.annotation.web.builders.HttpSecurity.addFilterAtOffsetOf(Filter, int, Class<? extends Filter>)
NPE seem not to be graceful - compare withorg.springframework.security.config.annotation.web.builders.HttpSecurity.addFilter(Filter)
which at least validates and throws some more meaningful exception
A workaround exists: the second filter must be also applied via a custom DSL.