|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.shiro.web.servlet.ServletContextSupport
org.apache.shiro.web.servlet.AbstractFilter
org.apache.shiro.web.servlet.NameableFilter
org.apache.shiro.web.servlet.OncePerRequestFilter
org.apache.shiro.web.servlet.AdviceFilter
org.apache.shiro.web.filter.PathMatchingFilter
public abstract class PathMatchingFilter
Base class for Filters that will process only specified paths and allow all others to pass through.
| Field Summary | |
|---|---|
protected Map<String,Object> |
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. |
protected PatternMatcher |
pathMatcher
PatternMatcher used in determining which paths to react to for a given request. |
| Fields inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter |
|---|
ALREADY_FILTERED_SUFFIX |
| Fields inherited from class org.apache.shiro.web.servlet.AbstractFilter |
|---|
filterConfig |
| Constructor Summary | |
|---|---|
PathMatchingFilter()
|
|
| Method Summary | |
|---|---|
protected String |
getPathWithinApplication(javax.servlet.ServletRequest request)
Returns the context path within the application based on the specified request. |
protected boolean |
isEnabled(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
String path,
Object mappedValue)
Path-matching version of the parent class's OncePerRequestFilter.isEnabled(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method, but additionally allows
for inspection of any path-specific configuration values corresponding to the specified request. |
protected boolean |
onPreHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
Object mappedValue)
This default implementation always returns true and should be overridden by subclasses for custom
logic if necessary. |
protected boolean |
pathsMatch(String path,
javax.servlet.ServletRequest request)
Returns true if the incoming request matches the specified path pattern,
false otherwise. |
protected boolean |
pathsMatch(String pattern,
String path)
Returns true if the path matches the specified pattern string,
false otherwise. |
protected boolean |
preHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Implementation that handles path-matching behavior before a request is evaluated. |
javax.servlet.Filter |
processPathConfig(String path,
String config)
Splits any comma-delmited values that might be found in the config argument and sets the resulting
String[] array on the appliedPaths internal Map. |
| Methods inherited from class org.apache.shiro.web.servlet.AdviceFilter |
|---|
afterCompletion, cleanup, doFilterInternal, executeChain, postHandle |
| Methods inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter |
|---|
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, setEnabled, shouldNotFilter |
| Methods inherited from class org.apache.shiro.web.servlet.NameableFilter |
|---|
getName, setName, toStringBuilder |
| Methods inherited from class org.apache.shiro.web.servlet.AbstractFilter |
|---|
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfig |
| Methods inherited from class org.apache.shiro.web.servlet.ServletContextSupport |
|---|
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected PatternMatcher pathMatcher
protected Map<String,Object> appliedPaths
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 Detail |
|---|
public PathMatchingFilter()
| Method Detail |
|---|
public javax.servlet.Filter processPathConfig(String path,
String config)
config argument and sets the resulting
String[] array on the appliedPaths internal Map.
That is:
String[] values = null;
if (config != null) {
values = split(config);
}
this.appliedPaths.put(path, values);
processPathConfig in interface PathConfigProcessorpath - the application context path to match for executing this filter.config - the specified for this particular filter only for the given path
protected String getPathWithinApplication(javax.servlet.ServletRequest request)
request.
This implementation merely delegates to
WebUtils.getPathWithinApplication(request),
but can be overridden by subclasses for custom logic.
request - the incoming ServletRequest
protected boolean pathsMatch(String path,
javax.servlet.ServletRequest request)
true if the incoming request matches the specified path pattern,
false otherwise.
The default implementation acquires the request's path within the application and determines
if that matches:
String requestURI = getPathWithinApplication(request);
return pathsMatch(path,requestURI)
path - the configured url pattern to check the incoming request against.request - the incoming ServletRequest
true if the incoming request matches the specified path pattern,
false otherwise.
protected boolean pathsMatch(String pattern,
String path)
true if the path matches the specified pattern string,
false otherwise.
Simply delegates to
this.pathMatcher.matches(pattern,path),
but can be overridden by subclasses for custom matching behavior.
pattern - the pattern to match againstpath - the value to match with the specified pattern
true if the path matches the specified pattern string,
false otherwise.
protected boolean preHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
throws Exception
isEnabled for
that path/config, the request will be allowed through via the result from
onPreHandle. If the
path does not match or the filter is not enabled for that path, this filter will allow passthrough immediately
to allow the FilterChain to continue executing.
In order to retain path-matching functionality, subclasses should not override this method if at all
possible, and instead override
onPreHandle instead.
preHandle in class AdviceFilterrequest - the incoming ServletRequestresponse - the outgoing ServletResponse
true if the filter chain is allowed to continue to execute, false if a subclass has
handled the request explicitly.
Exception - if an error occurs
protected boolean onPreHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
Object mappedValue)
throws Exception
true and should be overridden by subclasses for custom
logic if necessary.
request - the incoming ServletRequestresponse - the outgoing ServletResponsemappedValue - the filter-specific config value mapped to this filter in the URL rules mappings.
true if the request should be able to continue, false if the filter will
handle the response directly.
Exception - if an error occursisEnabled(javax.servlet.ServletRequest, javax.servlet.ServletResponse, String, Object)
protected boolean isEnabled(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
String path,
Object mappedValue)
throws Exception
OncePerRequestFilter.isEnabled(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method, but additionally allows
for inspection of any path-specific configuration values corresponding to the specified request. Subclasses
may wish to inspect this additional mapped configuration to determine if the filter is enabled or not.
This method's default implementation ignores the path and mappedValue arguments and merely
returns the value from a call to OncePerRequestFilter.isEnabled(javax.servlet.ServletRequest, javax.servlet.ServletResponse).
It is expected that subclasses override this method if they need to perform enable/disable logic for a specific
request based on any path-specific config for the filter instance.
request - the incoming servlet requestresponse - the outbound servlet responsepath - the path matched for the incoming servlet request that has been configured with the given mappedValue.mappedValue - the filter-specific config value mapped to this filter in the URL rules mappings for the given path.
true if this filter should filter the specified request, false if it should let the
request/response pass through immediately to the next element in the FilterChain.
Exception - in the case of any error
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||