shiro登录认证流程--源码分析

shiro在未配置自定义的CredentialsMatcher密码验证器时,真正对用户名密码进行认证的方法是:

package org.apache.shiro.authc.AbstractAuthenticator.authenticate(AuthenticationToken token)下的doAuthenticate(token)方法,进入此方法:
protected AuthenticationInfo doAuthenticate(AuthenticationToken authenticationToken) throws AuthenticationException {
        assertRealmsConfigured();
        Collection<Realm> realms = getRealms();
        if (realms.size() == 1) {
            return doSingleRealmAuthentication(realms.iterator().next(), authenticationToken);
        } else {
            return doMultiRealmAuthentication(realms, authenticationToken);
        }
    }

可以看到,assertRealmsConfigured()方法作用是判断是否存在realm,如果没有,直接抛出realm配置异常:msg = "Configuration error: No realms have been configured! One or more realms must be " +"present to execute an authentication attempt."

而realm就是在securityManager.setRealm(authRealm())时配置的自定义认证规则

如果存在realm,即通过doSingleRealmAuthentication(realms.iterator().next(), authenticationToken)或者doMultiRealmAuthentication(realms, authenticationToken)(当配置了多个realm时)对用户名密码进行验证,验证成功,返回认证成功的info,失败则抛出异常

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 文章转载自:http://blog.csdn.net/w1196726224/article/details/53...
    wangzaiplus阅读 8,677评论 0 3
  • 身份验证,即在应用中谁能证明他就是他本人。一般提供如他们的身份ID一些标识信息来表明他就是他本人,如提供身份证,用...
    小孩真笨阅读 3,573评论 0 0
  • 一、架构 要学习如何使用Shiro必须先从它的架构谈起,作为一款安全框架Shiro的设计相当精妙。Shiro的应用...
    ITsupuerlady阅读 8,879评论 4 32
  • 今天脆弱的我又当班了,所以今日遵从内心,自抱自静。 等时间给我希望
    络石花阅读 1,540评论 1 1
  • 你在我心里放置一个精致的花瓶, 却不告诉我采哪朵花才适合它, 在你的花园里,我走走停停,无所适从, 如果我只能带走...
    Milynn阅读 1,711评论 0 0

友情链接更多精彩内容