shiro入门

来源:互联网 发布:视频付费观看程序源码 编辑:程序博客网 时间:2024/05/29 03:07

一.shiro认证流程

         

二.搭建简单的shiro认证程序

         1.引入shiro的依赖包

           <dependency>
                <groupId>org.apache.shiro</groupId>
                <artifactId>shiro-core</artifactId>
                <version>1.2.3</version>
           </dependency>

          2.创建.ini文件

                 

          3.编写代码

 

三.认证执行流程

   1、创建token令牌,token中有用户提交的认证信息即账号和密码
   2、执行subject.login(token),最终由securityManager通过Authenticator进行认证
   3、Authenticator的实现ModularRealmAuthenticator调用realm从ini配置文件取用户真实的账号和密码,这里使用的是IniRealm(shiro自带)
   4、IniRealm先根据token中的账号去ini中找该账号,如果找不到则给ModularRealmAuthenticator返回null,那么ModularRealmAuthenticator
则爆出异常   org.apache.shiro.authc.UnknownAccountException: No account found for user  如果ModularRealmAuthenticator匹配密码
匹配失败则爆出org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - zhangsan, rememberMe=false] did not match the expected credentials.
匹配密码成功则认证通过。

原创粉丝点击