Class ServletFilterRegistration
JettyServerComponent, TomcatServerComponent) mount before the server starts.
Contribute one as a FilterRegistrationBean, so the same registration works on Jetty and Tomcat.
Example:
Order:
Filters run outermost first, by ascending order. A bean-supplied AuthFilterChain is
mounted automatically at AUTH_ORDER, so a registration at the default DEFAULT_ORDER runs after
authentication. Two registrations at the same order run in ascending bean-name order, and the auto-mounted
authentication filter runs ahead of a registration at its own order; give registrations that must keep a relative
order distinct values rather than relying on names.
The order is only ever ServletFilterRegistration.Builder.order(int).
Running a filter before authentication is a property of a narrow URL pattern, not of the order alone. A boundary
on HIGHEST_PRECEDENCE would also intercept authentication redirects and challenges.
Names:
More than one registration in an application needs a distinct bean name, because a
Replacing the authentication mount:
An application that needs the AuthFilterChain on other dispatcher types, or at another position, registers it
itself: wrap the injected AuthFilterChain bean instance in a registration. That registration then replaces
the automatic mount. It must be the injected instance; a new instance is a second, separate filter.
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe order at which a bean-suppliedAuthFilterChainis mounted automatically.static final intThe default order: after authentication.static final intRuns before everything else, including the automatically mountedAuthFilterChain.static final intRuns after everything else. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<ServletFilterRegistration>Collects the registrations a server component mounts, outermost first.create(jakarta.servlet.Filter filter) Creates a builder for a registration of a filter.Set<jakarta.servlet.DispatcherType>Returns the dispatcher types the filter is mapped to.jakarta.servlet.FilterReturns the filter.getName()Returns the explicit container filter name.intgetOrder()Returns the order: lower values run first.Returns the URL patterns the filter is mapped to.booleanReturns whether the filter supports asynchronous request processing.
-
Field Details
-
HIGHEST_PRECEDENCE
Runs before everything else, including the automatically mountedAuthFilterChain.- See Also:
-
AUTH_ORDER
The order at which a bean-suppliedAuthFilterChainis mounted automatically.- See Also:
-
DEFAULT_ORDER
The default order: after authentication.- See Also:
-
LOWEST_PRECEDENCE
Runs after everything else.- See Also:
-
-
Method Details
-
create
Creates a builder for a registration of a filter.- Parameters:
filter- The filter instance. Cannot benull .- Returns:
- A new builder.
- Throws:
IllegalArgumentException- If the filter isnull .
-
collect
Collects the registrations a server component mounts, outermost first.Takes every
ServletFilterRegistrationbean, plus an internal registration for theAuthFilterChainbean when there is one and no registration wraps that same instance (see the class description). Sorts byorder, then the automatic authentication mount first, then bean name.Intended for the server components; applications contribute registrations as beans.
- Parameters:
store- The microservice bean store. Cannot benull .- Returns:
- The registrations in mount order. Never
null . - Throws:
IllegalStateException- If one filter instance is registered more than once, or two registrations have the same explicit name.
-
getFilter
Returns the filter.- Returns:
- The filter instance. Never
null .
-
getUrlPatterns
Returns the URL patterns the filter is mapped to.- Returns:
- An unmodifiable list, in declaration order and without duplicates.
-
getDispatcherTypes
Returns the dispatcher types the filter is mapped to.- Returns:
- An unmodifiable set. Never empty.
-
getOrder
Returns the order: lower values run first.- Returns:
- The order.
-
isAsyncSupported
Returns whether the filter supports asynchronous request processing.- Returns:
true if it does.
-
getName
Returns the explicit container filter name.- Returns:
- The name, or empty when the component generates one.
-