Package org.apache.shiro.web.filter.mgt
Interface FilterChainManager
- All Known Implementing Classes:
DefaultFilterChainManager
public interface FilterChainManager
A
FilterChainManager manages the creation and modification of Filter chains from an available pool
of Filter instances.- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a filter to the 'pool' of available filters that can be used whencreating filter chains.voidAdds a filter to the 'pool' of available filters that can be used whencreating filter chains.voidaddToChain(String chainName, String filterName) Adds (appends) a filter to the filter chain identified by the givenchainName.voidaddToChain(String chainName, String filterName, String chainSpecificFilterConfig) Adds (appends) a filter to the filter chain identified by the givenchainName.voidcreateChain(String chainName, String chainDefinition) Creates a filter chain for the givenchainNamewith the specifiedchainDefinitionString.voidcreateDefaultChain(String chainName) Creates a chain that should match any non-matched request paths, typically/**assuming anAntPathMatcherI used.Returns the filter chain identified by the specifiedchainNameornullif there is no chain with that name.Returns the names of all configured chains or an emptySetif no chains have been configured.Returns the pool of availableFilters managed by this manager, keyed byname.booleanReturnstrueif one or more configured chains are available,falseif none are configured.javax.servlet.FilterChainProxies the specifiedoriginalFilterChain with the named chain.voidsetGlobalFilters(List<String> globalFilterNames) Configures the set of named filters that will match all paths.
-
Method Details
-
getFilters
Map<String,javax.servlet.Filter> getFilters()Returns the pool of availableFilters managed by this manager, keyed byname.- Returns:
- the pool of available
Filters managed by this manager, keyed byname.
-
getChain
Returns the filter chain identified by the specifiedchainNameornullif there is no chain with that name.- Parameters:
chainName- the name identifying the filter chain.- Returns:
- the filter chain identified by the specified
chainNameornullif there is no chain with that name.
-
hasChains
boolean hasChains()Returnstrueif one or more configured chains are available,falseif none are configured.- Returns:
trueif one or more configured chains are available,falseif none are configured.
-
getChainNames
Returns the names of all configured chains or an emptySetif no chains have been configured.- Returns:
- the names of all configured chains or an empty
Setif no chains have been configured.
-
proxy
Proxies the specifiedoriginalFilterChain with the named chain. The returnedFilterChaininstance will first execute the configured named chain and then lastly invoke the givenoriginalchain.- Parameters:
original- the original FilterChain to proxychainName- the name of the internal configured filter chain that should 'sit in front' of the specified original chain.- Returns:
- a
FilterChaininstance that will execute the named chain and then finally the specifiedoriginalFilterChain instance. - Throws:
IllegalArgumentException- if there is no configured chain with the givenchainName.
-
addFilter
Adds a filter to the 'pool' of available filters that can be used whencreating filter chains. Calling this method is effectively the same as callingaddFilter(name, filter, false);- Parameters:
name- 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 used
-
addFilter
Adds a filter to the 'pool' of available filters that can be used whencreating filter chains.- Parameters:
name- 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 theFiltershould beinitializedfirst before being added to the pool.
-
createChain
Creates a filter chain for the givenchainNamewith the specifiedchainDefinitionString.Conventional Use
Because theFilterChainManagerinterface 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 anAnt path expression). For example:createChain(path_expression, path_specific_filter_chain_definition);This convention can be used by aFilterChainResolverto inspect request URL paths against the chain name (path) and, if a match is found, return the corresponding chain for runtime filtering.Chain Definition Format
ThechainDefinitionmethod argument is expected to conform to the following format:filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN]
wherefilterNis the name of a filter previouslyregisteredwith the manager, and[optional_configN]is an optional bracketed string that has meaning for that particular filter for this particular chain
filterN[]just becomesfilterN. And because this method does create a chain, remember that order matters! The comma-delimited filter tokens in thechainDefinitionspecify the chain's execution order.Examples
/account/** = authcBasic
This example says "Create a filter named '/account/**' consisting of only the 'authcBasic' filter". Also because theauthcBasicfilter 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- ensures the user is first authenticated (
authcBasic) then - ensures that user has the
b2bClientrole, and then finally - ensures that they have the
remote:invoke:lan,wanpermission.
- authcBasic
- roles[b2bclient]
- perms[remote:invoke:lan
- wan]
- Parameters:
chainName- the name to associate with the chain, conventionally a URL path pattern.chainDefinition- the string-formatted chain definition used to construct an actualNamedFilterListchain instance.- See Also:
-
createDefaultChain
Creates a chain that should match any non-matched request paths, typically/**assuming anAntPathMatcherI used.- Parameters:
chainName- The name of the chain to create, likely/**.- Since:
- 1.6
- See Also:
-
addToChain
Adds (appends) a filter to the filter chain identified by the givenchainName. If there is no chain with the given name, a new one is created and the filter will be the first in the chain.- Parameters:
chainName- the name of the chain where the filter will be appended.filterName- the name of theregisteredfilter to add to the chain.- Throws:
IllegalArgumentException- if there is not aregisteredfilter under the givenfilterName
-
addToChain
void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) throws org.apache.shiro.config.ConfigurationException Adds (appends) a filter to the filter chain identified by the givenchainName. 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 aPathConfigProcessorto accept per-chain configuration. If it is not, aIllegalArgumentExceptionwill be thrown.- Parameters:
chainName- the name of the chain where the filter will be appended.filterName- the name of theregisteredfilter to add to the chain.chainSpecificFilterConfig- the filter-specific configuration that should be applied for only the specified filter chain.- Throws:
IllegalArgumentException- if there is not aregisteredfilter under the givenfilterNameorg.apache.shiro.config.ConfigurationException- if the filter is not capable of acceptingchainSpecificFilterConfig(usually such filters implement thePathConfigProcessorinterface).
-
setGlobalFilters
void setGlobalFilters(List<String> globalFilterNames) throws org.apache.shiro.config.ConfigurationException Configures the set of named filters that will match all paths. These filters will match BEFORE explicitly configured filter chains i.e. by callingcreateChain(String, String),addToChain(String, String), etc.
Filters configured in this list will apply to ALL requests.- Parameters:
globalFilterNames- the list of filter names to match ALL paths.- Throws:
org.apache.shiro.config.ConfigurationException- if one of the filter names is invalid and cannot be loaded from the set of configured filtersgetFilters()}.- Since:
- 1.6
-