Authorization源码解析
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源码解析的更多相关文章
- DotNetOpenAuth Part 1 : Authorization 验证服务实现及关键源码解析
DotNetOpenAuth 是 .Net 环境下OAuth 开源实现框架.基于此,可以方便的实现 OAuth 验证(Authorization)服务.资源(Resource)服务.针对 DotNet ...
- Okhttp3源码解析(5)-拦截器RetryAndFollowUpInterceptor
### 前言 回顾: [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析](htt ...
- Spring Security 解析(七) —— Spring Security Oauth2 源码解析
Spring Security 解析(七) -- Spring Security Oauth2 源码解析 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因 ...
- AspNetCore源码解析_1_CORS中间件
概述 什么是跨域 在前后端分离开发方式中,跨域是我们经常会遇到的问题.所谓的跨域,就是处于安全考虑,A域名向B域名发出Ajax请求,浏览器会拒绝,抛出类似下图的错误. JSONP JSONP不是标准跨 ...
- AspNetCore3.1_Secutiry源码解析_1_目录
文章目录 AspNetCore3.1_Secutiry源码解析_1_目录 AspNetCore3.1_Secutiry源码解析_2_Authentication_核心项目 AspNetCore3.1_ ...
- AspNetCore3.1_Secutiry源码解析_4_Authentication_JwtBear
title: "AspNetCore3.1_Secutiry源码解析_4_Authentication_JwtBear" date: 2020-03-22T16:29:29+08: ...
- AspNetCore3.1_Secutiry源码解析_5_Authentication_OAuth
title: "AspNetCore3.1_Secutiry源码解析_5_Authentication_OAuth" date: 2020-03-24T23:27:45+08:00 ...
- AspNetCore3.1_Secutiry源码解析_6_Authentication_OpenIdConnect
title: "AspNetCore3.1_Secutiry源码解析_6_Authentication_OpenIdConnect" date: 2020-03-25T21:33: ...
- AspNetCore3.1_Secutiry源码解析_8_Authorization_授权框架
目录 AspNetCore3.1_Secutiry源码解析_1_目录 AspNetCore3.1_Secutiry源码解析_2_Authentication_核心流程 AspNetCore3.1_Se ...
随机推荐
- Python 03 pip 的安装和使用
原文:https://www.runoob.com/w3cnote/python-pip-install-usage.html 原文:https://www.jianshu.com/p/2be68ef ...
- CSS3 之filter毛玻璃效果弹窗
先看效果: 效果主要用css3的滤镜属性实现,代码如下: <!DOCTYPE html> <html lang="en"> <head> < ...
- go 指南学习笔记
1 If for 后面没有小括号.后面的花括号,要在当前行,并且中间有内容,右花括号要单独一行. 因为go会格式化代码,自动插入分号. 2 函数和方法的区别: 方法需要有一个接受者(select ...
- rust变量与可变性
fn main() { //let x = 5; let mut x = 5; //通过const定义常量名称要大写,并且值不可更改 const Y:i32=6; println!("Y i ...
- compass和paoding分词器的基本使用
1.实现搜索的技术: 数据库查询:like查询:lucene全文检索技术: 1)在数据量比较大,查询字段比较多的情况下,如果采用数据库like sql查询,性能比较差:采用lucene来查询,性能相对 ...
- Pygame 贪吃蛇
目录 代码 遇到的问题 参考 代码 #-*-encoding=utf-8-*- # Wormy(a Nibbles clone) # By Al Sweigart al@inventwithpytho ...
- shell中$(( ))、$( )、``与${ }的区别
转 :shell $(( )).$( ).``与${ }的区别 $( )与` `(反引号)命令替换 在bash中,$( )与` `(反引号)都是用来作命令替换的.命令替换与变量替换差不多,都是用来重组 ...
- css3实现左侧固宽,右侧随着屏幕,右侧随着屏幕变化而变化
A, ----float+calc(css3新属性计算属性)方式 <div class="Father"> <div class="LeftChildr ...
- enq: DX – contention等待事件解决方法
前几日,一测试环境在dblink单表同步的时候(不管怎么说,目前仍然是同构数据库同步性能最快的方法,别听网上的扯淡,无论goldengate还是java层,都是比较慢的),某张表一直同步不过去,看了一 ...
- matlab学习笔记10_2 一般操作符
一起来学matlab-matlab学习笔记10 10_2一般操作符和数据显示格式 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合应用>张德 ...