com.github.dactiv.showcase.service.account
类 CaptchaAuthenticationFilter

java.lang.Object
  继承者 org.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
                          继承者 org.apache.shiro.web.filter.AccessControlFilter
                              继承者 org.apache.shiro.web.filter.authc.AuthenticationFilter
                                  继承者 org.apache.shiro.web.filter.authc.AuthenticatingFilter
                                      继承者 org.apache.shiro.web.filter.authc.FormAuthenticationFilter
                                          继承者 com.github.dactiv.showcase.service.account.CaptchaAuthenticationFilter
所有已实现的接口:
javax.servlet.Filter, org.apache.shiro.util.Nameable, org.apache.shiro.web.filter.PathConfigProcessor

@Component
public class CaptchaAuthenticationFilter
extends org.apache.shiro.web.filter.authc.FormAuthenticationFilter

验证码登录认证Filter

作者:
maurice

字段摘要
static String DEFAULT_CAPTCHA_PARAM
          默认验证码参数名称
 
从类 org.apache.shiro.web.filter.authc.FormAuthenticationFilter 继承的字段
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME, DEFAULT_PASSWORD_PARAM, DEFAULT_REMEMBER_ME_PARAM, DEFAULT_USERNAME_PARAM
 
从类 org.apache.shiro.web.filter.authc.AuthenticatingFilter 继承的字段
PERMISSIVE
 
从类 org.apache.shiro.web.filter.authc.AuthenticationFilter 继承的字段
DEFAULT_SUCCESS_URL
 
从类 org.apache.shiro.web.filter.AccessControlFilter 继承的字段
DEFAULT_LOGIN_URL, GET_METHOD, POST_METHOD
 
从类 org.apache.shiro.web.filter.PathMatchingFilter 继承的字段
appliedPaths, pathMatcher
 
从类 org.apache.shiro.web.servlet.OncePerRequestFilter 继承的字段
ALREADY_FILTERED_SUFFIX
 
从类 org.apache.shiro.web.servlet.AbstractFilter 继承的字段
filterConfig
 
构造方法摘要
CaptchaAuthenticationFilter()
           
 
方法摘要
protected  boolean executeLogin(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          重写父类方法,在shiro执行登录时先对比验证码,正确后在登录,否则直接登录失败
 Integer getAllowIncorrectNumber()
          获取允许登录次数
 String getCaptcha(javax.servlet.ServletRequest request)
          获取用户输入的验证码
 String getCaptchaParam()
          获取验证码提交的参数名称
 String getLoginIncorrectNumberKeyAttribute()
          获取登录错误次数的key属性名称
 String getSessionCaptchaKeyAttribute()
          获取设置在session中的存储验证码的key名称
protected  boolean onLoginFailure(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.authc.AuthenticationException e, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          重写父类方法,当登录失败后,将allowIncorrectNumber(允许登错误录次) + 1
protected  boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.subject.Subject subject, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          重写父类方法,当登录成功后,将allowIncorrectNumber(允许登错误录次)设置为0,重置下一次登录的状态
 void setAllowIncorrectNumber(Integer allowIncorrectNumber)
          设置允许登录次数,当登录次数大于该数值时,会在页面中显示验证码
 void setCaptchaParam(String captchaParam)
          设置验证码提交的参数名称
protected  void setFailureAttribute(javax.servlet.ServletRequest request, org.apache.shiro.authc.AuthenticationException ae)
          重写父类方法,当登录失败将异常信息设置到request的attribute中
 void setLoginIncorrectNumberKeyAttribute(String loginIncorrectNumberKeyAttribute)
          设置登录错误次数的key属性名称
 void setSessionCaptchaKeyAttribute(String sessionCaptchaKeyAttribute)
          设置在session中的存储验证码的key名称
 
从类 org.apache.shiro.web.filter.authc.FormAuthenticationFilter 继承的方法
createToken, getFailureKeyAttribute, getPassword, getPasswordParam, getRememberMeParam, getUsername, getUsernameParam, isLoginSubmission, isRememberMe, onAccessDenied, setFailureKeyAttribute, setLoginUrl, setPasswordParam, setRememberMeParam, setUsernameParam
 
从类 org.apache.shiro.web.filter.authc.AuthenticatingFilter 继承的方法
cleanup, createToken, createToken, getHost, isAccessAllowed, isPermissive
 
从类 org.apache.shiro.web.filter.authc.AuthenticationFilter 继承的方法
getSuccessUrl, issueSuccessRedirect, setSuccessUrl
 
从类 org.apache.shiro.web.filter.AccessControlFilter 继承的方法
getLoginUrl, getSubject, isLoginRequest, onAccessDenied, onPreHandle, redirectToLogin, saveRequest, saveRequestAndRedirectToLogin
 
从类 org.apache.shiro.web.filter.PathMatchingFilter 继承的方法
getPathWithinApplication, isEnabled, pathsMatch, pathsMatch, preHandle, processPathConfig
 
从类 org.apache.shiro.web.servlet.AdviceFilter 继承的方法
afterCompletion, doFilterInternal, executeChain, postHandle
 
从类 org.apache.shiro.web.servlet.OncePerRequestFilter 继承的方法
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, setEnabled, shouldNotFilter
 
从类 org.apache.shiro.web.servlet.NameableFilter 继承的方法
getName, setName, toStringBuilder
 
从类 org.apache.shiro.web.servlet.AbstractFilter 继承的方法
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfig
 
从类 org.apache.shiro.web.servlet.ServletContextSupport 继承的方法
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

DEFAULT_CAPTCHA_PARAM

public static final String DEFAULT_CAPTCHA_PARAM
默认验证码参数名称

另请参见:
常量字段值
构造方法详细信息

CaptchaAuthenticationFilter

public CaptchaAuthenticationFilter()
方法详细信息

executeLogin

protected boolean executeLogin(javax.servlet.ServletRequest request,
                               javax.servlet.ServletResponse response)
                        throws Exception
重写父类方法,在shiro执行登录时先对比验证码,正确后在登录,否则直接登录失败

覆盖:
org.apache.shiro.web.filter.authc.AuthenticatingFilter 中的 executeLogin
抛出:
Exception

setFailureAttribute

protected void setFailureAttribute(javax.servlet.ServletRequest request,
                                   org.apache.shiro.authc.AuthenticationException ae)
重写父类方法,当登录失败将异常信息设置到request的attribute中

覆盖:
org.apache.shiro.web.filter.authc.FormAuthenticationFilter 中的 setFailureAttribute

onLoginFailure

protected boolean onLoginFailure(org.apache.shiro.authc.AuthenticationToken token,
                                 org.apache.shiro.authc.AuthenticationException e,
                                 javax.servlet.ServletRequest request,
                                 javax.servlet.ServletResponse response)
重写父类方法,当登录失败后,将allowIncorrectNumber(允许登错误录次) + 1

覆盖:
org.apache.shiro.web.filter.authc.FormAuthenticationFilter 中的 onLoginFailure

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
重写父类方法,当登录成功后,将allowIncorrectNumber(允许登错误录次)设置为0,重置下一次登录的状态

覆盖:
org.apache.shiro.web.filter.authc.FormAuthenticationFilter 中的 onLoginSuccess
抛出:
Exception

setCaptchaParam

public void setCaptchaParam(String captchaParam)
设置验证码提交的参数名称

参数:
captchaParam - 验证码提交的参数名称

getCaptchaParam

public String getCaptchaParam()
获取验证码提交的参数名称

返回:
String

setSessionCaptchaKeyAttribute

public void setSessionCaptchaKeyAttribute(String sessionCaptchaKeyAttribute)
设置在session中的存储验证码的key名称

参数:
sessionCaptchaKeyAttribute - 存储验证码的key名称

getSessionCaptchaKeyAttribute

public String getSessionCaptchaKeyAttribute()
获取设置在session中的存储验证码的key名称

返回:
Sting

getLoginIncorrectNumberKeyAttribute

public String getLoginIncorrectNumberKeyAttribute()
获取登录错误次数的key属性名称

返回:
String

setLoginIncorrectNumberKeyAttribute

public void setLoginIncorrectNumberKeyAttribute(String loginIncorrectNumberKeyAttribute)
设置登录错误次数的key属性名称

参数:
loginIncorrectNumberKeyAttribute - 属性名称

getCaptcha

public String getCaptcha(javax.servlet.ServletRequest request)
获取用户输入的验证码

参数:
request - ServletRequest
返回:
String

getAllowIncorrectNumber

public Integer getAllowIncorrectNumber()
获取允许登录次数

返回:
Integer

setAllowIncorrectNumber

public void setAllowIncorrectNumber(Integer allowIncorrectNumber)
设置允许登录次数,当登录次数大于该数值时,会在页面中显示验证码

参数:
allowIncorrectNumber - 允许登录次数


Copyright © 2014. All rights reserved.