-
Notifications
You must be signed in to change notification settings - Fork 6.1k
adding custom filters to FilterOrderRegistration #9832
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
Changes from all commits
3bb7745
774463a
a3eed91
d4f44c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2020 the original author or authors. | ||
* Copyright 2002-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -114,6 +114,18 @@ final class FilterOrderRegistration { | |
put(SwitchUserFilter.class, order.next()); | ||
} | ||
|
||
/** | ||
* Add a particular {@link Filter} class to the latest position to the internal data | ||
* structure of the FilterOrderRegistration. | ||
* @param filter the {@link Filter} class that should be added | ||
*/ | ||
void add(Class<? extends Filter> filter) { | ||
int givenOrder = getOrder(filter); | ||
Step step = new Step(givenOrder, ORDER_STEP); | ||
int nextOrder = step.next(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to register it at Instead, If NOTE: The reason for the large step is so users have space to insert custom |
||
put(filter, nextOrder); | ||
} | ||
|
||
private void put(Class<? extends Filter> filter, int position) { | ||
String className = filter.getName(); | ||
this.filterToOrder.put(className, position); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2020 the original author or authors. | ||
* Copyright 2002-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -2652,6 +2652,7 @@ public HttpSecurity addFilterBefore(Filter filter, Class<? extends Filter> befor | |
|
||
private HttpSecurity addFilterAtOffsetOf(Filter filter, int offset, Class<? extends Filter> registeredFilter) { | ||
int order = this.filterOrders.getOrder(registeredFilter) + offset; | ||
this.filterOrders.add(filter.getClass()); | ||
theexiile1305 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.filters.add(new OrderedFilter(filter, order)); | ||
return this; | ||
} | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not required because we know the |
||
return this; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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 addfindOrder(Class<? extends Filter> filter)
which performs this logic and returns the current (or added) order.