Comparing version 5.19.3 to 5.20.0
@@ -0,1 +1,8 @@ | ||
# [5.20.0](https://github.com/casbin/node-casbin/compare/v5.19.3...v5.20.0) (2022-12-29) | ||
### Features | ||
* **defaultrolemanager.ts:** add hierarchical domain support for rbac ([#380](https://github.com/casbin/node-casbin/issues/380)) ([da980af](https://github.com/casbin/node-casbin/commit/da980afd80303d37a5c3e073250ed64c217c3225)), closes [#377](https://github.com/casbin/node-casbin/issues/377) | ||
## [5.19.3](https://github.com/casbin/node-casbin/compare/v5.19.2...v5.19.3) (2022-12-02) | ||
@@ -2,0 +9,0 @@ |
@@ -8,2 +8,4 @@ import { RoleManager } from './roleManager'; | ||
private hasDomainPattern; | ||
private hasDomainHierarchy; | ||
private domainHierarchyManager; | ||
private matchingFunc; | ||
@@ -36,2 +38,7 @@ private domainMatchingFunc; | ||
addDomainMatchingFunc(fn: MatchingFunc): Promise<void>; | ||
/** | ||
* addDomainHierarchy sets a rolemanager to define role inheritance between domains | ||
* @param rm RoleManager to define domain hierarchy | ||
*/ | ||
addDomainHierarchy(rm: RoleManager): Promise<void>; | ||
private generateTempRoles; | ||
@@ -38,0 +45,0 @@ /** |
@@ -114,2 +114,3 @@ "use strict"; | ||
this.hasDomainPattern = false; | ||
this.hasDomainHierarchy = false; | ||
this.allDomains = new Map(); | ||
@@ -146,9 +147,23 @@ this.allDomains.set(DEFAULT_DOMAIN, new Roles()); | ||
} | ||
/** | ||
* addDomainHierarchy sets a rolemanager to define role inheritance between domains | ||
* @param rm RoleManager to define domain hierarchy | ||
*/ | ||
async addDomainHierarchy(rm) { | ||
if (!(rm === null || rm === void 0 ? void 0 : rm.syncedHasLink)) | ||
throw Error('Domain hierarchy must be syncronous.'); | ||
this.hasDomainHierarchy = true; | ||
this.domainHierarchyManager = rm; | ||
} | ||
generateTempRoles(domain) { | ||
loadOrDefault(this.allDomains, domain, new Roles()); | ||
const patternDomain = new Set([domain]); | ||
if (this.hasDomainPattern) { | ||
if (!this.hasPattern && !this.hasDomainPattern && !this.hasDomainHierarchy) { | ||
return loadOrDefault(this.allDomains, domain, new Roles()); | ||
} | ||
const extraDomain = new Set([domain]); | ||
if (this.hasDomainPattern || this.hasDomainHierarchy) { | ||
this.allDomains.forEach((value, key) => { | ||
if (this.domainMatchingFunc(domain, key)) { | ||
patternDomain.add(key); | ||
var _a; | ||
if ((this.hasDomainPattern && this.domainMatchingFunc(domain, key)) || | ||
(((_a = this.domainHierarchyManager) === null || _a === void 0 ? void 0 : _a.syncedHasLink) && this.domainHierarchyManager.syncedHasLink(key, domain))) { | ||
extraDomain.add(key); | ||
} | ||
@@ -158,4 +173,4 @@ }); | ||
const allRoles = new Roles(); | ||
patternDomain.forEach((domain) => { | ||
loadOrDefault(this.allDomains, domain, new Roles()).forEach((value, key) => { | ||
extraDomain.forEach((dom) => { | ||
loadOrDefault(this.allDomains, dom, new Roles()).forEach((value, key) => { | ||
const role1 = allRoles.createRole(value.name, this.matchingFunc); | ||
@@ -227,9 +242,3 @@ value.getRoles().forEach((n) => { | ||
} | ||
let allRoles; | ||
if (this.hasPattern || this.hasDomainPattern) { | ||
allRoles = this.generateTempRoles(domain[0]); | ||
} | ||
else { | ||
allRoles = loadOrDefault(this.allDomains, domain[0], new Roles()); | ||
} | ||
const allRoles = this.generateTempRoles(domain[0]); | ||
if (!allRoles.hasRole(name1, this.matchingFunc) || !allRoles.hasRole(name2, this.matchingFunc)) { | ||
@@ -255,9 +264,3 @@ return false; | ||
} | ||
let allRoles; | ||
if (this.hasPattern || this.hasDomainPattern) { | ||
allRoles = this.generateTempRoles(domain[0]); | ||
} | ||
else { | ||
allRoles = loadOrDefault(this.allDomains, domain[0], new Roles()); | ||
} | ||
const allRoles = this.generateTempRoles(domain[0]); | ||
if (!allRoles.hasRole(name, this.matchingFunc)) { | ||
@@ -279,13 +282,12 @@ return []; | ||
} | ||
let allRoles; | ||
if (this.hasPattern || this.hasDomainPattern) { | ||
allRoles = this.generateTempRoles(domain[0]); | ||
} | ||
else { | ||
allRoles = loadOrDefault(this.allDomains, domain[0], new Roles()); | ||
} | ||
const allRoles = this.generateTempRoles(domain[0]); | ||
if (!allRoles.hasRole(name, this.matchingFunc)) { | ||
return []; | ||
} | ||
return [...allRoles.values()].filter((n) => n.hasDirectRole(name)).map((n) => n.name); | ||
const users = []; | ||
for (const user of allRoles.values()) { | ||
if (user.hasDirectRole(name)) | ||
users.push(user.name); | ||
} | ||
return users; | ||
} | ||
@@ -292,0 +294,0 @@ /** |
@@ -8,2 +8,4 @@ import { RoleManager } from './roleManager'; | ||
private hasDomainPattern; | ||
private hasDomainHierarchy; | ||
private domainHierarchyManager; | ||
private matchingFunc; | ||
@@ -36,2 +38,7 @@ private domainMatchingFunc; | ||
addDomainMatchingFunc(fn: MatchingFunc): Promise<void>; | ||
/** | ||
* addDomainHierarchy sets a rolemanager to define role inheritance between domains | ||
* @param rm RoleManager to define domain hierarchy | ||
*/ | ||
addDomainHierarchy(rm: RoleManager): Promise<void>; | ||
private generateTempRoles; | ||
@@ -38,0 +45,0 @@ /** |
@@ -111,2 +111,3 @@ // Copyright 2018 The Casbin Authors. All Rights Reserved. | ||
this.hasDomainPattern = false; | ||
this.hasDomainHierarchy = false; | ||
this.allDomains = new Map(); | ||
@@ -143,9 +144,23 @@ this.allDomains.set(DEFAULT_DOMAIN, new Roles()); | ||
} | ||
/** | ||
* addDomainHierarchy sets a rolemanager to define role inheritance between domains | ||
* @param rm RoleManager to define domain hierarchy | ||
*/ | ||
async addDomainHierarchy(rm) { | ||
if (!(rm === null || rm === void 0 ? void 0 : rm.syncedHasLink)) | ||
throw Error('Domain hierarchy must be syncronous.'); | ||
this.hasDomainHierarchy = true; | ||
this.domainHierarchyManager = rm; | ||
} | ||
generateTempRoles(domain) { | ||
loadOrDefault(this.allDomains, domain, new Roles()); | ||
const patternDomain = new Set([domain]); | ||
if (this.hasDomainPattern) { | ||
if (!this.hasPattern && !this.hasDomainPattern && !this.hasDomainHierarchy) { | ||
return loadOrDefault(this.allDomains, domain, new Roles()); | ||
} | ||
const extraDomain = new Set([domain]); | ||
if (this.hasDomainPattern || this.hasDomainHierarchy) { | ||
this.allDomains.forEach((value, key) => { | ||
if (this.domainMatchingFunc(domain, key)) { | ||
patternDomain.add(key); | ||
var _a; | ||
if ((this.hasDomainPattern && this.domainMatchingFunc(domain, key)) || | ||
(((_a = this.domainHierarchyManager) === null || _a === void 0 ? void 0 : _a.syncedHasLink) && this.domainHierarchyManager.syncedHasLink(key, domain))) { | ||
extraDomain.add(key); | ||
} | ||
@@ -155,4 +170,4 @@ }); | ||
const allRoles = new Roles(); | ||
patternDomain.forEach((domain) => { | ||
loadOrDefault(this.allDomains, domain, new Roles()).forEach((value, key) => { | ||
extraDomain.forEach((dom) => { | ||
loadOrDefault(this.allDomains, dom, new Roles()).forEach((value, key) => { | ||
const role1 = allRoles.createRole(value.name, this.matchingFunc); | ||
@@ -224,9 +239,3 @@ value.getRoles().forEach((n) => { | ||
} | ||
let allRoles; | ||
if (this.hasPattern || this.hasDomainPattern) { | ||
allRoles = this.generateTempRoles(domain[0]); | ||
} | ||
else { | ||
allRoles = loadOrDefault(this.allDomains, domain[0], new Roles()); | ||
} | ||
const allRoles = this.generateTempRoles(domain[0]); | ||
if (!allRoles.hasRole(name1, this.matchingFunc) || !allRoles.hasRole(name2, this.matchingFunc)) { | ||
@@ -252,9 +261,3 @@ return false; | ||
} | ||
let allRoles; | ||
if (this.hasPattern || this.hasDomainPattern) { | ||
allRoles = this.generateTempRoles(domain[0]); | ||
} | ||
else { | ||
allRoles = loadOrDefault(this.allDomains, domain[0], new Roles()); | ||
} | ||
const allRoles = this.generateTempRoles(domain[0]); | ||
if (!allRoles.hasRole(name, this.matchingFunc)) { | ||
@@ -276,13 +279,12 @@ return []; | ||
} | ||
let allRoles; | ||
if (this.hasPattern || this.hasDomainPattern) { | ||
allRoles = this.generateTempRoles(domain[0]); | ||
} | ||
else { | ||
allRoles = loadOrDefault(this.allDomains, domain[0], new Roles()); | ||
} | ||
const allRoles = this.generateTempRoles(domain[0]); | ||
if (!allRoles.hasRole(name, this.matchingFunc)) { | ||
return []; | ||
} | ||
return [...allRoles.values()].filter((n) => n.hasDirectRole(name)).map((n) => n.name); | ||
const users = []; | ||
for (const user of allRoles.values()) { | ||
if (user.hasDirectRole(name)) | ||
users.push(user.name); | ||
} | ||
return users; | ||
} | ||
@@ -289,0 +291,0 @@ /** |
{ | ||
"name": "casbin", | ||
"version": "5.19.3", | ||
"version": "5.20.0", | ||
"description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
572044
226
13481