spring-projects / spring-projects/spring-security
add filter before or after multiple existing filters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Expected Behavior
I have a custom filter (doing things like user validation) expected to be put after both BearerTokenAuthenticationFilter (Used for OAuth2 ResourceServer) and OAuth2LoginAuthenticationFilter (Used for OAuth2 client).
I'm expecting to have a new addFilterAfter to accept multiple reference filters instead of one. For example:
public HttpSecurity addFilterAfter(Filter filter, Collection<Class? extends Filter>> afterFilters) {}
The expected behavior is to have my custom filter added after the last filter in afterFilters.
Current Behavior
Currently, HttpSecurity has addFilterAfter and addFilterBefore method, both accepts only one existing filter as reference position.
Also, internal field filterOrders is private which means I cannot call its getOrder(filter) to detect order of existing filters.
Context
Since now I cannot put my custom filter to multiple existing filters. Then, I have to relying on options:
- find out which existing filter is late in the list by running my application and logging their ordering, and then call
addFitlerAfterwith that filter.
This put my code depends on sequence of filters which is internal to framework. I searched for example, there are no documentation said that BearerTokenAuthenticationFilter will always be after OAuth2LoginAuthenticationFilter, then relying on the ordering of these two filters is a hack and may break in future release.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading HttpSecurity.addFilterAfter and addFilterBefore, then inspect the private filterOrders field and its getOrder behavior. Compare how the named BearerTokenAuthenticationFilter and OAuth2LoginAuthenticationFilter are ordered. Done means the proposed multiple-reference-filter behavior is designed consistently with existing filter ordering APIs and covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100