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. PDE工具箱的简单使用

    转载自Here matlab的PDE工具箱的简单使用 问题选择 边界条件选择 菜单按钮和简单使用 命令行输入pdetool,打开GUI编辑界面如下: 注意到工具栏上,就是我们要用到的,从左到右依次使用 ...

  2. HDU 1542.Atlantis-线段树求矩形面积并(离散化、扫描线/线段树)-贴模板

    好久没写过博客了,这学期不是很有热情去写博客,写过的题也懒得写题解.现在来水一水博客,写一下若干年前的题目的题解. Atlantis Time Limit: 2000/1000 MS (Java/Ot ...

  3. javascript预览本地图片

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. python 得到列表的第二大的元素

    code #coding=utf- l=[,,,,,,] max1=l[] max2=l[] if(max1>max2): pass else: max1,max2=max2,max1 :]: ...

  5. 理解Web路由(浅谈前后端路由与前后端渲染)

    1.什么是路由? 在Web开发过程中,经常会遇到『路由』的概念.那么,到底什么是路由?简单来说,路由就是URL到函数的映射. 路由的概念最开始是由后端提出来的,在以前用模板引擎开发页面的时候,是使用路 ...

  6. TypeScript之Https通信

    NetWorkRequest.ts(源代码如下) import * as https from "https"; import * as vscode from 'vscode'; ...

  7. linux桌面系统开启windows远程访问

    本文基于centos系统,且默认你的桌面系统已经安装完成 1.在linux中安装如下软件 sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epe ...

  8. [C++] namespace命名空间和using用法

    命名空间namespace:指标识符的各种可见范围. C++标准程序库中的所有标识符都被定义在一个std的namespace,这就是程序开始添加 using namespace std; 的原因. 很 ...

  9. Use of Time-series Based Forecasting Technique for Balancing Load and Reducing Consumption of Energy in a Cloud Data Center

    年份:2017 摘要: 由于工作负载分配不均,一些服务器变得过载,而另一些服务器仍处于欠载状态. 为了实现负载平衡,需要从过度使用的节点迁移一些虚拟机. 但是与此不同的是,本文提出了一种负载预测算法, ...

  10. curl的速度为什么比file_get_contents快以及具体原因

    一.背景      大家做项目的时候,不免会看到前辈的代码.博主最近看到前辈有的时候请求外部接口用的是file_get_contents,有的用的是curl.稍微了解这两部分的同学都知道,curl在性 ...