shiro 学习笔记

权限系统:
分配权限(把对某些安全实体的某些权限分配给某些人员的过程)
验证权限(判断某个人员或程序对某个安全实体是否拥有某个或某些权限的过程)
安全实体:比如数据,资源。
权限:比如查看,修改

权限的继承性:安全实体的包含性,比如大楼里面的房间。
权限最近匹配原则:和包含类似,里面没有权限控制,像外层找,找到最近的。
shiro 的作用:认证,授权,加密,会话。
这里写图片描述

这里写图片描述
subject:与软件交互的主体,可以是人,也可以是其他东西。
SecurityManager:shrio框架的心脏,用户操作subject,但是subject会与SecurityManager进行绑定。
Realms:本质是一个DAO.,shiro 通过Realms 获取相关的安全数据


Shiro 配置,就是SecurityManager的配置。
ini配置方式:
【main】配置应用程序的SecurityManager 实例以及任何他依赖的组件。其实就是getter/setter方法的调用,有自己默认的,我们可以定义自己的。
【users】username=password, rolename1,rolename2,(会根据users自动初始化Realms)
【roles】rolename=permissionDefinition1 .任意的字符串。应当使用wildcardPermission,printer:print.(printer,被操作的领域,后者执行的动作)
【urls】
配置都是顺序执行的。


身份认证

Principals(身份)
Credentials(凭证)
认证过程:
这里写图片描述

1.应用程序使用Subject.login方法,传递创建好的AuthenticationToken实例。
2.DelegatingSubject 委托应用程序的SecurityManager,开始真正的验证。
3。SubjectManager 接受token,委托给Authenticator实例(ModularRealmAuthenticator)通过调用authenticator.authenticate(token)
4.ModularRealmAuthenticator可以配置AuthenticaionStrategy.启动Multi-Realm


Shiro的授权

权限:
角色:
用户:
权限API
hasRole(rolename).trueJ结果。
hasRoles(List<> rolenames) [true,false] ,返回数组
hasAllRoles(collection<> rolenames)
checkRole() checkRoles(),checkRoles()

isPermitted(Permission p)
isPermitted(List perms)
isPermittedAll(Collection perms)
checkPermission(Permission p)
checkPermission(String perm)
checkPermissions(Collection perms)
checkPermissions(String… perms)

基于注解的授权。
@RequiresAuthentication : 要求当前Subject已经在当前的session 中被验证通过,才能访问,或调用。
@RequiresGuest: 在Session中没有被验证或者记住。
@RequiresPermissions(“accont:create”):需要相应的权限。
@RequiresRoles(“admin”):需要是指定角色
@RequiresUser()

这里写图片描述

1.应用程序调用Subject的hasRole*,checkRole,isPermitted*等方法,传递需要的权限或者角色。
2..DelegatingSubject 委托应用程序的SecurityManager,执行同样的方法。
3.SecurityManager实现Authorizer接口,ModularRealmAuthorizer实例。它支持协调任何授权操作过程中的一个或多个Realm实例。
4.检查配置的Realm是否实现了相同的Authorizer接口。如果是,调用Realm的hasRole*等相同方法。

PermissionResolver. (可以全局设置)将字符串转化为Permission实例。


Realms .
shiro的认证过程,最终会交给Realm执行。调用Realm的getAuthenticationInfo(token)
1.检查提交的进行认证的令牌信息。
2.根据令牌信息从数据原获取用户信息
3.对用户信息进行匹配验证
4.验证通过将返回一个封装了用户信息的AuthenticationInfo实例。
5.失败,就抛出AuthenticationException异常信息。

shiro 默认的Realms 认证实现。
SimpleCredentialsMatcher.
jdbcRealm
自定义Realm.一般继承AuthorizingRealm 实现常用的authentication,authorization.


Shiro的session管理

Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
session.setAttribute(“someKey”, someValue);

Session还有监听。
Session数据可以持久化到数据库。
自定义SessionDao 通常继承AbstractSessionDao.


shiro和springboot的结合

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值