shiny4647 2014-01-12 02:52
浏览 5824

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进不去

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题