2 shiny4647 shiny4647 于 2014.01.12 10:52 提问

shiro自定义authc过滤器的问题

配置了








过滤器代码如下
public class FormAuthenticationCaptchaFilter extends FormAuthenticationFilter {
public static final String DEFAULT_CAPTCHA_PARAM = "captcha";

private String captchaParam = DEFAULT_CAPTCHA_PARAM;

public String getCaptchaParam() {

    return captchaParam;

}

protected String getCaptcha(ServletRequest request) {

    return WebUtils.getCleanParam(request, getCaptchaParam());

}

protected AuthenticationToken createToken(

ServletRequest request, ServletResponse response) {

    String username = getUsername(request);

    String password = getPassword(request);

    String captcha = getCaptcha(request);

    boolean rememberMe = isRememberMe(request);

    return new UsernamePasswordCaptchaToken(username,
            password, rememberMe, captcha);

}

 // 验证码校验
   protected void doCaptchaValidate( HttpServletRequest request 
      ,UsernamePasswordCaptchaToken token ){ 

       String captcha = (String) SecurityUtils.getSubject().getSession()
        .getAttribute(CaptchaServlet.KEY_CAPTCHA);

      if( captcha!=null && 
         !captcha.equalsIgnoreCase(token.getCaptcha()) ){ 
         throw new CaptchaException ("验证码错误!"); 
      } 
   } 


// 认证
   protected boolean executeLogin(ServletRequest request, 
      ServletResponse response) throws Exception { 
       UsernamePasswordCaptchaToken token = (UsernamePasswordCaptchaToken)createToken(request, response); 

      try { 
         doCaptchaValidate( (HttpServletRequest)request,token ); 

         Subject subject = getSubject(request, response); 
         subject.login(token); 

         return onLoginSuccess(token, subject, request, response); 
      } catch (AuthenticationException e) { 
         return onLoginFailure(token, e, request, response); 
      } 
   } 

}
但是在访问相应 url的时候再过滤器中debug进不去

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!