casbin 5.48.0 → 5.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -22
- package/lib/cjs/cachedEnforcer.js +1 -1
- package/lib/cjs/config.js +1 -1
- package/lib/cjs/coreEnforcer.js +25 -25
- package/lib/cjs/effect/defaultEffectorStream.js +5 -5
- package/lib/cjs/effect/index.js +6 -2
- package/lib/cjs/enforceContext.js +2 -1
- package/lib/cjs/enforcer.js +17 -13
- package/lib/cjs/frontend.js +2 -2
- package/lib/cjs/index.js +7 -3
- package/lib/cjs/internalEnforcer.js +7 -7
- package/lib/cjs/log/index.js +6 -2
- package/lib/cjs/model/assertion.js +7 -3
- package/lib/cjs/model/functionMap.d.ts +1 -1
- package/lib/cjs/model/functionMap.js +6 -2
- package/lib/cjs/model/index.js +6 -2
- package/lib/cjs/model/model.js +17 -13
- package/lib/cjs/persist/defaultFilteredAdapter.js +2 -3
- package/lib/cjs/persist/fileAdapter.js +18 -20
- package/lib/cjs/persist/fileSystem.d.ts +1 -1
- package/lib/cjs/persist/fileSystem.js +6 -3
- package/lib/cjs/persist/helper.js +1 -1
- package/lib/cjs/persist/index.js +6 -2
- package/lib/cjs/rbac/defaultRoleManager.d.ts +1 -1
- package/lib/cjs/rbac/defaultRoleManager.js +2 -2
- package/lib/cjs/rbac/index.js +6 -2
- package/lib/cjs/syncedEnforcer.js +1 -1
- package/lib/cjs/util/builtinOperators.js +1 -1
- package/lib/cjs/util/index.js +6 -2
- package/lib/cjs/util/ip.d.ts +3 -3
- package/lib/cjs/util/ip.js +20 -8
- package/lib/cjs/util/util.d.ts +2 -2
- package/lib/cjs/util/util.js +4 -4
- package/lib/esm/constants.js +1 -0
- package/lib/esm/effect/defaultEffectorStream.js +5 -5
- package/lib/esm/effect/effectorStream.js +1 -0
- package/lib/esm/enforcer.js +5 -5
- package/lib/esm/internalEnforcer.js +7 -7
- package/lib/esm/log/logger.js +1 -0
- package/lib/esm/model/functionMap.d.ts +1 -1
- package/lib/esm/model/model.js +6 -6
- package/lib/esm/persist/adapter.js +1 -0
- package/lib/esm/persist/batchAdapter.js +1 -0
- package/lib/esm/persist/defaultFilteredAdapter.js +1 -2
- package/lib/esm/persist/fileAdapter.js +16 -18
- package/lib/esm/persist/fileSystem.d.ts +1 -1
- package/lib/esm/persist/filteredAdapter.js +1 -0
- package/lib/esm/persist/updatableAdapter.js +1 -0
- package/lib/esm/persist/watcher.js +1 -0
- package/lib/esm/persist/watcherEx.js +1 -0
- package/lib/esm/rbac/defaultRoleManager.d.ts +1 -1
- package/lib/esm/rbac/roleManager.js +1 -0
- package/lib/esm/util/ip.d.ts +3 -3
- package/lib/esm/util/ip.js +20 -8
- package/lib/esm/util/util.d.ts +2 -2
- package/lib/esm/util/util.js +2 -2
- package/package.json +5 -6
- package/CHANGELOG.md +0 -812
package/lib/esm/model/model.js
CHANGED
|
@@ -447,12 +447,12 @@ export class Model {
|
|
|
447
447
|
*/
|
|
448
448
|
sortPoliciesBySubjectHierarchy() {
|
|
449
449
|
var _a, _b, _c;
|
|
450
|
-
if (((_b = (_a = this.model.get('e')) === null || _a === void 0 ? void 0 : _a.get('e')) === null || _b === void 0 ? void 0 : _b.value) !== "subjectPriority(p_eft) || deny" /* SUBJECT_PRIORITY */) {
|
|
450
|
+
if (((_b = (_a = this.model.get('e')) === null || _a === void 0 ? void 0 : _a.get('e')) === null || _b === void 0 ? void 0 : _b.value) !== "subjectPriority(p_eft) || deny" /* EffectExpress.SUBJECT_PRIORITY */) {
|
|
451
451
|
return;
|
|
452
452
|
}
|
|
453
453
|
(_c = this.model.get('p')) === null || _c === void 0 ? void 0 : _c.forEach((assertion, ptype) => {
|
|
454
|
-
const domainIndex = this.getFieldIndex(ptype, "dom" /* Domain */);
|
|
455
|
-
const subIndex = this.getFieldIndex(ptype, "sub" /* Subject */);
|
|
454
|
+
const domainIndex = this.getFieldIndex(ptype, "dom" /* FieldIndex.Domain */);
|
|
455
|
+
const subIndex = this.getFieldIndex(ptype, "sub" /* FieldIndex.Subject */);
|
|
456
456
|
// eslint-disable-next-line
|
|
457
457
|
const subjectHierarchyMap = this.getSubjectHierarchyMap(this.model.get('g').get('g').policy);
|
|
458
458
|
assertion.policy.sort((policyA, policyB) => {
|
|
@@ -478,9 +478,9 @@ export class Model {
|
|
|
478
478
|
let domain = defaultDomain;
|
|
479
479
|
groupPolicies.forEach((policy) => {
|
|
480
480
|
if (policy.length !== 2)
|
|
481
|
-
domain = policy[this.getFieldIndex('p', "dom" /* Domain */)];
|
|
482
|
-
const child = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "sub" /* Subject */)]);
|
|
483
|
-
const parent = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "obj" /* Object */)]);
|
|
481
|
+
domain = policy[this.getFieldIndex('p', "dom" /* FieldIndex.Domain */)];
|
|
482
|
+
const child = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "sub" /* FieldIndex.Subject */)]);
|
|
483
|
+
const parent = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "obj" /* FieldIndex.Object */)]);
|
|
484
484
|
policyMap.set(child, parent);
|
|
485
485
|
if (!subjectHierarchyMap.has(child)) {
|
|
486
486
|
subjectHierarchyMap.set(child, 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -46,8 +46,7 @@ export class DefaultFilteredAdapter extends FileAdapter {
|
|
|
46
46
|
if (this.filtered) {
|
|
47
47
|
throw new Error('cannot save a filtered policy');
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
return true;
|
|
49
|
+
return super.savePolicy(model);
|
|
51
50
|
}
|
|
52
51
|
static filterLine(line, filter) {
|
|
53
52
|
if (!filter) {
|
|
@@ -43,27 +43,25 @@ export class FileAdapter {
|
|
|
43
43
|
}
|
|
44
44
|
let result = '';
|
|
45
45
|
const pList = model.model.get('p');
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
result += '\n';
|
|
46
|
+
if (pList) {
|
|
47
|
+
pList.forEach((n) => {
|
|
48
|
+
n.policy.forEach((m) => {
|
|
49
|
+
result += n.key + ', ';
|
|
50
|
+
result += arrayToString(m);
|
|
51
|
+
result += '\n';
|
|
52
|
+
});
|
|
54
53
|
});
|
|
55
|
-
});
|
|
56
|
-
const gList = model.model.get('g');
|
|
57
|
-
if (!gList) {
|
|
58
|
-
return false;
|
|
59
54
|
}
|
|
60
|
-
gList.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const gList = model.model.get('g');
|
|
56
|
+
if (gList) {
|
|
57
|
+
gList.forEach((n) => {
|
|
58
|
+
n.policy.forEach((m) => {
|
|
59
|
+
result += n.key + ', ';
|
|
60
|
+
result += arrayToString(m.map((element) => this.escapeCsv(element)));
|
|
61
|
+
result += '\n';
|
|
62
|
+
});
|
|
65
63
|
});
|
|
66
|
-
}
|
|
64
|
+
}
|
|
67
65
|
await this.savePolicyFile(result.trim());
|
|
68
66
|
return true;
|
|
69
67
|
}
|
|
@@ -3,6 +3,6 @@ export interface FileSystem {
|
|
|
3
3
|
readFileSync(path: string, encoding?: string): Buffer | string;
|
|
4
4
|
writeFileSync(path: string, text: string, encoding?: string): void;
|
|
5
5
|
}
|
|
6
|
-
export declare const setDefaultFileSystem: (fs?: FileSystem
|
|
6
|
+
export declare const setDefaultFileSystem: (fs?: FileSystem) => void;
|
|
7
7
|
export declare const getDefaultFileSystem: () => FileSystem | undefined;
|
|
8
8
|
export declare const mustGetDefaultFileSystem: () => FileSystem;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RoleManager } from './roleManager';
|
|
2
|
-
export
|
|
2
|
+
export type MatchingFunc = (arg1: string, arg2: string) => boolean;
|
|
3
3
|
export declare class DefaultRoleManager implements RoleManager {
|
|
4
4
|
private allDomains;
|
|
5
5
|
private maxHierarchyLevel;
|
package/lib/esm/util/ip.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Buffer } from 'buffer/';
|
|
2
2
|
export declare const ip: {
|
|
3
|
-
toBuffer: (ip: string, buff?: Buffer
|
|
4
|
-
toString: (buff: Buffer, offset?: number
|
|
3
|
+
toBuffer: (ip: string, buff?: Buffer, offset?: number) => Buffer;
|
|
4
|
+
toString: (buff: Buffer, offset?: number, length?: number) => string;
|
|
5
5
|
isV4Format: (ip: string) => boolean;
|
|
6
6
|
isV6Format: (ip: string) => boolean;
|
|
7
|
-
fromPrefixLen: (prefixlen: number, family?: string
|
|
7
|
+
fromPrefixLen: (prefixlen: number, family?: string) => string;
|
|
8
8
|
mask: (addr: string, mask: string) => string;
|
|
9
9
|
subnet: (addr: string, mask: string) => any;
|
|
10
10
|
cidrSubnet: (cidrString: string) => any;
|
package/lib/esm/util/ip.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
27
27
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
28
|
import { Buffer } from 'buffer/';
|
|
29
|
-
const ipv4Regex = /^(\d
|
|
29
|
+
const ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d\d|\d?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|\d?\d)){3}$/;
|
|
30
30
|
const ipv6Regex = /^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
|
|
31
31
|
export const ip = {
|
|
32
32
|
toBuffer: function (ip, buff, offset) {
|
|
@@ -122,15 +122,13 @@ export const ip = {
|
|
|
122
122
|
return ipv4Regex.test(ip);
|
|
123
123
|
},
|
|
124
124
|
isV6Format: function (ip) {
|
|
125
|
-
return ipv6Regex.test(ip);
|
|
125
|
+
return ip.includes(':') && ipv6Regex.test(ip);
|
|
126
126
|
},
|
|
127
127
|
fromPrefixLen: function (prefixlen, family) {
|
|
128
|
+
family = _normalizeFamily(typeof family === 'string' ? family : 'ipv4');
|
|
128
129
|
if (prefixlen > 32) {
|
|
129
130
|
family = 'ipv6';
|
|
130
131
|
}
|
|
131
|
-
else {
|
|
132
|
-
family = _normalizeFamily(typeof family === 'string' ? family : '');
|
|
133
|
-
}
|
|
134
132
|
let len = 4;
|
|
135
133
|
if (family === 'ipv6') {
|
|
136
134
|
len = 16;
|
|
@@ -182,7 +180,7 @@ export const ip = {
|
|
|
182
180
|
return ip.toString(result);
|
|
183
181
|
},
|
|
184
182
|
subnet: function (addr, mask) {
|
|
185
|
-
const
|
|
183
|
+
const networkBuffer = ip.toBuffer(ip.mask(addr, mask));
|
|
186
184
|
// Calculate the mask's length.
|
|
187
185
|
const maskBuffer = ip.toBuffer(mask);
|
|
188
186
|
let maskLength = 0;
|
|
@@ -200,7 +198,20 @@ export const ip = {
|
|
|
200
198
|
}
|
|
201
199
|
return {
|
|
202
200
|
contains: function (other) {
|
|
203
|
-
|
|
201
|
+
let otherBuffer;
|
|
202
|
+
try {
|
|
203
|
+
otherBuffer = ip.toBuffer(ip.mask(other, mask));
|
|
204
|
+
}
|
|
205
|
+
catch (_a) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (networkBuffer.length !== otherBuffer.length)
|
|
209
|
+
return false;
|
|
210
|
+
for (let i = 0; i < networkBuffer.length; i++) {
|
|
211
|
+
if (networkBuffer[i] !== otherBuffer[i])
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
204
215
|
},
|
|
205
216
|
};
|
|
206
217
|
},
|
|
@@ -209,7 +220,8 @@ export const ip = {
|
|
|
209
220
|
const addr = cidrParts[0];
|
|
210
221
|
if (cidrParts.length !== 2)
|
|
211
222
|
throw new Error('invalid CIDR subnet: ' + addr);
|
|
212
|
-
const
|
|
223
|
+
const family = ip.isV6Format(addr) ? 'ipv6' : 'ipv4';
|
|
224
|
+
const mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10), family);
|
|
213
225
|
return ip.subnet(addr, mask);
|
|
214
226
|
},
|
|
215
227
|
isEqual: function (a, b) {
|
package/lib/esm/util/util.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ declare function arrayRemoveDuplicates(s: string[]): string[];
|
|
|
6
6
|
declare function arrayToString(a: string[]): string;
|
|
7
7
|
declare function paramsToString(...v: string[]): string;
|
|
8
8
|
declare function setEquals(a: string[], b: string[]): boolean;
|
|
9
|
-
declare function readFile(path: string, encoding?: string):
|
|
10
|
-
declare function writeFile(path: string, file: string, encoding?: string):
|
|
9
|
+
declare function readFile(path: string, encoding?: string): Promise<string>;
|
|
10
|
+
declare function writeFile(path: string, file: string, encoding?: string): Promise<void>;
|
|
11
11
|
declare function hasEval(s: string): boolean;
|
|
12
12
|
declare function replaceEval(s: string, ruleName: string, rule: string): string;
|
|
13
13
|
declare function getEvalValue(s: string): string[];
|
package/lib/esm/util/util.js
CHANGED
|
@@ -80,8 +80,8 @@ function readFile(path, encoding) {
|
|
|
80
80
|
const fs = mustGetDefaultFileSystem();
|
|
81
81
|
return new Promise((resolve, reject) => {
|
|
82
82
|
try {
|
|
83
|
-
fs.readFileSync(path, encoding || 'utf8');
|
|
84
|
-
resolve();
|
|
83
|
+
const content = fs.readFileSync(path, encoding || 'utf8');
|
|
84
|
+
resolve(content);
|
|
85
85
|
}
|
|
86
86
|
catch (e) {
|
|
87
87
|
reject(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "casbin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.50.0",
|
|
4
4
|
"description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"typings": "lib/cjs/index.d.ts",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"@types/picomatch": "^2.2.2",
|
|
30
30
|
"@typescript-eslint/eslint-plugin": "^4.17.0",
|
|
31
31
|
"@typescript-eslint/parser": "^4.17.0",
|
|
32
|
-
"coveralls": "^3.0.2",
|
|
33
32
|
"cz-conventional-changelog": "^3.2.0",
|
|
34
33
|
"eslint": "^7.22.0",
|
|
35
34
|
"eslint-config-prettier": "^6.12.0",
|
|
@@ -44,23 +43,23 @@
|
|
|
44
43
|
"semantic-release": "^17.4.4",
|
|
45
44
|
"ts-jest": "^26.5.3",
|
|
46
45
|
"tslint": "^5.11.0",
|
|
47
|
-
"typescript": "^
|
|
46
|
+
"typescript": "^4.9.5"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
49
|
"@casbin/expression-eval": "^5.3.0",
|
|
51
50
|
"await-lock": "^2.0.1",
|
|
52
51
|
"buffer": "^6.0.3",
|
|
53
52
|
"csv-parse": "^5.5.6",
|
|
54
|
-
"minimatch": "^
|
|
53
|
+
"minimatch": "^10.2.1"
|
|
55
54
|
},
|
|
56
55
|
"files": [
|
|
57
56
|
"lib",
|
|
58
57
|
"examples"
|
|
59
58
|
],
|
|
60
|
-
"homepage": "
|
|
59
|
+
"homepage": "https://casbin.apache.org",
|
|
61
60
|
"repository": {
|
|
62
61
|
"type": "git",
|
|
63
|
-
"url": "https://github.com/casbin
|
|
62
|
+
"url": "https://github.com/apache/casbin-node-casbin.git"
|
|
64
63
|
},
|
|
65
64
|
"license": "Apache-2.0",
|
|
66
65
|
"husky": {
|