Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

casbin

Package Overview
Dependencies
Maintainers
6
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casbin - npm Package Compare versions

Comparing version 5.18.0 to 5.19.0

lib/cjs/constants.d.ts

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [5.19.0](https://github.com/casbin/node-casbin/compare/v5.18.0...v5.19.0) (2022-09-24)
### Features
* add `fieldIndexMap` ([#391](https://github.com/casbin/node-casbin/issues/391)) ([8f6e2c3](https://github.com/casbin/node-casbin/commit/8f6e2c39a19725e467aafda8b7fa948e3e471ce8))
# [5.18.0](https://github.com/casbin/node-casbin/compare/v5.17.0...v5.18.0) (2022-09-14)

@@ -2,0 +9,0 @@

8

lib/cjs/effect/defaultEffectorStream.js

@@ -33,3 +33,3 @@ "use strict";

switch (this.expr) {
case 'some(where (p_eft == allow))':
case "some(where (p_eft == allow))" /* ALLOW */:
if (eft === effector_1.Effect.Allow) {

@@ -41,3 +41,3 @@ this.res = true;

break;
case '!some(where (p_eft == deny))':
case "!some(where (p_eft == deny))" /* DENY */:
this.res = true;

@@ -50,3 +50,3 @@ if (eft === effector_1.Effect.Deny) {

break;
case 'some(where (p_eft == allow)) && !some(where (p_eft == deny))':
case "some(where (p_eft == allow)) && !some(where (p_eft == deny))" /* ALLOW_AND_DENY */:
if (eft === effector_1.Effect.Allow) {

@@ -65,3 +65,3 @@ this.res = true;

break;
case 'priority(p_eft) || deny':
case "priority(p_eft) || deny" /* PRIORITY */:
if (eft !== effector_1.Effect.Indeterminate) {

@@ -68,0 +68,0 @@ this.res = eft === effector_1.Effect.Allow;

@@ -175,3 +175,4 @@ "use strict";

if (domain === undefined) {
return this.removeFilteredGroupingPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
return this.removeFilteredGroupingPolicy(subIndex, user);
}

@@ -190,4 +191,5 @@ else {

async deleteUser(user) {
const res1 = await this.removeFilteredGroupingPolicy(0, user);
const res2 = await this.removeFilteredPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
const res1 = await this.removeFilteredGroupingPolicy(subIndex, user);
const res2 = await this.removeFilteredPolicy(subIndex, user);
return res1 || res2;

@@ -203,4 +205,5 @@ }

async deleteRole(role) {
const res1 = await this.removeFilteredGroupingPolicy(1, role);
const res2 = await this.removeFilteredPolicy(0, role);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
const res1 = await this.removeFilteredGroupingPolicy(subIndex, role);
const res2 = await this.removeFilteredPolicy(subIndex, role);
return res1 || res2;

@@ -250,3 +253,4 @@ }

async deletePermissionsForUser(user) {
return this.removeFilteredPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
return this.removeFilteredPolicy(subIndex, user);
}

@@ -260,3 +264,4 @@ /**

async getPermissionsForUser(user) {
return this.getFilteredPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
return this.getFilteredPolicy(subIndex, user);
}

@@ -263,0 +268,0 @@ /**

@@ -24,2 +24,10 @@ import { CoreEnforcer } from './coreEnforcer';

protected removeFilteredPolicyInternal(sec: string, ptype: string, fieldIndex: number, fieldValues: string[], useWatcher: boolean): Promise<boolean>;
/**
* get field index in model.fieldMap.
*/
getFieldIndex(ptype: string, field: string): number;
/**
* set index of field
*/
setFieldIndex(ptype: string, field: string, index: number): void;
}

@@ -237,3 +237,17 @@ "use strict";

}
/**
* get field index in model.fieldMap.
*/
getFieldIndex(ptype, field) {
return this.model.getFieldIndex(ptype, field);
}
/**
* set index of field
*/
setFieldIndex(ptype, field, index) {
var _a;
const assertion = (_a = this.model.model.get('p')) === null || _a === void 0 ? void 0 : _a.get(ptype);
assertion === null || assertion === void 0 ? void 0 : assertion.fieldIndexMap.set(field, index);
}
}
exports.InternalEnforcer = InternalEnforcer;

@@ -9,2 +9,3 @@ import * as rbac from '../rbac';

rm: rbac.RoleManager;
fieldIndexMap: Map<string, number>;
/**

@@ -11,0 +12,0 @@ * constructor is the constructor for Assertion.

@@ -51,2 +51,3 @@ "use strict";

this.rm = new rbac.DefaultRoleManager(10);
this.fieldIndexMap = new Map();
}

@@ -53,0 +54,0 @@ async buildIncrementalRoleLinks(rm, op, rules) {

@@ -42,2 +42,6 @@ import * as rbac from '../rbac';

printPolicy(): void;
/**
* return the field index in fieldMap, if no this field in fieldMap, add it.
*/
getFieldIndex(ptype: string, field: string): number;
}

@@ -44,0 +48,0 @@ /**

@@ -91,2 +91,3 @@ "use strict";

ast.value = value;
ast.fieldIndexMap = new Map();
if (sec === 'r' || sec === 'p') {

@@ -421,2 +422,29 @@ const tokens = value.split(',').map((n) => n.trim());

}
/**
* return the field index in fieldMap, if no this field in fieldMap, add it.
*/
getFieldIndex(ptype, field) {
var _a;
const assertion = (_a = this.model.get('p')) === null || _a === void 0 ? void 0 : _a.get(ptype);
if (!assertion) {
return -1;
}
let index = assertion.fieldIndexMap.get(field);
if (index) {
return index;
}
const pattern = ptype + '_' + field;
index = -1;
for (let i = 0; i < assertion.tokens.length; i++) {
if (assertion.tokens[i] === pattern) {
index = i;
break;
}
}
if (index === -1) {
return index;
}
assertion.fieldIndexMap.set(field, index);
return index;
}
}

@@ -423,0 +451,0 @@ exports.Model = Model;

@@ -30,3 +30,3 @@ // Copyright 2020 The Casbin Authors. All Rights Reserved.

switch (this.expr) {
case 'some(where (p_eft == allow))':
case "some(where (p_eft == allow))" /* ALLOW */:
if (eft === Effect.Allow) {

@@ -38,3 +38,3 @@ this.res = true;

break;
case '!some(where (p_eft == deny))':
case "!some(where (p_eft == deny))" /* DENY */:
this.res = true;

@@ -47,3 +47,3 @@ if (eft === Effect.Deny) {

break;
case 'some(where (p_eft == allow)) && !some(where (p_eft == deny))':
case "some(where (p_eft == allow)) && !some(where (p_eft == deny))" /* ALLOW_AND_DENY */:
if (eft === Effect.Allow) {

@@ -62,3 +62,3 @@ this.res = true;

break;
case 'priority(p_eft) || deny':
case "priority(p_eft) || deny" /* PRIORITY */:
if (eft !== Effect.Indeterminate) {

@@ -65,0 +65,0 @@ this.res = eft === Effect.Allow;

@@ -172,3 +172,4 @@ // Copyright 2018 The Casbin Authors. All Rights Reserved.

if (domain === undefined) {
return this.removeFilteredGroupingPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
return this.removeFilteredGroupingPolicy(subIndex, user);
}

@@ -187,4 +188,5 @@ else {

async deleteUser(user) {
const res1 = await this.removeFilteredGroupingPolicy(0, user);
const res2 = await this.removeFilteredPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
const res1 = await this.removeFilteredGroupingPolicy(subIndex, user);
const res2 = await this.removeFilteredPolicy(subIndex, user);
return res1 || res2;

@@ -200,4 +202,5 @@ }

async deleteRole(role) {
const res1 = await this.removeFilteredGroupingPolicy(1, role);
const res2 = await this.removeFilteredPolicy(0, role);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
const res1 = await this.removeFilteredGroupingPolicy(subIndex, role);
const res2 = await this.removeFilteredPolicy(subIndex, role);
return res1 || res2;

@@ -247,3 +250,4 @@ }

async deletePermissionsForUser(user) {
return this.removeFilteredPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
return this.removeFilteredPolicy(subIndex, user);
}

@@ -257,3 +261,4 @@ /**

async getPermissionsForUser(user) {
return this.getFilteredPolicy(0, user);
const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
return this.getFilteredPolicy(subIndex, user);
}

@@ -260,0 +265,0 @@ /**

@@ -24,2 +24,10 @@ import { CoreEnforcer } from './coreEnforcer';

protected removeFilteredPolicyInternal(sec: string, ptype: string, fieldIndex: number, fieldValues: string[], useWatcher: boolean): Promise<boolean>;
/**
* get field index in model.fieldMap.
*/
getFieldIndex(ptype: string, field: string): number;
/**
* set index of field
*/
setFieldIndex(ptype: string, field: string, index: number): void;
}

@@ -234,2 +234,16 @@ // Copyright 2018 The Casbin Authors. All Rights Reserved.

}
/**
* get field index in model.fieldMap.
*/
getFieldIndex(ptype, field) {
return this.model.getFieldIndex(ptype, field);
}
/**
* set index of field
*/
setFieldIndex(ptype, field, index) {
var _a;
const assertion = (_a = this.model.model.get('p')) === null || _a === void 0 ? void 0 : _a.get(ptype);
assertion === null || assertion === void 0 ? void 0 : assertion.fieldIndexMap.set(field, index);
}
}

@@ -9,2 +9,3 @@ import * as rbac from '../rbac';

rm: rbac.RoleManager;
fieldIndexMap: Map<string, number>;
/**

@@ -11,0 +12,0 @@ * constructor is the constructor for Assertion.

@@ -29,2 +29,3 @@ // Copyright 2017 The casbin Authors. All Rights Reserved.

this.rm = new rbac.DefaultRoleManager(10);
this.fieldIndexMap = new Map();
}

@@ -31,0 +32,0 @@ async buildIncrementalRoleLinks(rm, op, rules) {

@@ -42,2 +42,6 @@ import * as rbac from '../rbac';

printPolicy(): void;
/**
* return the field index in fieldMap, if no this field in fieldMap, add it.
*/
getFieldIndex(ptype: string, field: string): number;
}

@@ -44,0 +48,0 @@ /**

@@ -69,2 +69,3 @@ // Copyright 2018 The Casbin Authors. All Rights Reserved.

ast.value = value;
ast.fieldIndexMap = new Map();
if (sec === 'r' || sec === 'p') {

@@ -399,2 +400,29 @@ const tokens = value.split(',').map((n) => n.trim());

}
/**
* return the field index in fieldMap, if no this field in fieldMap, add it.
*/
getFieldIndex(ptype, field) {
var _a;
const assertion = (_a = this.model.get('p')) === null || _a === void 0 ? void 0 : _a.get(ptype);
if (!assertion) {
return -1;
}
let index = assertion.fieldIndexMap.get(field);
if (index) {
return index;
}
const pattern = ptype + '_' + field;
index = -1;
for (let i = 0; i < assertion.tokens.length; i++) {
if (assertion.tokens[i] === pattern) {
index = i;
break;
}
}
if (index === -1) {
return index;
}
assertion.fieldIndexMap.set(field, index);
return index;
}
}

@@ -401,0 +429,0 @@ /**

{
"name": "casbin",
"version": "5.18.0",
"version": "5.19.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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc