-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AwsCognitoJwtAuthenticationFilter bean is registered twice when placed in Spring Security Filter Chain #13
Comments
in this way i need to register manually with addFilterBefore? only with your bean i receive:
|
What you're seeing here is the top level filter chain that the spring context is building. (All filters that are either registered via a FilterRegistrationBean, or GenericFilterBeans). If you want to make use of Spring Security features, I think it's best to make sure your filter is hooked into the springSecurityFilterChain. To do that you make sure Spring doesn't register it automatically, and you create a new security config (via a WebSecurityConfigurer) to hook your filter in the spring security filter before or after an existing filter. It is also mentioned here : https://spring.io/guides/topicals/spring-security-architecture/ The fact that all filters internal to Spring Security are unknown to the container is important, especially in a Spring Boot application, where all @beans of type Filter are registered automatically with the container by default. So if you want to add a custom filter to the security chain, you need to either not make it a @bean or wrap it in a FilterRegistrationBean that explicitly disables the container registration. |
with this configuration all works fine but i don't know if this is a correct way
|
Looks ok to me .. I'm probably going to disable the filter registration by default in the auto config of this library so you don't have to do it in code anymore. That will solve this ticket and if the config above works for you we can also close issue #12 |
"disable the filter registration by default" i think is the correct coice i have a question about:
i put aws and custom filter beforce UsernamePasswordAuthenticationFilter, but is not clear the order, actually works correctly but i fear that is a coincidence. i need my custom fitler chained after Cognito, this is the correct way? i don't want that in a future version of spring change somethings internal and my code stop works.
|
Yes, misread your original config .... that indeed didn't make the order explicit. |
sorry seams something wrong before, now works just i receive 2 invocation per fiter:
|
@ddewaele also with only your filter using FilterRegistrationBean (enabled false) and addFilterBefore i receive 2 invocation. another question are you sure to extends GenericFilterBean and not AbstractAuthenticationProcessingFilter ? |
@ddewaele can you make version without autoregistration and read my pull request about a little fix ? |
Spring automatically registers all filter beans and puts it in the top level filter chain.
This means that when adding the AwsCognitoJwtAuthenticationFilter to the spring security filter chain (using
addFilterBefore
oraddFilterAfter
) it will be registered twice. Once in the top-level chain and once in the spring security filter chain.Adding this will avoid spring registering it in the top level filter.
The text was updated successfully, but these errors were encountered: