Skip to content

Commit 010f5f8

Browse files
committed
fix: optimize redis lookup for HR scopes in beginning of isAllowed and whatIsAllowed
1 parent 5329b5f commit 010f5f8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/core/accessController.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ export class AccessController {
114114
context.subject.role_associations = subject.payload.role_associations;
115115
}
116116
}
117+
118+
// check if context subject_id contains HR scope if not make request 'createHierarchicalScopes'
119+
if (context?.subject?.token &&
120+
_.isEmpty(context.subject.hierarchical_scopes)) {
121+
context = await this.createHRScope(context);
122+
}
123+
117124
for (let [, value] of this.policySets) {
118125
const policySet: PolicySetWithCombinables = value;
119126
let policyEffects: EffectEvaluation[] = [];
@@ -327,6 +334,11 @@ export class AccessController {
327334
context.subject.role_associations = subject.payload.role_associations;
328335
}
329336
}
337+
// check if context subject_id contains HR scope if not make request 'createHierarchicalScopes'
338+
if (context?.subject?.token &&
339+
_.isEmpty(context.subject.hierarchical_scopes)) {
340+
context = await this.createHRScope(context);
341+
}
330342
let obligations: Attribute[] = [];
331343
for (let [, value] of this.policySets) {
332344
let pSet: PolicySetRQ;
@@ -779,11 +791,6 @@ export class AccessController {
779791
private async checkSubjectMatches(ruleSubAttributes: Attribute[],
780792
requestSubAttributes: Attribute[], request: Request): Promise<boolean> {
781793
let context = (request as any)?.context as ContextWithSubResolved;
782-
// check if context subject_id contains HR scope if not make request 'createHierarchicalScopes'
783-
if (context?.subject?.token &&
784-
_.isEmpty(context.subject.hierarchical_scopes)) {
785-
context = await this.createHRScope(context);
786-
}
787794
// Just check the Role value matches here in subject
788795
const roleURN = this.urns.get('role');
789796
let ruleRole: string;

0 commit comments

Comments
 (0)