Class AuthenticatingFilter
java.lang.Object
- All Implemented Interfaces:
javax.servlet.Filter,org.apache.shiro.lang.util.Nameable,PathConfigProcessor
- Direct Known Subclasses:
BasicHttpAuthenticationFilter,BearerHttpAuthenticationFilter,FormAuthenticationFilter
An
AuthenticationFilter that is capable of automatically performing an authentication attempt
based on the incoming request.- Since:
- 0.9
-
Field Summary
FieldsFields inherited from class org.apache.shiro.web.filter.authc.AuthenticationFilter
DEFAULT_SUCCESS_URLFields inherited from class org.apache.shiro.web.filter.AccessControlFilter
DEFAULT_LOGIN_URL, GET_METHOD, POST_METHODFields inherited from class org.apache.shiro.web.filter.PathMatchingFilter
appliedPaths, pathMatcherFields 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 voidcleanup(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Exception existing) Overrides the default behavior to callAccessControlFilter.onAccessDenied(javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.Object)and swallow the exception if the exception isUnauthenticatedException.protected org.apache.shiro.authc.AuthenticationTokencreateToken(String username, String password, boolean rememberMe, String host) protected org.apache.shiro.authc.AuthenticationTokencreateToken(String username, String password, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) protected abstract org.apache.shiro.authc.AuthenticationTokencreateToken(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) protected booleanexecuteLogin(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) protected StringgetHost(javax.servlet.ServletRequest request) Returns the host name or IP associated with the current subject.protected booleanisAccessAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) Determines whether the current subject should be allowed to make the current request.protected booleanisPermissive(Object mappedValue) Returnstrueif the mappedValue contains thePERMISSIVEqualifier.protected booleanisRememberMe(javax.servlet.ServletRequest request) Returnstrueif "rememberMe" should be enabled for the login attempt associated with the currentrequest,falseotherwise.protected booleanonLoginFailure(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.authc.AuthenticationException e, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) protected booleanonLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.subject.Subject subject, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) Methods inherited from class org.apache.shiro.web.filter.authc.AuthenticationFilter
getSuccessUrl, issueSuccessRedirect, setSuccessUrlMethods inherited from class org.apache.shiro.web.filter.AccessControlFilter
getLoginUrl, getSubject, isLoginRequest, onAccessDenied, onAccessDenied, onPreHandle, redirectToLogin, saveRequest, saveRequestAndRedirectToLogin, setLoginUrlMethods inherited from class org.apache.shiro.web.filter.PathMatchingFilter
getPathWithinApplication, isEnabled, pathsMatch, pathsMatch, preHandle, processPathConfigMethods inherited from class org.apache.shiro.web.servlet.AdviceFilter
afterCompletion, 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
-
PERMISSIVE
-
-
Constructor Details
-
AuthenticatingFilter
public AuthenticatingFilter()
-
-
Method Details
-
executeLogin
protected boolean executeLogin(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception - Throws:
Exception
-
createToken
protected abstract org.apache.shiro.authc.AuthenticationToken createToken(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception - Throws:
Exception
-
createToken
protected org.apache.shiro.authc.AuthenticationToken createToken(String username, String password, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) -
createToken
protected org.apache.shiro.authc.AuthenticationToken createToken(String username, String password, boolean rememberMe, String host) -
onLoginSuccess
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.subject.Subject subject, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception - Throws:
Exception
-
onLoginFailure
protected boolean onLoginFailure(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.authc.AuthenticationException e, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) -
getHost
Returns the host name or IP associated with the current subject. This method is primarily provided for use during construction of anAuthenticationToken. The default implementation merely returnsServletRequest.getRemoteHost().- Parameters:
request- the incoming ServletRequest- Returns:
- the
InetAddressto associate with the login attempt.
-
isRememberMe
Returnstrueif "rememberMe" should be enabled for the login attempt associated with the currentrequest,falseotherwise. This implementation always returnsfalseand is provided as a template hook to subclasses that supportrememberMelogins and wish to determinerememberMein a custom manner based on the currentrequest.- Parameters:
request- the incoming ServletRequest- Returns:
trueif "rememberMe" should be enabled for the login attempt associated with the currentrequest,falseotherwise.
-
isAccessAllowed
protected boolean isAccessAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) Determines whether the current subject should be allowed to make the current request. The default implementation returnstrueif the user is authenticated. Will also returntrueif theAccessControlFilter.isLoginRequest(javax.servlet.ServletRequest, javax.servlet.ServletResponse)returns false and the "permissive" flag is set.- Overrides:
isAccessAllowedin classAuthenticationFilter- Parameters:
request- the incomingServletRequestresponse- the outgoingServletResponsemappedValue- the filter-specific config value mapped to this filter in the URL rules mappings.- Returns:
trueif request should be allowed access
-
isPermissive
Returnstrueif the mappedValue contains thePERMISSIVEqualifier.- Returns:
trueif this filter should be permissive
-
cleanup
protected void cleanup(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Exception existing) throws javax.servlet.ServletException, IOException Overrides the default behavior to callAccessControlFilter.onAccessDenied(javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.Object)and swallow the exception if the exception isUnauthenticatedException.- Overrides:
cleanupin classAdviceFilter- Parameters:
request- the incomingServletRequestresponse- the outgoingServletResponseexisting- any exception that might have occurred while executing theFilterChainor pre or post advice, ornullif the pre/chain/post execution did not throw anException.- Throws:
javax.servlet.ServletException- if any exception other than anIOExceptionis thrown.IOException- if the pre/chain/post execution throw anIOException
-