SpringBoot 整合Shiro 遇到多次重复调用登录方法的问题

 SptringBoot在整合Shiro在设定登录url(shiroFilterFactoryBean.setLoginUrl("/login"))时发现,一直在登录里面循环调用/login。

@RequestMapping(value = "/login")

public String login(HttpServletRequest request, ModelMap map) {

String exception = (String) request.getAttribute("shiroLoginFailure");

String msg = "";

if (exception != null) {

if (UnknownAccountException.class.getName().equals(exception)) {

System.out.println("UnknownAccountException -- > 账号不存在:");

msg = "UnknownAccountException -- > 账号不存在:";

} else if (IncorrectCredentialsException.class.getName().equals(exception)) {

System.out.println("IncorrectCredentialsException -- > 密码不正确:");

msg = "IncorrectCredentialsException -- > 密码不正确:";

} else if ("kaptchaValidateFailed".equals(exception)) {

System.out.println("kaptchaValidateFailed -- > 验证码错误");

msg = "kaptchaValidateFailed -- > 验证码错误";

} else {

msg = "else >> " + exception;

System.out.println("else -- >" + exception);

}

}

map.put("msg", msg);

return "login";

}

主要原因是因为:

                filterChainDefinitionMap.put("/css/**", "anon");

filterChainDefinitionMap.put("/images/**", "anon");

filterChainDefinitionMap.put("/js/**", "anon");

filterChainDefinitionMap.put("/json/**", "anon");

                      静态资源没有设定为可匿名访问。而前端页面中

<div class="login_face"><img src="${pageContext.request.contextPath}/images/face.jpg" class="userAvatar"></div>

所有涉及到引用静态资源的地方,都会验证失败,失败就会再次进入/login,造成了重复调用/login的现象。






 
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值