-
Notifications
You must be signed in to change notification settings - Fork 66
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
Solution for getting ServletRequestFilter working in external Tomcat war deployments #309
Comments
The provided solution has a limitation: only one ServletFilter is registered with a specific order.
The current solution registers multiple filters, each with a distinct order. This is necessary, for example, if you want the rate limit to be executed before and/or after a security filter as an example. |
yes, but the filter delegates to multiple ServletRequestFilter, also in a specific order (all before other regular filters).
To differentiate between ServletRequestFilter that should applied "before regular filters" and "after regular filters", a new element at ServletRequestFilter could be introduced, or by different order ranges. The above solution is not as fine-graind as the current solution, but it provides a huge range of use-cases. In fact, i can't see any use case, that makes it necessary to put one ServletRequestFilter bevore regular filter one, another before regular two and onother after regular filter three (for example) - one filter execution chain before all regular filters and one execution chain after all regular filters would deliver a useable solution. The provided implementation can also be enhanced with a @ConditionalOnProperty(name="bucket4j.useDelegatingFilter=true") (for example) to enable/disable the DelegatingFilter. What about enhancements to get rid of the workarounds:
|
any updates here? |
As far as my understanding is correct, configured ServletRequests are only registered correctly when using embedded Tomcat.
As a solution, I implemented my own filter, which works similarly to the Spring Security Filterchain, delegating requests to the list of ServletRequestFilters registered in the application context.
In order to access the registered ServletRequestFilter instances, they are passed to the delegating filter after the aplicationcontext refresh (because my own Filter does not have access to the list of ServletRequestFilters at creation time).
In addition, two points are currently only possible as a workaround:
This solution should work also for embedded Tomcat (not verified). To get rid of the workarounds, the following enhancements would helpfull:
shouldNotFilter(HttpServletRequest request)
method as public method.I would be very happy if the suggestions or parts of them could be taken into account in a next version
Here are the implementations:
Spring Boot Configuration
Filter
The text was updated successfully, but these errors were encountered: