Package org.apache.shiro.web.filter.mgt
Class PathMatchingFilterChainResolver
- java.lang.Object
-
- org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver
-
- All Implemented Interfaces:
FilterChainResolver
public class PathMatchingFilterChainResolver extends Object implements FilterChainResolver
AFilterChainResolver
that resolvesFilterChain
s based on url path matching, as determined by a configurablePathMatcher
. This implementation functions by consulting aFilterChainManager
for all configured filter chains (keyed by configured path pattern). If an incoming Request path matches one of the configured path patterns (via thePathMatcher
, the corresponding configuredFilterChain
is returned.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description PathMatchingFilterChainResolver()
PathMatchingFilterChainResolver(FilterConfig filterConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FilterChain
getChain(ServletRequest request, ServletResponse response, FilterChain originalChain)
Returns the filter chain that should be executed for the given request, ornull
if the original chain should be used.FilterChainManager
getFilterChainManager()
PatternMatcher
getPathMatcher()
Returns thePatternMatcher
used when determining if an incoming request's path matches a configured filter chain.protected String
getPathWithinApplication(ServletRequest request)
Merely returnsWebUtils.
and can be overridden by subclasses for custom request-to-application-path resolution behavior.getPathWithinApplication(request)
protected boolean
pathMatches(String pattern, String path)
Returnstrue
if an incoming request path (thepath
argument) matches a configured filter chain path (thepattern
argument),false
otherwise.void
setFilterChainManager(FilterChainManager filterChainManager)
void
setPathMatcher(PatternMatcher pathMatcher)
Sets thePatternMatcher
used when determining if an incoming request's path matches a configured filter chain.
-
-
-
Constructor Detail
-
PathMatchingFilterChainResolver
public PathMatchingFilterChainResolver()
-
PathMatchingFilterChainResolver
public PathMatchingFilterChainResolver(FilterConfig filterConfig)
-
-
Method Detail
-
getPathMatcher
public PatternMatcher getPathMatcher()
Returns thePatternMatcher
used when determining if an incoming request's path matches a configured filter chain. Unless overridden, the default implementation is anAntPathMatcher
.- Returns:
- the
PatternMatcher
used when determining if an incoming request's path matches a configured filter chain.
-
setPathMatcher
public void setPathMatcher(PatternMatcher pathMatcher)
Sets thePatternMatcher
used when determining if an incoming request's path matches a configured filter chain. Unless overridden, the default implementation is anAntPathMatcher
.- Parameters:
pathMatcher
- thePatternMatcher
used when determining if an incoming request's path matches a configured filter chain.
-
getFilterChainManager
public FilterChainManager getFilterChainManager()
-
setFilterChainManager
public void setFilterChainManager(FilterChainManager filterChainManager)
-
getChain
public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain)
Description copied from interface:FilterChainResolver
Returns the filter chain that should be executed for the given request, ornull
if the original chain should be used. This method allows a implementation to define arbitrary securityFilter
chains for any given request or URL pattern.- Specified by:
getChain
in interfaceFilterChainResolver
- Parameters:
request
- the incoming ServletRequestresponse
- the outgoing ServletResponseoriginalChain
- the originalFilterChain
intercepted by the ShiroFilter implementation.- Returns:
- the filter chain that should be executed for the given request, or
null
if the original chain should be used.
-
pathMatches
protected boolean pathMatches(String pattern, String path)
Returnstrue
if an incoming request path (thepath
argument) matches a configured filter chain path (thepattern
argument),false
otherwise. Simply delegates to
. Subclass implementors should think carefully before overriding this method, as typically a customgetPathMatcher()
.matches(pattern,path)
PathMatcher
should be configured for custom path matching behavior instead. Favor OO composition rather than inheritance to limit your exposure to Shiro implementation details which may change over time.- Parameters:
pattern
- the pattern to match againstpath
- the value to match with the specifiedpattern
- Returns:
true
if the requestpath
matches the specified filter chain urlpattern
,false
otherwise.
-
getPathWithinApplication
protected String getPathWithinApplication(ServletRequest request)
Merely returnsWebUtils.
and can be overridden by subclasses for custom request-to-application-path resolution behavior.getPathWithinApplication(request)
- Parameters:
request
- the incomingServletRequest
- Returns:
- the request's path within the appliation.
-
-