public class DelegatingFilterProxyRegistrationBean extends DynamicRegistrationBean<javax.servlet.FilterRegistration.Dynamic> implements org.springframework.context.ApplicationContextAware
ServletContextInitializer to register DelegatingFilterProxys in a
Servlet 3.0+ container. Similar to the registration features provided by ServletContext but with a Spring Bean
friendly design.
The bean name of the actual delegate Filter should be specified using the
targetBeanName constructor argument. Unlike the FilterRegistrationBean,
referenced filters are not instantiated early. In fact, if the delegate filter bean is
marked @Lazy it won't be instantiated at all until the filter is called.
Registrations can be associated with URL patterns and/or
servlets (either by name or via a
ServletRegistrationBeans. When no URL pattern or
servlets are specified the filter will be associated to '/*'. The targetBeanName will
be used as the filter name if not otherwise specified.
ServletContextInitializer,
ServletContext.addFilter(String, Filter),
FilterRegistrationBean,
DelegatingFilterProxy| Modifier and Type | Field and Description |
|---|---|
protected static int |
REQUEST_WRAPPER_FILTER_MAX_ORDER
Filters that wrap the servlet request should be ordered less than or equal to this.
|
| Constructor and Description |
|---|
DelegatingFilterProxyRegistrationBean(String targetBeanName,
ServletRegistrationBean<?>... servletRegistrationBeans)
Create a new
DelegatingFilterProxyRegistrationBean instance to be
registered with the specified ServletRegistrationBeans. |
| Modifier and Type | Method and Description |
|---|---|
protected javax.servlet.FilterRegistration.Dynamic |
addRegistration(String description,
javax.servlet.ServletContext servletContext) |
void |
addServletNames(String... servletNames)
Add servlet names for the filter.
|
void |
addServletRegistrationBeans(ServletRegistrationBean<?>... servletRegistrationBeans)
Add
ServletRegistrationBeans for the filter. |
void |
addUrlPatterns(String... urlPatterns)
Add URL patterns that the filter will be registered against.
|
protected void |
configure(javax.servlet.FilterRegistration.Dynamic registration)
Configure registration settings.
|
protected String |
getDescription()
Return a description of the registration.
|
org.springframework.web.filter.DelegatingFilterProxy |
getFilter()
Return the
Filter to be registered. |
Collection<String> |
getServletNames()
Return a mutable collection of servlet names that the filter will be registered
against.
|
Collection<ServletRegistrationBean<?>> |
getServletRegistrationBeans()
Return a mutable collection of the
ServletRegistrationBean that the filter
will be registered against. |
protected String |
getTargetBeanName() |
Collection<String> |
getUrlPatterns()
Return a mutable collection of URL patterns that the filter will be registered
against.
|
boolean |
isMatchAfter()
Return if filter mappings should be matched after any declared Filter mappings of
the ServletContext.
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setDispatcherTypes(javax.servlet.DispatcherType first,
javax.servlet.DispatcherType... rest)
Convenience method to
set dispatcher types
using the specified elements. |
void |
setDispatcherTypes(EnumSet<javax.servlet.DispatcherType> dispatcherTypes)
Sets the dispatcher types that should be used with the registration.
|
void |
setMatchAfter(boolean matchAfter)
Set if the filter mappings should be matched after any declared filter mappings of
the ServletContext.
|
void |
setServletNames(Collection<String> servletNames)
Set servlet names that the filter will be registered against.
|
void |
setServletRegistrationBeans(Collection<? extends ServletRegistrationBean<?>> servletRegistrationBeans)
Set
ServletRegistrationBeans that the filter will be registered against. |
void |
setUrlPatterns(Collection<String> urlPatterns)
Set the URL patterns that the filter will be registered against.
|
addInitParameter, getInitParameters, getOrDeduceName, isAsyncSupported, register, setAsyncSupported, setInitParameters, setNamegetOrder, isEnabled, onStartup, setEnabled, setOrderprotected static final int REQUEST_WRAPPER_FILTER_MAX_ORDER
public DelegatingFilterProxyRegistrationBean(String targetBeanName, ServletRegistrationBean<?>... servletRegistrationBeans)
DelegatingFilterProxyRegistrationBean instance to be
registered with the specified ServletRegistrationBeans.targetBeanName - name of the target filter bean to look up in the Spring
application context (must not be null).servletRegistrationBeans - associate ServletRegistrationBeanspublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionprotected String getTargetBeanName()
public org.springframework.web.filter.DelegatingFilterProxy getFilter()
Filter to be registered.public void setServletRegistrationBeans(Collection<? extends ServletRegistrationBean<?>> servletRegistrationBeans)
ServletRegistrationBeans that the filter will be registered against.servletRegistrationBeans - the Servlet registration beanspublic Collection<ServletRegistrationBean<?>> getServletRegistrationBeans()
ServletRegistrationBean that the filter
will be registered against. ServletRegistrationBeans.setServletNames(java.util.Collection<java.lang.String>),
setUrlPatterns(java.util.Collection<java.lang.String>)public void addServletRegistrationBeans(ServletRegistrationBean<?>... servletRegistrationBeans)
ServletRegistrationBeans for the filter.servletRegistrationBeans - the servlet registration beans to addsetServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.web.servlet.ServletRegistrationBean<?>>)public void setServletNames(Collection<String> servletNames)
servletNames - the servlet namessetServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.web.servlet.ServletRegistrationBean<?>>),
setUrlPatterns(java.util.Collection<java.lang.String>)public Collection<String> getServletNames()
public void addServletNames(String... servletNames)
servletNames - the servlet names to addpublic void setUrlPatterns(Collection<String> urlPatterns)
urlPatterns - the URL patternssetServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.web.servlet.ServletRegistrationBean<?>>),
setServletNames(java.util.Collection<java.lang.String>)public Collection<String> getUrlPatterns()
public void addUrlPatterns(String... urlPatterns)
urlPatterns - the URL patternspublic void setDispatcherTypes(javax.servlet.DispatcherType first,
javax.servlet.DispatcherType... rest)
set dispatcher types
using the specified elements.first - the first dispatcher typerest - additional dispatcher typespublic void setDispatcherTypes(EnumSet<javax.servlet.DispatcherType> dispatcherTypes)
DynamicRegistrationBean.isAsyncSupported().dispatcherTypes - the dispatcher typespublic void setMatchAfter(boolean matchAfter)
false indicating the filters are supposed
to be matched before any declared filter mappings of the ServletContext.matchAfter - if filter mappings are matched afterpublic boolean isMatchAfter()
protected String getDescription()
RegistrationBeangetDescription in class RegistrationBeanprotected javax.servlet.FilterRegistration.Dynamic addRegistration(String description, javax.servlet.ServletContext servletContext)
addRegistration in class DynamicRegistrationBean<javax.servlet.FilterRegistration.Dynamic>protected void configure(javax.servlet.FilterRegistration.Dynamic registration)
configure in class DynamicRegistrationBean<javax.servlet.FilterRegistration.Dynamic>registration - the registrationCopyright © 2018 Pivotal Software, Inc.. All rights reserved.