Class FormAuthenticationFilter
- All Implemented Interfaces:
jakarta.servlet.Filter,org.apache.shiro.lang.util.Nameable
loginUrl you configure.
This filter constructs a UsernamePasswordToken with the values found in
username, password,
and rememberMe request parameters. It then calls
Subject.login(usernamePasswordToken),
effectively automatically performing a login attempt. Note that the login attempt will only occur when the
isLoginSubmission(request,response)
is true, which by default occurs when the request is for the loginUrl and
is a POST request.
If the login attempt fails, the resulting AuthenticationException fully qualified class name will
be set as a request attribute under the failureKeyAttribute key. This
FQCN can be used as an i18n key or lookup mechanism to explain to the user why their login attempt failed
(e.g. no account, incorrect password, etc).
If you would prefer to handle the authentication validation and login in your own code, consider using the
PassThruAuthenticationFilter instead, which allows requests to the
AccessControlFilter.loginUrl to pass through to your application's code directly.
- Since:
- 0.4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.tynamo.security.shiro.AccessControlFilter
GET_METHOD, LOGIN_URL, pathMatcher, POST_METHOD, REDIRECT_TO_SAVED_URL, SUCCESS_URL, TAPESTRY_VERSION, UNAUTHORIZED_URLFields 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 org.apache.shiro.authc.AuthenticationTokencreateToken(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) protected StringgetPassword(jakarta.servlet.ServletRequest request) protected StringgetUsername(jakarta.servlet.ServletRequest request) protected booleanisLoginSubmission(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) This default implementation merely returnstrueif the request is an HTTPPOST,falseotherwise.protected booleanisRememberMe(jakarta.servlet.ServletRequest request) Returnstrueif "rememberMe" should be enabled for the login attempt associated with the currentrequest,falseotherwise.protected booleanonAccessDenied(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) Processes requests where the subject was denied access as determined by theisAccessAllowedmethod.protected booleanonLoginFailure(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.authc.AuthenticationException e, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) protected booleanonLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.subject.Subject subject, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) protected voidsetFailureAttribute(jakarta.servlet.ServletRequest request, org.apache.shiro.authc.AuthenticationException ae) voidsetFailureKeyAttribute(String failureKeyAttribute) voidsetLoginUrl(String loginUrl) Sets the login URL used to authenticate a user.voidsetPasswordParam(String passwordParam) Sets the request parameter name to look for when acquiring the password.voidsetRememberMeParam(String rememberMeParam) Sets the request parameter name to look for when acquiring the rememberMe boolean value.voidsetUsernameParam(String usernameParam) Sets the request parameter name to look for when acquiring the username.Methods inherited from class org.tynamo.security.shiro.authc.AuthenticatingFilter
createToken, createToken, executeLogin, getHostMethods inherited from class org.tynamo.security.shiro.authc.AuthenticationFilter
isAccessAllowed, issueSuccessRedirectMethods inherited from class org.tynamo.security.shiro.AccessControlFilter
addConfig, getLoginContextService, getLoginUrl, getSubject, getSuccessUrl, getUnauthorizedUrl, isLoginRequest, isRedirectToSavedUrl, onAccessDenied, onPreHandle, preHandle, redirectToLogin, saveRequest, saveRequestAndRedirectToLogin, setConfig, setRedirectToSavedUrl, setSuccessUrl, setUnauthorizedUrlMethods 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
-
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
- See Also:
-
DEFAULT_USERNAME_PARAM
- See Also:
-
DEFAULT_PASSWORD_PARAM
- See Also:
-
DEFAULT_REMEMBER_ME_PARAM
- See Also:
-
-
Constructor Details
-
FormAuthenticationFilter
-
-
Method Details
-
setLoginUrl
Description copied from class:AccessControlFilterSets the login URL used to authenticate a user. Most Shiro filters use this url as the location to redirect a user when the filter requires authentication. Unless overridden, theis assumed.invalid reference
DEFAULT_LOGIN_URL- Overrides:
setLoginUrlin classAccessControlFilter- Parameters:
loginUrl- the login URL used to authenticate a user, used when redirecting users if authentication is required.
-
getUsernameParam
-
setUsernameParam
Sets the request parameter name to look for when acquiring the username. Unless overridden by calling this method, the default isusername.- Parameters:
usernameParam- the name of the request param to check for acquiring the username.
-
getPasswordParam
-
setPasswordParam
Sets the request parameter name to look for when acquiring the password. Unless overridden by calling this method, the default ispassword.- Parameters:
passwordParam- the name of the request param to check for acquiring the password.
-
getRememberMeParam
-
setRememberMeParam
Sets the request parameter name to look for when acquiring the rememberMe boolean value. Unless overridden by calling this method, the default isrememberMe. RememberMe will betrueif the parameter value equals any of those supported byWebUtils.isTrue(request,value),falseotherwise.- Parameters:
rememberMeParam- the name of the request param to check for acquiring the rememberMe boolean value.
-
getFailureKeyAttribute
-
setFailureKeyAttribute
-
onAccessDenied
protected boolean onAccessDenied(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws Exception Description copied from class:AccessControlFilterProcesses requests where the subject was denied access as determined by theisAccessAllowedmethod.- Specified by:
onAccessDeniedin classAccessControlFilter- Parameters:
request- the incomingServletRequestresponse- the outgoingServletResponse- Returns:
trueif the request should continue to be processed; false if the subclass will handle/render the response directly.- Throws:
Exception- if there is an error processing the request.
-
isLoginSubmission
protected boolean isLoginSubmission(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) This default implementation merely returnstrueif the request is an HTTPPOST,falseotherwise. Can be overridden by subclasses for custom login submission detection behavior.- Parameters:
request- the incoming ServletRequestresponse- the outgoing ServletResponse.- Returns:
trueif the request is an HTTPPOST,falseotherwise.
-
createToken
protected org.apache.shiro.authc.AuthenticationToken createToken(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) - Specified by:
createTokenin classAuthenticatingFilter
-
isRememberMe
protected boolean isRememberMe(jakarta.servlet.ServletRequest request) Description copied from class:AuthenticatingFilterReturnstrueif "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 mannner based on the currentrequest.- Overrides:
isRememberMein classAuthenticatingFilter- Parameters:
request- the incoming ServletRequest- Returns:
trueif "rememberMe" should be enabled for the login attempt associated with the currentrequest,falseotherwise.
-
onLoginSuccess
protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.subject.Subject subject, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws Exception - Overrides:
onLoginSuccessin classAuthenticatingFilter- Throws:
Exception
-
onLoginFailure
protected boolean onLoginFailure(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.authc.AuthenticationException e, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) - Overrides:
onLoginFailurein classAuthenticatingFilter
-
setFailureAttribute
protected void setFailureAttribute(jakarta.servlet.ServletRequest request, org.apache.shiro.authc.AuthenticationException ae) -
getUsername
-
getPassword
-