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

嵌套类摘要
protected  class CaptchaAuthenticationFilter.UsernamePasswordTokeExtend
          UsernamePasswordToke扩展,添加一个rememberMeValue字段,获取提交上来的rememberMe值 根据该rememberMe值去设置Cookie的有效时间。
 
字段摘要
static String DEFAULT_CAPTCHA_PARAM
          默认验证码参数名称
static String DEFAULT_SHOW_CAPTCHA_KEY_ATTRIBUTE
          登录次数超出allowLoginNum时,存储在session记录是否展示验证码的key默认名称
 
从类 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  org.apache.shiro.authc.AuthenticationToken createToken(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          重写父类方法,创建一个自定义的CaptchaAuthenticationFilter.UsernamePasswordTokeExtend
protected  boolean executeLogin(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          重写父类方法,在shiro执行登录时先对比验证码,正确后在登录,否则直接登录失败
 Integer getAllowLoginNum()
          获取允许登录次数
 String getCaptcha(javax.servlet.ServletRequest request)
          获取用户输入的验证码
 String getCaptchaParam()
          获取验证码提交的参数名称
 String getLoginNumKeyAttribute()
          获取在session中存储的登录次数名称
 String getSessionCaptchaKeyAttribute()
          获取设置在session中的存储验证码的key名称
 String getSessionShowCaptchaKeyAttribute()
          获取登录次数超出allowLoginNum时,存储在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)
          重写父类方法,当登录失败次数大于allowLoginNum(允许登录次)时,将显示验证码
protected  boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, org.apache.shiro.subject.Subject subject, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          重写父类方法,当登录成功后,将allowLoginNum(允许登录次)设置为0,重置下一次登录的状态
 void setAllowLoginNum(Integer allowLoginNum)
          设置允许登录次数,当登录次数大于该数值时,会在页面中显示验证码
 void setCaptchaParam(String captchaParam)
          设置验证码提交的参数名称
protected  void setFailureAttribute(javax.servlet.ServletRequest request, org.apache.shiro.authc.AuthenticationException ae)
          重写父类方法,当登录失败将异常信息设置到request的attribute中
 void setLoginNumKeyAttribute(String loginNumKeyAttribute)
          设置在session中存储的登录次数名称
 void setSessionCaptchaKeyAttribute(String sessionCaptchaKeyAttribute)
          设置在session中的存储验证码的key名称
 void setSessionShowCaptchaKeyAttribute(String sessionShowCaptchaKeyAttribute)
          设置登录次数超出allowLoginNum时,存储在session记录是否展示验证码的key名称
 
从类 org.apache.shiro.web.filter.authc.FormAuthenticationFilter 继承的方法
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
默认验证码参数名称

另请参见:
常量字段值

DEFAULT_SHOW_CAPTCHA_KEY_ATTRIBUTE

public static final String DEFAULT_SHOW_CAPTCHA_KEY_ATTRIBUTE
登录次数超出allowLoginNum时,存储在session记录是否展示验证码的key默认名称

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

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

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

getLoginNumKeyAttribute

public String getLoginNumKeyAttribute()
获取在session中存储的登录次数名称

返回:
Stromg

setLoginNumKeyAttribute

public void setLoginNumKeyAttribute(String loginNumKeyAttribute)
设置在session中存储的登录次数名称

参数:
loginNumKeyAttribute - 登录次数名称

getCaptcha

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

参数:
request - ServletRequest
返回:
String

getSessionShowCaptchaKeyAttribute

public String getSessionShowCaptchaKeyAttribute()
获取登录次数超出allowLoginNum时,存储在session记录是否展示验证码的key名称

返回:
String

setSessionShowCaptchaKeyAttribute

public void setSessionShowCaptchaKeyAttribute(String sessionShowCaptchaKeyAttribute)
设置登录次数超出allowLoginNum时,存储在session记录是否展示验证码的key名称

参数:
sessionShowCaptchaKeyAttribute - 是否展示验证码的key名称

getAllowLoginNum

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

返回:
Integer

setAllowLoginNum

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

参数:
allowLoginNum - 允许登录次数

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)
重写父类方法,当登录失败次数大于allowLoginNum(允许登录次)时,将显示验证码

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

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

createToken

protected org.apache.shiro.authc.AuthenticationToken createToken(javax.servlet.ServletRequest request,
                                                                 javax.servlet.ServletResponse response)
重写父类方法,创建一个自定义的CaptchaAuthenticationFilter.UsernamePasswordTokeExtend

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


Copyright © 2013. All rights reserved.