Package org.apache.shiro.web.filter
Class PathMatchingFilter
- All Implemented Interfaces:
javax.servlet.Filter,org.apache.shiro.lang.util.Nameable,PathConfigProcessor
- Direct Known Subclasses:
AccessControlFilter,AnonymousFilter,NoSessionCreationFilter
Base class for Filters that will process only specified paths and allow all others to pass through.
- Since:
- 0.9
-
Field Summary
FieldsModifier and TypeFieldDescriptionA collection of path-to-config entries where the key is a path which this filter should process and the value is the (possibly null) configuration element specific to this Filter for that specific path.protected org.apache.shiro.util.PatternMatcherPatternMatcher used in determining which paths to react to for a given request.Fields inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.apache.shiro.web.servlet.AbstractFilter
filterConfig -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetPathWithinApplication(javax.servlet.ServletRequest request) Returns the context path within the application based on the specifiedrequest.protected booleanisEnabled(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, String path, Object mappedValue) protected booleanonPreHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) This default implementation always returnstrueand should be overridden by subclasses for custom logic if necessary.protected booleanpathsMatch(String pattern, String path) Returnstrueif thepathmatches the specifiedpatternstring,falseotherwise.protected booleanpathsMatch(String path, javax.servlet.ServletRequest request) Returnstrueif the incomingrequestmatches the specifiedpathpattern,falseotherwise.protected booleanpreHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) Implementation that handles path-matching behavior before a request is evaluated.javax.servlet.FilterprocessPathConfig(String path, String config) Splits any comma-delimited values that might be found in theconfigargument and sets the resultingString[]array on theappliedPathsinternal Map.Methods inherited from class org.apache.shiro.web.servlet.AdviceFilter
afterCompletion, cleanup, doFilterInternal, executeChain, postHandleMethods inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, isFilterOncePerRequest, setEnabled, setFilterOncePerRequest, shouldNotFilterMethods inherited from class org.apache.shiro.web.servlet.NameableFilter
getName, setName, toStringBuilderMethods inherited from class org.apache.shiro.web.servlet.AbstractFilter
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfigMethods inherited from class org.apache.shiro.web.servlet.ServletContextSupport
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString
-
Field Details
-
pathMatcher
PatternMatcher used in determining which paths to react to for a given request. -
appliedPaths
A collection of path-to-config entries where the key is a path which this filter should process and the value is the (possibly null) configuration element specific to this Filter for that specific path.To put it another way, the keys are the paths (urls) that this Filter will process.
The values are filter-specific data that this Filter should use when processing the corresponding key (path). The values can be null if no Filter-specific config was specified for that url.
-
-
Constructor Details
-
PathMatchingFilter
public PathMatchingFilter()
-
-
Method Details
-
processPathConfig
Splits any comma-delimited values that might be found in theconfigargument and sets the resultingString[]array on theappliedPathsinternal Map. That is:String[] values = null; if (config != null) { values = split(config); } this.appliedPaths.put(path, values);- Specified by:
processPathConfigin interfacePathConfigProcessor- Parameters:
path- the application context path to match for executing this filter.config- the specified for this particular filter only for the givenpath- Returns:
- this configured filter.
-
getPathWithinApplication
Returns the context path within the application based on the specifiedrequest. This implementation merely delegates toWebUtils.getPathWithinApplication(request), but can be overridden by subclasses for custom logic.- Parameters:
request- the incomingServletRequest- Returns:
- the context path within the application.
-
pathsMatch
Returnstrueif the incomingrequestmatches the specifiedpathpattern,falseotherwise. The default implementation acquires therequest's path within the application and determines if that matches:String requestURI =getPathWithinApplication(request);
returnpathsMatch(path,requestURI)- Parameters:
path- the configured url pattern to check the incoming request against.request- the incoming ServletRequest- Returns:
trueif the incomingrequestmatches the specifiedpathpattern,falseotherwise.
-
pathsMatch
Returnstrueif thepathmatches the specifiedpatternstring,falseotherwise. Simply delegates tothis.pathMatcher., but can be overridden by subclasses for custom matching behavior.matches(pattern,path)- Parameters:
pattern- the pattern to match againstpath- the value to match with the specifiedpattern- Returns:
trueif thepathmatches the specifiedpatternstring,falseotherwise.
-
preHandle
protected boolean preHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception Implementation that handles path-matching behavior before a request is evaluated. If the path matches and the filterisEnabledfor that path/config, the request will be allowed through via the result fromonPreHandle. If the path does not match or the filter is not enabled for that path, this filter will allow passthrough immediately to allow theFilterChainto continue executing. In order to retain path-matching functionality, subclasses should not override this method if at all possible, and instead overrideonPreHandleinstead.- Overrides:
preHandlein classAdviceFilter- Parameters:
request- the incoming ServletRequestresponse- the outgoing ServletResponse- Returns:
trueif the filter chain is allowed to continue to execute,falseif a subclass has handled the request explicitly.- Throws:
Exception- if an error occurs
-
onPreHandle
protected boolean onPreHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) throws Exception This default implementation always returnstrueand should be overridden by subclasses for custom logic if necessary.- Parameters:
request- the incoming ServletRequestresponse- the outgoing ServletResponsemappedValue- the filter-specific config value mapped to this filter in the URL rules mappings.- Returns:
trueif the request should be able to continue,falseif the filter will handle the response directly.- Throws:
Exception- if an error occurs- See Also:
-
isEnabled
protected boolean isEnabled(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, String path, Object mappedValue) throws Exception - Throws:
Exception
-