spring-cloud-gateway
spring-cloud-gateway copied to clipboard
I want to convert Netflix - zuul to Spring - cloud - gateway, In zuul I'm using request context for modifying the response body and request body in pre filter. But in spring - cloud-gateway I'm facing issues with exchange in global filter as I can't able to use request context. Please suggest me how can I proceed with it. My requirement is if access token is not valid or expired I have to give access-forbidden message as output in filter itself without routing to any service.
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like A clear and concise description of what you want to happen.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.
facing same issue... so following...
What issues are you facing? The easiest approach would probably be:
- Create a global filter (see https://cloud.spring.io/spring-cloud-gateway/multi/multi__global_filters.html#_global_filters)
- Create a
ReactiveJwtDecoder
(e.g.NimbusReactiveJwtDecoder
) - Parse authorization header and validate JWT
Otherwise https://github.com/spring-projects/spring-security/blob/main/web/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java migth be worth looking at.
@saitejachintalapudi This can also be achieved using OAuth2 Resource server along with SCG. With this, all the filters will be auto-configured and based on your requirement, you can customize the validations or error handling etc. I have written an article depicting the same if you are interested -
same issue...
Sorry for the late reply. Spring Security should be the thing parsing JWT and configured to reject requests. It is pluggable if needed.