Comparing version
@@ -116,2 +116,3 @@ "use strict"; | ||
if (customConditionFns === void 0) { customConditionFns = {}; } | ||
conditions_1.ConditionUtil.resetCustomConditionFunctions(); | ||
conditions_1.ConditionUtil.setCustomConditionFunctions(customConditionFns); | ||
@@ -168,2 +169,3 @@ this.setGrants(grants); | ||
this._grants = {}; | ||
conditions_1.ConditionUtil.resetCustomConditionFunctions(); | ||
return this; | ||
@@ -170,0 +172,0 @@ }; |
@@ -21,6 +21,8 @@ import { TrueCondition as TrueConditionFunction } from "./TrueCondition"; | ||
static registerCustomConditionFunction(functionName: string, fn: IFunctionCondition): void; | ||
static resetCustomConditionFunctions(): void; | ||
static getCustomConditionFunctions(): IDictionary<IFunctionCondition>; | ||
static setCustomConditionFunctions(customConditionFunctions?: IDictionary<IFunctionCondition>): void; | ||
static validateCondition(condition: any): void; | ||
static evaluate(condition: ICondition, context: any): boolean | Promise<boolean>; | ||
static getValueByPath(context: any, valuePathOrValue: any): any; | ||
} |
@@ -32,2 +32,5 @@ "use strict"; | ||
}; | ||
ConditionUtil.resetCustomConditionFunctions = function () { | ||
ConditionUtil._customConditionFunctions = {}; | ||
}; | ||
ConditionUtil.getCustomConditionFunctions = function () { | ||
@@ -42,2 +45,23 @@ return ConditionUtil._customConditionFunctions; | ||
}; | ||
ConditionUtil.validateCondition = function (condition) { | ||
if (!condition) { | ||
return; | ||
} | ||
if (typeof condition === "function") { | ||
return; | ||
} | ||
if (typeof condition === "string") { | ||
if (!ConditionUtil._customConditionFunctions[condition]) { | ||
throw new core_1.AccessControlError("Condition function: " + condition + " not found"); | ||
} | ||
return; | ||
} | ||
if (typeof condition === "object") { | ||
if (!condition.Fn || !(ConditionUtil[condition.Fn] || | ||
ConditionUtil._customConditionFunctions[condition.Fn])) { | ||
throw new core_1.AccessControlError("Condition function:" + condition.Fn + " is not valid"); | ||
} | ||
return; | ||
} | ||
}; | ||
ConditionUtil.evaluate = function (condition, context) { | ||
@@ -44,0 +68,0 @@ if (!condition) { |
@@ -199,2 +199,3 @@ "use strict"; | ||
grantsCopy[role].grants.forEach(function (grant) { | ||
conditions_1.ConditionUtil.validateCondition(grant.condition); | ||
grant.attributes = grant.attributes || ['*']; | ||
@@ -286,2 +287,3 @@ }); | ||
grants[role].grants = grants[role].grants || []; | ||
conditions_1.ConditionUtil.validateCondition(access.condition); | ||
grants[role].grants.push({ | ||
@@ -711,5 +713,7 @@ resource: access.resource, | ||
CommonUtil.extendRole = function (grants, roles, extenderRoles, condition) { | ||
conditions_1.ConditionUtil.validateCondition(condition); | ||
CommonUtil.extendRoleSync(grants, roles, extenderRoles, condition); | ||
}; | ||
CommonUtil.extendRoleSync = function (grants, roles, extenderRoles, condition) { | ||
conditions_1.ConditionUtil.validateCondition(condition); | ||
var arrExtRoles = array_1.ArrayUtil.toStringArray(extenderRoles); | ||
@@ -716,0 +720,0 @@ if (!arrExtRoles) |
{ | ||
"name": "role-acl", | ||
"version": "4.5.3", | ||
"version": "4.5.4", | ||
"description": "Role, Attribute and Condition based Access Control for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
Sorry, the diff of this file is too big to display
337480
0.76%6749
0.87%