Skip to content
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

adding custom filters to FilterOrderRegistration #9832

Closed
wants to merge 4 commits into from
Closed

adding custom filters to FilterOrderRegistration #9832

wants to merge 4 commits into from

Conversation

theexiile1305
Copy link
Contributor

This pull request let custom filters to be added to the FilterOrderRegistration in order to solve the issue mentioned in #9787.

Closes gh-9787

@pivotal-cla
Copy link

@theexiile1305 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@theexiile1305 Thank you for signing the Contributor License Agreement!

@Stexxen
Copy link

Stexxen commented May 31, 2021

Hi @theexiile1305, I don't work for pivotal and personally I want to see this issue resolved asap, but I suspect they are going to want a couple of tests as well?
Just my 2 cents...

@theexiile1305
Copy link
Contributor Author

Hi @Stexxen, thank you for the reply. Yea, I give it a try to add some tests 😄

@jgrandja jgrandja requested a review from rwinch May 31, 2021 18:44
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 1, 2021
@jzheaux jzheaux added in: web An issue in web modules (web, webmvc) status: duplicate A duplicate of another issue type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 1, 2021
@theexiile1305
Copy link
Contributor Author

@rwinch Hey there 😃
Should I add some unit or integration tests or both to this pull request? What do you prefer? Do you think, that the changes in this pull request are right so far?
Thank you for the feedback.

Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've provided feedback inline.

You can add tests to HttpSecurityAddFilterTest. Please be sure to include a test for the original issue and to cover the scenarios I mentioned inline.

void add(Class<? extends Filter> filter) {
int givenOrder = getOrder(filter);
Step step = new Step(givenOrder, ORDER_STEP);
int nextOrder = step.next();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to register it at order + ORDER_STEP. If we do this, then registering MyFilter after BasicAuthenticationFilter means that MyFilter is registered in the same spot as RequestCacheAwareFilter which is not what we want.

Instead, MyFilter should end up just before or just after (depending on the offset) the order.

If MyFilter is added in two different slots as is done in gh-9633, then we should fail if a user tries to use MyFilter as reference point. We should also ensure that none of the predefined Filter registrations can be overridden by accident.

NOTE: The reason for the large step is so users have space to insert custom Filters between the predefined Filters.

* structure of the FilterOrderRegistration.
* @param filter the {@link Filter} class that should be added
*/
void add(Class<? extends Filter> filter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we refactor this so that using this API does not allow us to get things wrong. Instead of two independent methods, I think we should remove this method and change getOrder to a private method and add findOrder(Class<? extends Filter> filter) which performs this logic and returns the current (or added) order.

@@ -2664,6 +2665,7 @@ public HttpSecurity addFilter(Filter filter) {
+ " does not have a registered order and cannot be added without a specified order. Consider using addFilterBefore or addFilterAfter instead.");
}
this.filters.add(new OrderedFilter(filter, order));
this.filterOrders.add(filter.getClass());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required because we know the Filter was already added (otherwise order would be null).

@rwinch rwinch assigned marcusdacoregio and unassigned rwinch Jun 8, 2021
@marcusdacoregio
Copy link
Contributor

I am going to work on the PR and clean it up based on @rwinch suggestions.

@ch4mpy
Copy link
Contributor

ch4mpy commented Jun 12, 2021

I created this PR #9898 which was closed for being a "duplicate".

It contains unit tests, solves the bug and code modification is really small.

Feel free to copy / paste from there if it helps to get this solved quickly, I don't care about having credits but do care this bug is solved as it is a show stopper for me to migrate to spring-boot 2.5

@jgrandja
Copy link
Contributor

@theexiile1305 We haven't received any updates based on @rwinch feedback so we went ahead with the changes.

I'll close this in favour of gh-9902.

@jgrandja jgrandja closed this Jun 14, 2021
@jgrandja jgrandja assigned jgrandja and unassigned marcusdacoregio Jun 14, 2021
@jgrandja jgrandja removed in: web An issue in web modules (web, webmvc) status: duplicate A duplicate of another issue labels Jun 14, 2021
@jgrandja jgrandja added status: declined A suggestion or change that we don't feel we should currently apply and removed type: bug A general bug labels Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding filters relative to custom ones is broken
10 participants