1、首先调用 Subject.isPermitted*/hasRole* 接口,其会委托给SecurityManager。SecurityManager 接着会委托给 Authorizer;

Authorizer是真正的授权者,如果调用如isPermitted(“user:view”),其首先会通过• PermissionResolver 把字符串转换成相应的 Permission 实例;

DelegatingSubject
public boolean hasRole(String roleIdentifier) {
return hasPrincipals() && securityManager.hasRole(getPrincipals(), roleIdentifier);
}

2、SecurityManager 接着会委托给 Authorizer;

this.authorizer = new ModularRealmAuthorizer();
public boolean hasRole(PrincipalCollection principals, String roleIdentifier) {
return this.authorizer.hasRole(principals, roleIdentifier);
}

3、ModularRealmAuthorizer 进行多 Realm 匹配流程

1)首先检查相应的 Realm 是否实现了实现了Authorizer;
2)如果实现了 Authorizer,那么接着调用其相应的isPermitted*/hasRole* 接口进行匹配

3)如果有一个Realm匹配那么将返回 true,否则返回 false。

public boolean hasRole(PrincipalCollection principals, String roleIdentifier) {
assertRealmsConfigured();
for (Realm realm : getRealms()) {
if (!(realm instanceof Authorizer)) continue;
if (((Authorizer) realm).hasRole(principals, roleIdentifier)) {
return true;
}
}
return false;
}

4、AuthorizingRealm中根据用户名去数据源中获取角色/权限,并进行判断

public boolean hasRole(PrincipalCollection principal, String roleIdentifier) {
AuthorizationInfo info = getAuthorizationInfo(principal);
return hasRole(roleIdentifier, info);
} protected boolean hasRole(String roleIdentifier, AuthorizationInfo info) {
return info != null && info.getRoles() != null && info.getRoles().contains(roleIdentifier);
}

Authorization源码解析的更多相关文章

  1. DotNetOpenAuth Part 1 : Authorization 验证服务实现及关键源码解析

    DotNetOpenAuth 是 .Net 环境下OAuth 开源实现框架.基于此,可以方便的实现 OAuth 验证(Authorization)服务.资源(Resource)服务.针对 DotNet ...

  2. Okhttp3源码解析(5)-拦截器RetryAndFollowUpInterceptor

    ### 前言 回顾: [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析](htt ...

  3. Spring Security 解析(七) —— Spring Security Oauth2 源码解析

    Spring Security 解析(七) -- Spring Security Oauth2 源码解析   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因 ...

  4. AspNetCore源码解析_1_CORS中间件

    概述 什么是跨域 在前后端分离开发方式中,跨域是我们经常会遇到的问题.所谓的跨域,就是处于安全考虑,A域名向B域名发出Ajax请求,浏览器会拒绝,抛出类似下图的错误. JSONP JSONP不是标准跨 ...

  5. AspNetCore3.1_Secutiry源码解析_1_目录

    文章目录 AspNetCore3.1_Secutiry源码解析_1_目录 AspNetCore3.1_Secutiry源码解析_2_Authentication_核心项目 AspNetCore3.1_ ...

  6. AspNetCore3.1_Secutiry源码解析_4_Authentication_JwtBear

    title: "AspNetCore3.1_Secutiry源码解析_4_Authentication_JwtBear" date: 2020-03-22T16:29:29+08: ...

  7. AspNetCore3.1_Secutiry源码解析_5_Authentication_OAuth

    title: "AspNetCore3.1_Secutiry源码解析_5_Authentication_OAuth" date: 2020-03-24T23:27:45+08:00 ...

  8. AspNetCore3.1_Secutiry源码解析_6_Authentication_OpenIdConnect

    title: "AspNetCore3.1_Secutiry源码解析_6_Authentication_OpenIdConnect" date: 2020-03-25T21:33: ...

  9. AspNetCore3.1_Secutiry源码解析_8_Authorization_授权框架

    目录 AspNetCore3.1_Secutiry源码解析_1_目录 AspNetCore3.1_Secutiry源码解析_2_Authentication_核心流程 AspNetCore3.1_Se ...

随机推荐

  1. HTML5之图片在Retina屏的常用几种处理方式

    Media Queries使用css3的媒体查询实现高清屏的图片处理. @media only screen and (-webkit-min-device-pixel-ratio: 1.5), on ...

  2. Alibaba Nacos:搭建Nacos平台

    1.下载安装包 https://github.com/alibaba/nacos/releases 往下翻,找到压缩包下载. 2.解压 tar -xvf nacos-server-$version.t ...

  3. array.includes的使用

    看看某个值在不在这个数组里面,是个完整的数 var array1 = [1, 2, 3]; console.log(array1.includes(2)); // expected output: t ...

  4. 京津冀大学生竞赛:babyphp

    京津冀大学生竞赛:babyphp 比赛的时候没做出来,回来以后一会就做出来了,难受...还是基本功不扎实,都不记得__invoke怎么触发的了 放上源码 <?php error_reportin ...

  5. CMU Database Systems - MVCC

    MVCC是一种用空间来换取更高的并发度的技术 对同一个对象不去update,而且记录下每一次的不同版本的值 存在不会消失,新值并不能抹杀原先的存在 所以update操作并不是对世界的真实反映,这是一种 ...

  6. odoo开发笔记--form视图按钮样例

    如图: 对应后台views视图,class可选内容值: class="oe_highlight" class="btn-xs" class="btn- ...

  7. Win10 高频率使用的快捷组合键

    Win10 系统有很多的快捷组合键,学会使用这些快捷组合键可以节省一点时间 0x01 Win+D 显示或最小化桌面在键盘上按下Win+D可以切换显示桌面或最小化桌面所有内容: 0x02 Ctrl+Sh ...

  8. Qt QtXml读取xml文件内容

    Qt QtXml读取xml文件内容 xml文件内容 <?xml version="1.0" encoding="UTF-8"?> <YG_RT ...

  9. Node add Test1

    root_group->addChild(node22); osg::Vec3f vec3f1 = node22->getBound().center(); osg::NodePathLi ...

  10. Docker 安装 MySQL 并实现远程连接

    获取 MySQL 镜像 docker pull mysql:5.6 查看镜像列表 docker images 启动 MySQL 镜像 docker run -itd -P mysql:5.6 bash ...