shiro Apache 框架的学习之authentication 和authorization
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了shiro Apache 框架的学习之authentication 和authorization,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2170字,纯文字阅读大概需要4分钟。
内容图文
shiro 作为Apache的开源项目。该框架下的主要模块包含如下:
1,Subject
2,SecurityManager
3,Authenticator
4,Authorizer
5,Realm
6,SessionManager
7,SessionDao
8,CacheManager
9,Cryptography
源码下载链接:http://shiro.apache.org/download.html 详见官网。
如下以版本1.4学习为主。
shiro 作为java security framework, 其特点参考官网和百科。
如下以例子用户登录做authentication开篇介绍。
编写如下伪代码:
// 伪代码... class Controller{
... ModelAndView login(Customer c){ Subject s = SecurityUtils.getSubject() UsenamePasswordToken token = new U...(c); try{s.login(token);} catche(..){..} .. } }
例子是个简单的login的Controller,使用SpringMVC的思想。
代码中会引入有关shiro框架的各种类。
很明显我们看到了Subject 这个模块了。但是其他的模块好像都没有看到。这个时候我们不得不思考Subject是一个什么类,它是如何来完成Authentication和Authorization的。
很明显我们是一头雾水的,在没看APi的情况下。
源码学习: 通过查看shiro 的API文档 我们至少可以发现Subject的hierarchy 结构图。它有一个委托的子类DelegatingSubject 。以及Api中介绍的如何获得这个instance的方法:SecurityUtils.getSubject() (To acquire the currently-executing
Subject 获取当前执行的用户Subject,很明显避免并发产生的问题。
)
interface Authencator method: authencate(...)
SecurityUtils Api下有三个静态的方法;我们可以得到SecurityManager 模块了。
在执行Subject的login(token)方法时,通过如上链接下载的源码学习,可以看到
login(token)方法由DelegatingSubject的login(token)运行指向了
DefaultSecurityManager 的login(subject,token),在此方法中进行authenticate(token)
从此开始为了获得AuthenticationInfo
此时:AuthenticatingSecurityManager实现了该方法,执行该方法时,Manager this.authenticator.authenticate()使用一个
了 实现了模块Authenticator
authenticate(token)的抽象类AbstractAuthenticator在执行authenticate(token)方法时候,将执行一个doAuthenticate(token)
notice:注意虽然AbstractAuthenticator 有方法:authenticate(),但是方法修饰为 final ,不会造成歧义。
doAuthenticate(token)该
方法是个抽象方法,这个时候,让子类ModularRealmAuthenticator来实现了该方法。 该方法中我们会得到一个
Realms模块。
最终方法通过doAuthenticate(token)--->doSingleRealmsAuthentication(realms,token)--->Realms 模块的doGetAuthenticationInfo(token)
最终需要我们配置一个类CustomerRealm 来继承AuthorizatingRealms 实现抽象方法doGetAuthenticationInfo(token) 和dogetAuthorizationInfo(token)抽象方法。
总结:在做authenticating和authorizating 时候,我们是将该验证交给了以个核心的SecurityManager来管理。而SecurityManager将该登录验证和权限管理交给对应的...SecurityManager,再交给验证器来做对应的验证和权限验证
而为了做这个验证我们将此验证交给开发者来做这个Realms的管理。
而SecurityManager 接口实现了接口:Authenticator, Authorizer, SessionManager
其中的设计模式叫什么来着的,有点忘记了。
原文:https://www.cnblogs.com/futureT/p/11380600.html
内容总结
以上是互联网集市为您收集整理的shiro Apache 框架的学习之authentication 和authorization全部内容,希望文章能够帮你解决shiro Apache 框架的学习之authentication 和authorization所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。