|
||||||||||
| 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.tynamo.security.shiro.AccessControlFilter
public abstract class AccessControlFilter
Superclass for any filter that controls access to a resource and may redirect the user to the login page
if they are not authenticated. This superclass provides the method
saveRequestAndRedirectToLogin(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
which is used by many subclasses as the behavior when a user is unauthenticated.
This class and the subclasses that are used as Shiro's built-in filters were copied from Shiro 1.1.0
and modified locally to implement same behavior as specified in https://issues.apache.org/jira/browse/SHIRO-256
We'll revert to using Shiro's filters if the feature gets implemented in Shiro 2.x
| Field Summary | |
|---|---|
static java.lang.String |
GET_METHOD
Constant representing the HTTP 'GET' request method, equal to GET. |
static java.lang.String |
LOGIN_URL
|
protected org.apache.shiro.util.PatternMatcher |
pathMatcher
|
static java.lang.String |
POST_METHOD
Constant representing the HTTP 'POST' request method, equal to POST. |
static boolean |
REDIRECT_TO_SAVED_URL
|
static java.lang.String |
SUCCESS_URL
|
static java.lang.String |
UNAUTHORIZED_URL
|
| 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 | |
|---|---|
AccessControlFilter(PageService pageService)
|
|
| Method Summary | |
|---|---|
void |
addConfig(java.lang.String config)
|
java.lang.String |
getLoginUrl()
Returns the login URL used to authenticate a user. |
protected PageService |
getPageService()
|
protected org.apache.shiro.subject.Subject |
getSubject(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Convenience method that acquires the Subject associated with the request. |
java.lang.String |
getSuccessUrl()
Returns the success url to use as the default location a user is sent after logging in. |
java.lang.String |
getUnauthorizedUrl()
|
protected abstract boolean |
isAccessAllowed(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.Object mappedValue)
Returns true if the request is allowed to proceed through the filter normally, or false
if the request should be handled by the
onAccessDenied(request,response,mappedValue)
method instead. |
protected boolean |
isLoginRequest(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Returns true if the incoming request is a login request, false otherwise. |
boolean |
isRedirectToSavedUrl()
|
protected abstract boolean |
onAccessDenied(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Processes requests where the subject was denied access as determined by the isAccessAllowed
method. |
protected boolean |
onAccessDenied(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.Object mappedValue)
Processes requests where the subject was denied access as determined by the isAccessAllowed
method, retaining the mappedValue that was used during configuration. |
boolean |
onPreHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.Object mappedValue)
Returns true if
isAccessAllowed(Request,Response,Object),
otherwise returns the result of
onAccessDenied(Request,Response,Object). |
protected boolean |
preHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
|
protected void |
redirectToLogin(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Convenience method for subclasses that merely acquires the getLoginUrl and redirects
the request to that url. |
protected void |
saveRequest(javax.servlet.ServletRequest request)
Convenience method merely delegates to WebUtils.saveRequest(request) to save the request
state for reuse later. |
protected void |
saveRequestAndRedirectToLogin(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
Convenience method for subclasses to use when a login redirect is required. |
void |
setConfig(java.lang.String config)
|
void |
setLoginUrl(java.lang.String loginUrl)
Sets the login URL used to authenticate a user. |
void |
setRedirectToSavedUrl(boolean redirectToSavedUrl)
|
void |
setSuccessUrl(java.lang.String successUrl)
Sets the default/fallback success url to use as the default location a user is sent after logging in. |
void |
setUnauthorizedUrl(java.lang.String unauthorizedUrl)
|
| 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 |
|---|
public static java.lang.String LOGIN_URL
public static java.lang.String SUCCESS_URL
public static java.lang.String UNAUTHORIZED_URL
public static boolean REDIRECT_TO_SAVED_URL
protected org.apache.shiro.util.PatternMatcher pathMatcher
public static final java.lang.String GET_METHOD
GET.
public static final java.lang.String POST_METHOD
POST.
| Constructor Detail |
|---|
public AccessControlFilter(PageService pageService)
| Method Detail |
|---|
public void addConfig(java.lang.String config)
public void setConfig(java.lang.String config)
public java.lang.String getSuccessUrl()
#DEFAULT_SUCCESS_URL.
public void setSuccessUrl(java.lang.String successUrl)
#DEFAULT_SUCCESS_URL.
successUrl - the success URL to redirect the user to after a successful login.public java.lang.String getLoginUrl()
DEFAULT_LOGIN_URL is assumed, which can be overridden via
setLoginUrl.
public void setLoginUrl(java.lang.String loginUrl)
DEFAULT_LOGIN_URL is assumed.
loginUrl - the login URL used to authenticate a user, used when redirecting users if authentication is required.public java.lang.String getUnauthorizedUrl()
public void setUnauthorizedUrl(java.lang.String unauthorizedUrl)
protected org.apache.shiro.subject.Subject getSubject(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
SecurityUtils.getSubject().
request - the incoming ServletRequestresponse - the outgoing ServletResponse
protected abstract boolean isAccessAllowed(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.Object mappedValue)
throws java.lang.Exception
true if the request is allowed to proceed through the filter normally, or false
if the request should be handled by the
onAccessDenied(request,response,mappedValue)
method instead.
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 proceed through the filter normally, false if the
request should be processed by this filter's
onAccessDenied(ServletRequest,ServletResponse,Object) method instead.
java.lang.Exception - if an error occurs during processing.
protected boolean onAccessDenied(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.Object mappedValue)
throws java.lang.Exception
isAccessAllowed
method, retaining the mappedValue that was used during configuration.
This method immediately delegates to onAccessDenied(ServletRequest,ServletResponse) as a
convenience in that most post-denial behavior does not need the mapped config again.
request - the incoming ServletRequestresponse - the outgoing ServletResponsemappedValue - the config specified for the filter in the matching request's filter chain.
true if the request should continue to be processed; false if the subclass will
handle/render the response directly.
java.lang.Exception - if there is an error processing the request.
protected abstract boolean onAccessDenied(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
throws java.lang.Exception
isAccessAllowed
method.
request - the incoming ServletRequestresponse - the outgoing ServletResponse
true if the request should continue to be processed; false if the subclass will
handle/render the response directly.
java.lang.Exception - if there is an error processing the request.
public boolean onPreHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.Object mappedValue)
throws java.lang.Exception
true if
isAccessAllowed(Request,Response,Object),
otherwise returns the result of
onAccessDenied(Request,Response,Object).
true if
isAccessAllowed,
otherwise returns the result of
onAccessDenied.
java.lang.Exception - if an error occurs.
protected boolean preHandle(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
throws java.lang.Exception
preHandle in class org.apache.shiro.web.servlet.AdviceFilterjava.lang.Exception
protected boolean isLoginRequest(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
true if the incoming request is a login request, false otherwise.
The default implementation merely returns true if the incoming request matches the configured
loginUrl by calling
pathsMatch(loginUrl, request).
request - the incoming ServletRequestresponse - the outgoing ServletResponse
true if the incoming request is a login request, false otherwise.
protected void saveRequestAndRedirectToLogin(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
throws java.io.IOException
saveRequest(request)
and then redirectToLogin(request,response).
request - the incoming ServletRequestresponse - the outgoing ServletResponse
java.io.IOException - if an error occurs.protected void saveRequest(javax.servlet.ServletRequest request)
WebUtils.saveRequest(request) to save the request
state for reuse later. This is mostly used to retain user request state when a redirect is issued to
return the user to their originally requested url/resource.
If you need to save and then immediately redirect the user to login, consider using
saveRequestAndRedirectToLogin(request,response) directly.
request - the incoming ServletRequest to save for re-use later (for example, after a redirect).
protected void redirectToLogin(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response)
throws java.io.IOException
getLoginUrl and redirects
the request to that url.
N.B. If you want to issue a redirect with the intention of allowing the user to then return to their
originally requested URL, don't use this method directly. Instead you should call
saveRequestAndRedirectToLogin(request,response), which will save the current request state so that it can
be reconstructed and re-used after a successful login.
request - the incoming ServletRequestresponse - the outgoing ServletResponse
java.io.IOException - if an error occurs.public boolean isRedirectToSavedUrl()
public void setRedirectToSavedUrl(boolean redirectToSavedUrl)
protected PageService getPageService()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||