@pristine-ts/security 0.0.254 → 0.0.255
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -23,6 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.RoleGuard = void 0;
|
|
25
25
|
const tsyringe_1 = require("tsyringe");
|
|
26
|
+
const security_module_keyname_1 = require("../security.module.keyname");
|
|
26
27
|
/**
|
|
27
28
|
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
28
29
|
*/
|
|
@@ -31,8 +32,9 @@ let RoleGuard = class RoleGuard {
|
|
|
31
32
|
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
32
33
|
* @param rolesClaimKey The key in the claims of the access token where the roles are defined.
|
|
33
34
|
*/
|
|
34
|
-
constructor(rolesClaimKey) {
|
|
35
|
+
constructor(rolesClaimKey, logHandler) {
|
|
35
36
|
this.rolesClaimKey = rolesClaimKey;
|
|
37
|
+
this.logHandler = logHandler;
|
|
36
38
|
/**
|
|
37
39
|
* The keyname of the guard.
|
|
38
40
|
*/
|
|
@@ -43,8 +45,11 @@ let RoleGuard = class RoleGuard {
|
|
|
43
45
|
* @param context The context for the guard to use.
|
|
44
46
|
*/
|
|
45
47
|
setContext(context) {
|
|
46
|
-
this
|
|
47
|
-
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
this.guardContext = context;
|
|
50
|
+
this.logHandler.debug("Setting the context", { context }, security_module_keyname_1.SecurityModuleKeyname);
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
});
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
55
|
* Returns whether or not the guard authorizes the request.
|
|
@@ -67,11 +72,13 @@ let RoleGuard = class RoleGuard {
|
|
|
67
72
|
}
|
|
68
73
|
// If the identity does not have a roles claim, we deny.
|
|
69
74
|
if (neededRoles.length > 0 && (((_a = identity === null || identity === void 0 ? void 0 : identity.claims) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(this.rolesClaimKey)) === false || !Array.isArray(identity === null || identity === void 0 ? void 0 : identity.claims[this.rolesClaimKey]))) {
|
|
75
|
+
this.logHandler.debug("Identity doesn't have a roles claim. Denying.", { request, identity, neededRoles }, security_module_keyname_1.SecurityModuleKeyname);
|
|
70
76
|
return false;
|
|
71
77
|
}
|
|
72
78
|
// If the identity is missing one of the needed roles, we deny.
|
|
73
79
|
for (const role of neededRoles) {
|
|
74
80
|
if (!(identity === null || identity === void 0 ? void 0 : identity.claims[this.rolesClaimKey].includes(role))) {
|
|
81
|
+
this.logHandler.debug("Role not found in claims. Denying.", { request, identity, neededRoles, role }, security_module_keyname_1.SecurityModuleKeyname);
|
|
75
82
|
return false;
|
|
76
83
|
}
|
|
77
84
|
}
|
|
@@ -83,7 +90,8 @@ let RoleGuard = class RoleGuard {
|
|
|
83
90
|
RoleGuard = __decorate([
|
|
84
91
|
(0, tsyringe_1.injectable)(),
|
|
85
92
|
__param(0, (0, tsyringe_1.inject)("%pristine.security.rolesClaimKey%")),
|
|
86
|
-
|
|
93
|
+
__param(1, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
94
|
+
__metadata("design:paramtypes", [String, Object])
|
|
87
95
|
], RoleGuard);
|
|
88
96
|
exports.RoleGuard = RoleGuard;
|
|
89
97
|
//# sourceMappingURL=role.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.guard.js","sourceRoot":"","sources":["../../../../src/guards/role.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA4C;AAM5C;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IAWlB;;;OAGG;IACH,YAA0E,aAAqB;
|
|
1
|
+
{"version":3,"file":"role.guard.js","sourceRoot":"","sources":["../../../../src/guards/role.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;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,uBAAR,QAAQ,CAAE,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAC;gBAClJ,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,+CAA+C,EAAE,EAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAC,EAAE,+CAAqB,CAAC,CAAC;gBAChI,OAAO,KAAK,CAAC;aAChB;YAED,+DAA+D;YAC/D,KAAI,MAAM,IAAI,IAAI,WAAW,EAAE;gBAC3B,IAAG,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA,EAAC;oBACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,oCAAoC,EAAE,EAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAC,EAAE,+CAAqB,CAAC,CAAC;oBAC3H,OAAO,KAAK,CAAC;iBAChB;aACJ;YAED,4DAA4D;YAC5D,OAAO,IAAI,CAAC;;KACf;CACJ,CAAA;AApEY,SAAS;IADrB,IAAA,qBAAU,GAAE;IAgBI,WAAA,IAAA,iBAAM,EAAC,mCAAmC,CAAC,CAAA;IAC3C,WAAA,IAAA,iBAAM,EAAC,qBAAqB,CAAC,CAAA;;GAhBjC,SAAS,CAoErB;AApEY,8BAAS"}
|
|
@@ -20,6 +20,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
import { inject, injectable } from "tsyringe";
|
|
23
|
+
import { SecurityModuleKeyname } from "../security.module.keyname";
|
|
23
24
|
/**
|
|
24
25
|
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
25
26
|
*/
|
|
@@ -28,8 +29,9 @@ let RoleGuard = class RoleGuard {
|
|
|
28
29
|
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
29
30
|
* @param rolesClaimKey The key in the claims of the access token where the roles are defined.
|
|
30
31
|
*/
|
|
31
|
-
constructor(rolesClaimKey) {
|
|
32
|
+
constructor(rolesClaimKey, logHandler) {
|
|
32
33
|
this.rolesClaimKey = rolesClaimKey;
|
|
34
|
+
this.logHandler = logHandler;
|
|
33
35
|
/**
|
|
34
36
|
* The keyname of the guard.
|
|
35
37
|
*/
|
|
@@ -40,8 +42,11 @@ let RoleGuard = class RoleGuard {
|
|
|
40
42
|
* @param context The context for the guard to use.
|
|
41
43
|
*/
|
|
42
44
|
setContext(context) {
|
|
43
|
-
this
|
|
44
|
-
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
this.guardContext = context;
|
|
47
|
+
this.logHandler.debug("Setting the context", { context }, SecurityModuleKeyname);
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
});
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
47
52
|
* Returns whether or not the guard authorizes the request.
|
|
@@ -64,11 +69,13 @@ let RoleGuard = class RoleGuard {
|
|
|
64
69
|
}
|
|
65
70
|
// If the identity does not have a roles claim, we deny.
|
|
66
71
|
if (neededRoles.length > 0 && (((_a = identity === null || identity === void 0 ? void 0 : identity.claims) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(this.rolesClaimKey)) === false || !Array.isArray(identity === null || identity === void 0 ? void 0 : identity.claims[this.rolesClaimKey]))) {
|
|
72
|
+
this.logHandler.debug("Identity doesn't have a roles claim. Denying.", { request, identity, neededRoles }, SecurityModuleKeyname);
|
|
67
73
|
return false;
|
|
68
74
|
}
|
|
69
75
|
// If the identity is missing one of the needed roles, we deny.
|
|
70
76
|
for (const role of neededRoles) {
|
|
71
77
|
if (!(identity === null || identity === void 0 ? void 0 : identity.claims[this.rolesClaimKey].includes(role))) {
|
|
78
|
+
this.logHandler.debug("Role not found in claims. Denying.", { request, identity, neededRoles, role }, SecurityModuleKeyname);
|
|
72
79
|
return false;
|
|
73
80
|
}
|
|
74
81
|
}
|
|
@@ -80,7 +87,8 @@ let RoleGuard = class RoleGuard {
|
|
|
80
87
|
RoleGuard = __decorate([
|
|
81
88
|
injectable(),
|
|
82
89
|
__param(0, inject("%pristine.security.rolesClaimKey%")),
|
|
83
|
-
|
|
90
|
+
__param(1, inject("LogHandlerInterface")),
|
|
91
|
+
__metadata("design:paramtypes", [String, Object])
|
|
84
92
|
], RoleGuard);
|
|
85
93
|
export { RoleGuard };
|
|
86
94
|
//# sourceMappingURL=role.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.guard.js","sourceRoot":"","sources":["../../../../src/guards/role.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAM5C;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IAWlB;;;OAGG;IACH,YAA0E,aAAqB;
|
|
1
|
+
{"version":3,"file":"role.guard.js","sourceRoot":"","sources":["../../../../src/guards/role.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAM5C,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAEjE;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IAWlB;;;OAGG;IACH,YAA0E,aAAqB,EACnC,UAA+B;QADjB,kBAAa,GAAb,aAAa,CAAQ;QACnC,eAAU,GAAV,UAAU,CAAqB;QAf3F;;WAEG;QACI,YAAO,GAAG,MAAM,CAAC;IAaxB,CAAC;IAED;;;OAGG;IACG,UAAU,CAAC,OAAY;;YACzB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;YAE5B,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAC,OAAO,EAAC,EAAE,qBAAqB,CAAC,CAAC;YAE/E,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC;K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AAO,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAC,EAAE,qBAAqB,CAAC,CAAC;oBAC3H,OAAO,KAAK,CAAC;iBAChB;aACJ;YAED,4DAA4D;YAC5D,OAAO,IAAI,CAAC;;KACf;CACJ,CAAA;AApEY,SAAS;IADrB,UAAU,EAAE;IAgBI,WAAA,MAAM,CAAC,mCAAmC,CAAC,CAAA;IAC3C,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;;GAhBjC,SAAS,CAoErB;SApEY,SAAS"}
|
|
@@ -2,11 +2,13 @@ import { IdentityInterface } from "@pristine-ts/common";
|
|
|
2
2
|
import { GuardInterface } from "../interfaces/guard.interface";
|
|
3
3
|
import { GuardContextInterface } from "../interfaces/guard-context.interface";
|
|
4
4
|
import { Request } from "@pristine-ts/common";
|
|
5
|
+
import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
5
6
|
/**
|
|
6
7
|
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
7
8
|
*/
|
|
8
9
|
export declare class RoleGuard implements GuardInterface {
|
|
9
10
|
private readonly rolesClaimKey;
|
|
11
|
+
private readonly logHandler;
|
|
10
12
|
/**
|
|
11
13
|
* The keyname of the guard.
|
|
12
14
|
*/
|
|
@@ -19,7 +21,7 @@ export declare class RoleGuard implements GuardInterface {
|
|
|
19
21
|
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
20
22
|
* @param rolesClaimKey The key in the claims of the access token where the roles are defined.
|
|
21
23
|
*/
|
|
22
|
-
constructor(rolesClaimKey: string);
|
|
24
|
+
constructor(rolesClaimKey: string, logHandler: LogHandlerInterface);
|
|
23
25
|
/**
|
|
24
26
|
* Sets the context for the guard.
|
|
25
27
|
* @param context The context for the guard to use.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/security",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.255",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/security.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/security.module.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@pristine-ts/common": "^0.0.
|
|
24
|
-
"@pristine-ts/logging": "^0.0.
|
|
23
|
+
"@pristine-ts/common": "^0.0.255",
|
|
24
|
+
"@pristine-ts/logging": "^0.0.255"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/jsonwebtoken": "^8.5.0"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"src/*.{js,ts}"
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "59a63101c85db253fef32ddde00cb372699e1bb2"
|
|
64
64
|
}
|