3.Shiro认证流程1_调用自定义realm

一、认证流程

认证即登录

1.获取当前的Subject,使用SecurityUtils.getSubject()

2.测试当前用户是否已经被认证,即是否已经登录,调用Subject的isAuthenticated()方法

3.若没有认证,则需要把账号密码封装成UsernamePasswordToken对象,提交到Handler。

    ①表单页面

    ②提交到Handler

    ③获取账号密码

4.执行登录Subject.login(AuthenticationToken arg0)

5.自定义Realm的方法,从数据库中获取对应的记录返回给Shiro。

    ①实际上需要继承org.apache.shiro.realm.AuthenticatingRealm类

实现doGetAuthenticationInfo(AuthenticationToken paramAuthenticationToken)方法

6.由Shiro完成对密码的比对

 

二、登录的具体代码步骤

1.自定义发realm是如何被调用的?

    在Controller中Subject的调用的login(token)方法,其中参数token就是传到了自定义的realm中doGetAuthenticationInfo(AuthenticationToken paramAuthenticationToken)方法中。在该方法中我们可以进行账号认证

2.为什么会调用自定义realm,是因为在spring.xml中注入了自定义realm的bean,并且把该bean配置到securityManager中。

3.Shiro认证流程1_调用自定义realm

    源码流程:

3.Shiro认证流程1_调用自定义realm

 

 

流程图下载:realm认证流程1_调用自定义realm.vsd