Class PathMatchingFilterChainResolver

  • All Implemented Interfaces:
    FilterChainResolver

    public class PathMatchingFilterChainResolver
    extends Object
    implements FilterChainResolver
    A FilterChainResolver that resolves FilterChains based on url path matching, as determined by a configurable PathMatcher.

    This implementation functions by consulting a FilterChainManager for all configured filter chains (keyed by configured path pattern). If an incoming Request path matches one of the configured path patterns (via the PathMatcher, the corresponding configured FilterChain is returned.

    Since:
    1.0
    • Constructor Detail

      • PathMatchingFilterChainResolver

        public PathMatchingFilterChainResolver()
      • PathMatchingFilterChainResolver

        public PathMatchingFilterChainResolver​(javax.servlet.FilterConfig filterConfig)
    • Method Detail

      • getPathMatcher

        public org.apache.shiro.util.PatternMatcher getPathMatcher()
        Returns the PatternMatcher used when determining if an incoming request's path matches a configured filter chain. Unless overridden, the default implementation is an AntPathMatcher.
        Returns:
        the PatternMatcher used when determining if an incoming request's path matches a configured filter chain.
      • setPathMatcher

        public void setPathMatcher​(org.apache.shiro.util.PatternMatcher pathMatcher)
        Sets the PatternMatcher used when determining if an incoming request's path matches a configured filter chain. Unless overridden, the default implementation is an AntPathMatcher.
        Parameters:
        pathMatcher - the PatternMatcher used when determining if an incoming request's path matches a configured filter chain.
      • setFilterChainManager

        public void setFilterChainManager​(FilterChainManager filterChainManager)
      • getChain

        public javax.servlet.FilterChain getChain​(javax.servlet.ServletRequest request,
                                                  javax.servlet.ServletResponse response,
                                                  javax.servlet.FilterChain originalChain)
        Description copied from interface: FilterChainResolver
        Returns the filter chain that should be executed for the given request, or null if the original chain should be used.

        This method allows a implementation to define arbitrary security Filter chains for any given request or URL pattern.

        Specified by:
        getChain in interface FilterChainResolver
        Parameters:
        request - the incoming ServletRequest
        response - the outgoing ServletResponse
        originalChain - the original FilterChain 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)
        Returns true if an incoming request path (the path argument) matches a configured filter chain path (the pattern argument), false otherwise.

        Simply delegates to getPathMatcher().matches(pattern,path). Subclass implementors should think carefully before overriding this method, as typically a custom 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 against
        path - the value to match with the specified pattern
        Returns:
        true if the request path matches the specified filter chain url pattern, false otherwise.
      • getPathWithinApplication

        protected String getPathWithinApplication​(javax.servlet.ServletRequest request)
        Merely returns WebUtils.getPathWithinApplication(request) and can be overridden by subclasses for custom request-to-application-path resolution behavior.
        Parameters:
        request - the incoming ServletRequest
        Returns:
        the request's path within the appliation.