shiro认证流程记录

Subject.login()->委托给securityManager.login(this, token)-> authenticate(token)-> authenticate()->this.authenticator.authenticate(token)-> AbstractAuthenticator.authenticate(token)-> doAuthenticate(token)-> doSingleRealmAuthentication(realms.iterator().next(),-> authenticationToken)-> realm.getAuthenticationInfo(token)-> doGetAuthenticationInfo(token),前面都只是获取AuthenticationToken对象在执行完doGetAuthenticationInfo(token)后,还是在realm.getAuthenticationInfo(token)方法内,执行assertCredentialsMatch(token, info)方法进行token和info(AuthenticationToken的实例)中凭证的对比,对比正确则认证成功,失败则为密码错误。一旦执行assertCredentialsMatch方法则代表账号存在,因为在执行assertCredentialsMatch之前进行了info非空判断,而info实例是通过用户名获取的对象,在通过用户名获取info的时候,如果用户名不存在,则从数据库获取的密码为空,在自定义的realm中直接返回了null,即info对象为空,即不会进行对比认证,同时会打印debug信息,在doSingleRealmAuthentication方法接收到的值为null,此时会抛出UnknownAccountException异常。那么可以认为在realm.getAuthenticationInfo中就执行完了主要的认证匹配的流程。

猜你喜欢

转载自blog.csdn.net/weixin_43408641/article/details/89643573