From 821d163ea304749e0e925b473900d652fd1cb21a Mon Sep 17 00:00:00 2001 From: akumar Date: Tue, 10 Oct 2023 11:16:59 +0200 Subject: [PATCH] fix: fix filter and update logger --- src/core/accessController.ts | 17 +++++++++-------- src/resourceManager.ts | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/accessController.ts b/src/core/accessController.ts index e0dc5c0..cc2bb62 100644 --- a/src/core/accessController.ts +++ b/src/core/accessController.ts @@ -168,7 +168,6 @@ export class AccessController { if (rules.size == 0 && !!policy.effect) { policyEffects.push({ effect: policy.effect, evaluation_cacheable: policy.evaluation_cacheable }); } - else { let evaluationCacheableRule = true; for (let [, rule] of policy.combinables) { @@ -216,10 +215,9 @@ export class AccessController { } request.context = context || request.context; - console.log('Validating the Condition.......', rule.condition); - console.log('Req Target resources are...', JSON.stringify(request.target.resources)); + this.logger.debug('Validating rule condition', { name: rule.name, condition: rule.condition }); matches = conditionMatches(rule.condition, request); - console.log('Matches result is..', matches); + this.logger.debug('condition validation response', { matches }); } } catch (err) { this.logger.error('Caught an exception while applying rule condition to request', { code: err.code, message: err.message, stack: err.stack }); @@ -628,13 +626,16 @@ export class AccessController { operation: AccessControlOperation = 'isAllowed', maskPropertyList: Attribute[], effect: Effect = Effect.PERMIT, regexMatch?: boolean): Promise { const requestTarget = request.target; + const resourceMatch = this.resourceAttributesMatch(ruleTarget.resources, + requestTarget.resources, operation, maskPropertyList, effect, regexMatch); + if (!resourceMatch) { + return false; + } const subMatch = await this.checkSubjectMatches(ruleTarget.subjects, requestTarget.subjects, request); - const match = subMatch && this.attributesMatch(ruleTarget.actions, requestTarget.actions); - if (!match) { + if(!subMatch) { return false; } - return this.resourceAttributesMatch(ruleTarget.resources, - requestTarget.resources, operation, maskPropertyList, effect, regexMatch); + return subMatch && this.attributesMatch(ruleTarget.actions, requestTarget.actions); } /** diff --git a/src/resourceManager.ts b/src/resourceManager.ts index 53da01f..4f4a667 100644 --- a/src/resourceManager.ts +++ b/src/resourceManager.ts @@ -60,7 +60,7 @@ const marshallResource = (resource: any, resourceName: string): any => { const makeFilter = (ids: string[]): any => { return [{ - filter: [{ + filters: [{ field: 'id', operation: FilterOperation.in, value: ids