Skip to content

Commit

Permalink
fix: optimize redis lookup for HR scopes in beginning of isAllowed an…
Browse files Browse the repository at this point in the history
…d whatIsAllowed
  • Loading branch information
Arun-KumarH committed Jul 2, 2024
1 parent 5329b5f commit 010f5f8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/core/accessController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export class AccessController {
context.subject.role_associations = subject.payload.role_associations;
}
}

// check if context subject_id contains HR scope if not make request 'createHierarchicalScopes'
if (context?.subject?.token &&
_.isEmpty(context.subject.hierarchical_scopes)) {
context = await this.createHRScope(context);
}

for (let [, value] of this.policySets) {
const policySet: PolicySetWithCombinables = value;
let policyEffects: EffectEvaluation[] = [];
Expand Down Expand Up @@ -327,6 +334,11 @@ export class AccessController {
context.subject.role_associations = subject.payload.role_associations;
}
}
// check if context subject_id contains HR scope if not make request 'createHierarchicalScopes'
if (context?.subject?.token &&
_.isEmpty(context.subject.hierarchical_scopes)) {
context = await this.createHRScope(context);
}
let obligations: Attribute[] = [];
for (let [, value] of this.policySets) {
let pSet: PolicySetRQ;
Expand Down Expand Up @@ -779,11 +791,6 @@ export class AccessController {
private async checkSubjectMatches(ruleSubAttributes: Attribute[],
requestSubAttributes: Attribute[], request: Request): Promise<boolean> {
let context = (request as any)?.context as ContextWithSubResolved;
// check if context subject_id contains HR scope if not make request 'createHierarchicalScopes'
if (context?.subject?.token &&
_.isEmpty(context.subject.hierarchical_scopes)) {
context = await this.createHRScope(context);
}
// Just check the Role value matches here in subject
const roleURN = this.urns.get('role');
let ruleRole: string;
Expand Down

0 comments on commit 010f5f8

Please sign in to comment.