Skip to content

Commit

Permalink
Merge pull request #684 from magieno/added-explicit-logging-of-denied…
Browse files Browse the repository at this point in the history
…-decision

- Update.
  • Loading branch information
etiennenoel authored Mar 15, 2024
2 parents 5a01071 + 95cf387 commit 465c97d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/security/src/managers/permission.manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {injectable, injectAll, inject} from "tsyringe";
import {inject, injectable, injectAll} from "tsyringe";
import {VoterInterface} from "../interfaces/voter.interface";
import {VotingStrategyEnum} from "../enums/voting-strategy.enum";
import {LogHandler, LogHandlerInterface} from "@pristine-ts/logging";
import {LogHandlerInterface} from "@pristine-ts/logging";
import {VoteEnum} from "../enums/vote.enum";
import {IdentityInterface, ServiceDefinitionTagEnum} from "@pristine-ts/common";
import {SecurityModuleKeyname} from "../security.module.keyname";
Expand Down Expand Up @@ -49,7 +49,15 @@ export class PermissionManager {

try {
const vote = await voter.vote(identity, action, resource);
this.logHandler.debug("PERMISSION MANAGER - [" + voter.constructor.name + "] - Decision: " + vote, {identity, action, resource, voter: voter.constructor.name}, SecurityModuleKeyname );

const message = "PERMISSION MANAGER - [" + voter.constructor.name + "] - Decision: " + vote;

if(vote === VoteEnum.Deny) { // When it's being denied, it usually mean that something is important to be noticed.
this.logHandler.info(message, {identity, action, resource, voter: voter.constructor.name}, SecurityModuleKeyname)
}
else {
this.logHandler.debug("PERMISSION MANAGER - [" + voter.constructor.name + "] - Decision: " + vote, {identity, action, resource, voter: voter.constructor.name}, SecurityModuleKeyname );
}

votes.push(vote);
} catch (error) {
Expand Down

0 comments on commit 465c97d

Please sign in to comment.