public class DefaultFilterChainManager extends Object implements FilterChainManager
FilterChainManager implementation maintaining a map of Filter instances
(key: filter name, value: Filter) as well as a map of NamedFilterLists created from these
Filters (key: filter chain name, value: NamedFilterList). The NamedFilterList is essentially a
FilterChain that also has a name property by which it can be looked up.NamedFilterList| Constructor and Description |
|---|
DefaultFilterChainManager() |
DefaultFilterChainManager(javax.servlet.FilterConfig filterConfig) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addDefaultFilters(boolean init) |
void |
addFilter(String name,
javax.servlet.Filter filter)
Adds a filter to the 'pool' of available filters that can be used when
creating filter chains. |
void |
addFilter(String name,
javax.servlet.Filter filter,
boolean init)
Adds a filter to the 'pool' of available filters that can be used when
creating filter chains. |
protected void |
addFilter(String name,
javax.servlet.Filter filter,
boolean init,
boolean overwrite) |
void |
addToChain(String chainName,
String filterName)
Adds (appends) a filter to the filter chain identified by the given
chainName. |
void |
addToChain(String chainName,
String filterName,
String chainSpecificFilterConfig)
Adds (appends) a filter to the filter chain identified by the given
chainName. |
protected void |
applyChainConfig(String chainName,
javax.servlet.Filter filter,
String chainSpecificFilterConfig) |
void |
createChain(String chainName,
String chainDefinition)
Creates a filter chain for the given
chainName with the specified chainDefinition
String. |
protected NamedFilterList |
ensureChain(String chainName) |
NamedFilterList |
getChain(String chainName)
Returns the filter chain identified by the specified
chainName or null if there is no chain with
that name. |
Set<String> |
getChainNames()
Returns the names of all configured chains or an empty
Set if no chains have been configured. |
javax.servlet.Filter |
getFilter(String name) |
Map<String,NamedFilterList> |
getFilterChains() |
javax.servlet.FilterConfig |
getFilterConfig()
Returns the
FilterConfig provided by the Servlet container at webapp startup. |
Map<String,javax.servlet.Filter> |
getFilters()
Returns the pool of available
Filters managed by this manager, keyed by name. |
boolean |
hasChains()
Returns
true if one or more configured chains are available, false if none are configured. |
protected void |
initFilter(javax.servlet.Filter filter)
Initializes the filter by calling
filter.init( . |
javax.servlet.FilterChain |
proxy(javax.servlet.FilterChain original,
String chainName)
Proxies the specified
original FilterChain with the named chain. |
void |
setFilterChains(Map<String,NamedFilterList> filterChains) |
void |
setFilterConfig(javax.servlet.FilterConfig filterConfig)
Sets the
FilterConfig provided by the Servlet container at webapp startup. |
void |
setFilters(Map<String,javax.servlet.Filter> filters) |
protected String[] |
splitChainDefinition(String chainDefinition)
Splits the comma-delimited filter chain definition line into individual filter definition tokens.
|
protected String[] |
toNameConfigPair(String token)
Based on the given filter chain definition token (e.g.
|
public DefaultFilterChainManager()
public DefaultFilterChainManager(javax.servlet.FilterConfig filterConfig)
public javax.servlet.FilterConfig getFilterConfig()
FilterConfig provided by the Servlet container at webapp startup.FilterConfig provided by the Servlet container at webapp startup.public void setFilterConfig(javax.servlet.FilterConfig filterConfig)
FilterConfig provided by the Servlet container at webapp startup.filterConfig - the FilterConfig provided by the Servlet container at webapp startup.public Map<String,javax.servlet.Filter> getFilters()
FilterChainManagerFilters managed by this manager, keyed by name.getFilters in interface FilterChainManagerFilters managed by this manager, keyed by name.public Map<String,NamedFilterList> getFilterChains()
public void setFilterChains(Map<String,NamedFilterList> filterChains)
public javax.servlet.Filter getFilter(String name)
public void addFilter(String name, javax.servlet.Filter filter)
FilterChainManagercreating filter chains.
Calling this method is effectively the same as calling
addFilter(name, filter, false);addFilter in interface FilterChainManagername - the name to assign to the filter, used to reference the filter in chain definitionsfilter - the filter to initialize and then add to the pool of available filters that can be usedpublic void addFilter(String name, javax.servlet.Filter filter, boolean init)
FilterChainManagercreating filter chains.addFilter in interface FilterChainManagername - the name to assign to the filter, used to reference the filter in chain definitionsfilter - the filter to assign to the filter poolinit - whether or not the Filter should be
initialized first before being added to the pool.public void createChain(String chainName, String chainDefinition)
FilterChainManagerchainName with the specified chainDefinition
String.
FilterChainManager interface does not impose any restrictions on filter chain names,
(it expects only Strings), a convenient convention is to make the chain name an actual URL path expression
(such as an Ant path expression). For example:
createChain(path_expression, path_specific_filter_chain_definition);
This convention can be used by a FilterChainResolver to inspect request URL paths
against the chain name (path) and, if a match is found, return the corresponding chain for runtime filtering.
chainDefinition method argument is expected to conform to the following format:
filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN]where
filterN is the name of a filter previously
registered with the manager, and[optional_configN] is an optional bracketed string that has meaning for that particular filter for
this particular chainfilterN[] just becomes filterN.
And because this method does create a chain, remember that order matters! The comma-delimited filter tokens in
the chainDefinition specify the chain's execution order.
/account/** = authcBasicThis example says "Create a filter named '
/account/**' consisting of only the 'authcBasic'
filter". Also because the authcBasic filter does not need any path-specific
config, it doesn't have any config brackets [].
/remoting/** = authcBasic, roles[b2bClient], perms["remote:invoke:wan,lan"]This example by contrast uses the 'roles' and 'perms' filters which do use bracket notation. This definition says: Construct a filter chain named '
/remoting/**' which
authcBasic) thenb2bClient role, and then finallyremote:invoke:lan,wan permission.createChain in interface FilterChainManagerchainName - the name to associate with the chain, conventionally a URL path pattern.chainDefinition - the string-formatted chain definition used to construct an actual
NamedFilterList chain instance.FilterChainResolver,
AntPathMatcherprotected String[] splitChainDefinition(String chainDefinition)
foo, bar[baz], blah[x, y]
Resulting Output:
output[0] == foo
output[1] == bar[baz]
output[2] == blah[x, y]
chainDefinition - the comma-delimited filter chain definition.protected String[] toNameConfigPair(String token) throws ConfigurationException
| Input | Result |
|---|---|
foo |
returned[0] == fooreturned[1] == null |
foo[bar, baz] |
returned[0] == fooreturned[1] == bar, baz |
token - the filter chain definition tokenConfigurationException - if the token cannot be parsedprotected void addFilter(String name, javax.servlet.Filter filter, boolean init, boolean overwrite)
public void addToChain(String chainName, String filterName)
FilterChainManagerchainName. If there is no chain
with the given name, a new one is created and the filter will be the first in the chain.addToChain in interface FilterChainManagerchainName - the name of the chain where the filter will be appended.filterName - the name of the registered filter to add to the chain.public void addToChain(String chainName, String filterName, String chainSpecificFilterConfig)
FilterChainManagerchainName. If there is no chain
with the given name, a new one is created and the filter will be the first in the chain.
Note that the final argument expects the associated filter to be an instance of
a PathConfigProcessor to accept per-chain configuration.
If it is not, a IllegalArgumentException will be thrown.addToChain in interface FilterChainManagerchainName - the name of the chain where the filter will be appended.filterName - the name of the registered filter to add to the chain.chainSpecificFilterConfig - the filter-specific configuration that should be applied for only the specified
filter chain.protected void applyChainConfig(String chainName, javax.servlet.Filter filter, String chainSpecificFilterConfig)
protected NamedFilterList ensureChain(String chainName)
public NamedFilterList getChain(String chainName)
FilterChainManagerchainName or null if there is no chain with
that name.getChain in interface FilterChainManagerchainName - the name identifying the filter chain.chainName or null if there is no chain with
that name.public boolean hasChains()
FilterChainManagertrue if one or more configured chains are available, false if none are configured.hasChains in interface FilterChainManagertrue if one or more configured chains are available, false if none are configured.public Set<String> getChainNames()
FilterChainManagerSet if no chains have been configured.getChainNames in interface FilterChainManagerSet if no chains have been configured.public javax.servlet.FilterChain proxy(javax.servlet.FilterChain original,
String chainName)
FilterChainManageroriginal FilterChain with the named chain. The returned
FilterChain instance will first execute the configured named chain and then lastly invoke the given
original chain.proxy in interface FilterChainManageroriginal - the original FilterChain to proxychainName - the name of the internal configured filter chain that should 'sit in front' of the specified
original chain.FilterChain instance that will execute the named chain and then finally the
specified original FilterChain instance.protected void initFilter(javax.servlet.Filter filter)
filter.init( getFilterConfig() );.filter - the filter to initialize with the FilterConfig.protected void addDefaultFilters(boolean init)
Copyright © 2004-2016 The Apache Software Foundation. All Rights Reserved.