Comments (9)
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.
from ixortalk.aws.cognito.jwt.security.filter.
in this way i need to register manually with addFilterBefore? only with your bean i receive:
2018-07-27 14:23:42.834 INFO 18245 --- [ost-startStop-1] o.s.boot.web.servlet.RegistrationBean : Filter awsCognitoJwtAuthenticationFilter was not registered (disabled)
2018-07-27 14:23:42.839 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-27 14:23:42.840 INFO 18245 --- [ost-startStop-1] o.s.boot.web.servlet.RegistrationBean : Filter myHlJwtAuthenticationFilter was not registered (disabled)
2018-07-27 14:23:42.840 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-27 14:23:42.840 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-27 14:23:42.840 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-27 14:23:42.841 INFO 18245 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-07-27 14:23:42.841 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-07-27 14:23:42.841 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-07-27 14:23:42.841 INFO 18245 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestLoggingFilter' to: [/*]
from ixortalk.aws.cognito.jwt.security.filter.
with this configuration all works fine but i don't know if this is a correct way
@Configuration
public class HcaWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Autowired
private AwsCognitoJwtAuthenticationFilter awsCognitoJwtAuthenticationFilter;
@Autowired
private HcaAuthenticationEntryPoint hcaAuthenticationEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().authorizeRequests().anyRequest().authenticated().and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.exceptionHandling().authenticationEntryPoint(hcaAuthenticationEntryPoint).and()
.addFilterBefore(awsCognitoJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new MyHlJwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
;
}
@Bean
public FilterRegistrationBean unregister(AwsCognitoJwtAuthenticationFilter awsCognitoJwtAuthenticationFilter) {
FilterRegistrationBean registration = new FilterRegistrationBean<>(awsCognitoJwtAuthenticationFilter);
registration.setEnabled(false);
return registration;
}
}
from ixortalk.aws.cognito.jwt.security.filter.
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
from ixortalk.aws.cognito.jwt.security.filter.
"disable the filter registration by default" i think is the correct coice
i have a question about:
.addFilterBefore(awsCognitoJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new MyHlJwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
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.
i tried somethings like that but spring not start
.addFilterBefore(awsCognitoJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new MyHlJwtAuthenticationFilter(), AwsCognitoJwtAuthenticationFilter.class)
from ixortalk.aws.cognito.jwt.security.filter.
Yes, misread your original config .... that indeed didn't make the order explicit.
Your last snippet should work ... what is the error you are getting ?
from ixortalk.aws.cognito.jwt.security.filter.
sorry seams something wrong before, now works
just i receive 2 invocation per fiter:
@Configuration
public class HcaWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Autowired
private AwsCognitoJwtAuthenticationFilter awsCognitoJwtAuthenticationFilter;
@Autowired
private MyHlJwtAuthenticationFilter myHlJwtAuthenticationFilter;
@Autowired
private HcaAuthenticationEntryPoint hcaAuthenticationEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors();
http.authorizeRequests().anyRequest().authenticated();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.exceptionHandling().authenticationEntryPoint(hcaAuthenticationEntryPoint);
http.addFilterBefore(myHlJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
http.addFilterBefore(awsCognitoJwtAuthenticationFilter, MyHlJwtAuthenticationFilter.class);
}
@Bean
public FilterRegistrationBean awsBean(AwsCognitoJwtAuthenticationFilter awsCognitoJwtAuthenticationFilter) {
FilterRegistrationBean registration = new FilterRegistrationBean<>(awsCognitoJwtAuthenticationFilter);
registration.setEnabled(false);
return registration;
}
@Bean
public FilterRegistrationBean myhlBean(MyHlJwtAuthenticationFilter myHlJwtAuthenticationFilter) {
FilterRegistrationBean registration = new FilterRegistrationBean<>(myHlJwtAuthenticationFilter);
registration.setEnabled(false);
return registration;
}
}
@Component
public class MyHlJwtAuthenticationFilter extends GenericFilterBean {}
from ixortalk.aws.cognito.jwt.security.filter.
@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 ?
from ixortalk.aws.cognito.jwt.security.filter.
@ddewaele can you make version without autoregistration and read my pull request about a little fix ?
from ixortalk.aws.cognito.jwt.security.filter.
Related Issues (18)
- The code doesnt have AwsCognitoJwtVerifier class, does this work ? HOT 4
- Documentation Issue HOT 1
- clearContext on exception HOT 6
- Spring boot 2 support HOT 10
- BeanCreationException HOT 1
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.awsCognitoCredentialsHolder' HOT 1
- Group is required or a null pointer exception occurs. HOT 2
- Unable to generate private_key.json for jwks.json from cognito HOT 1
- Make header configurable
- identityPoolId does not appear to be used
- When add invalid token and then add a valid token on first request it throws 500 internal server error. with exception com.nimbusds.jose.proc.BadJWSException: Signed JWT rejected: Invalid signature
- Valid token getting NullPointerException HOT 2
- Usage of ID token HOT 1
- Verifying the JWT token signature HOT 2
- Duplicate HOT 2
- JSON parsing failing HOT 2
- client_credentials flow not supported HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ixortalk.aws.cognito.jwt.security.filter.