Shiro登陆异常 did not match the expected credentials.

错误如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 threw exception [Request processing failed; nested exception is org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=true] did not match the expected credentials.] with root cause
org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=true] did not match the expected credentials.
at org.apache.shiro.realm.AuthenticatingRealm.assertCredentialsMatch(AuthenticatingRealm.java:600)
at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:578)
at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)
at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
at com.sk.main.controller.LoginController.login(LoginController.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)

解决方案:

  1. 这是shiro返回的密码校验结果不一样,要么你把shiro校验的令牌规则重写,就是按什么方式去校验。
  2. 要么你自己把密码加密好传给shiro。
  • 白话文讲:
    当你登陆的时候,你会创建一个UsernamePasswordToken对象,或者UsernamePasswordToken的子类对象,并且赋予账号、密码、rememberMe,这里的密码你需要和数据库一直,比如你做了md5加密,那么你先做md5加密然后再创建UsernamePasswordToken对象.
    然后你在校验完毕后:

    1
    return new SimpleAuthenticationInfo(token,memberSecurity.getLoginPswd(), getName());
    • 这里的第二个参数为密码,shiro会把第二个参数和你开始传进来的参数按规则对比,如果错误(或者是同一个引用对象)就返回上面的错误。
-------------本文结束感谢您的阅读-------------

本文标题:Shiro登陆异常 did not match the expected credentials.

文章作者:Jason

发布时间:2019年06月23日 - 01:06

最后更新:2019年06月23日 - 10:06

原始链接:https://jasonssun.github.io/2019/06/23/使用SpringBoot-Shiro框架搭建过程中遇见的密码不匹配问题的解决方法/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。