@pristine-ts/security 0.0.188 → 0.0.192
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.
- package/dist/lib/cjs/decorators/authenticator.decorator.js +6 -0
- package/dist/lib/cjs/decorators/authenticator.decorator.js.map +1 -1
- package/dist/lib/cjs/decorators/guard.decorator.js +6 -0
- package/dist/lib/cjs/decorators/guard.decorator.js.map +1 -1
- package/dist/lib/cjs/enums/resource-action.enum.js +5 -0
- package/dist/lib/cjs/enums/resource-action.enum.js.map +1 -1
- package/dist/lib/cjs/enums/vote.enum.js +3 -0
- package/dist/lib/cjs/enums/vote.enum.js.map +1 -1
- package/dist/lib/cjs/enums/voting-strategy.enum.js +10 -0
- package/dist/lib/cjs/enums/voting-strategy.enum.js.map +1 -1
- package/dist/lib/cjs/errors/authenticator-decorator.error.js +2 -2
- package/dist/lib/cjs/errors/authenticator-decorator.error.js.map +1 -1
- package/dist/lib/cjs/errors/authenticator-instantiation.error.js +1 -1
- package/dist/lib/cjs/errors/authenticator-instantiation.error.js.map +1 -1
- package/dist/lib/cjs/errors/errors.js +1 -0
- package/dist/lib/cjs/errors/errors.js.map +1 -1
- package/dist/lib/cjs/errors/guard-decorator.error.js +1 -1
- package/dist/lib/cjs/errors/guard-decorator.error.js.map +1 -1
- package/dist/lib/cjs/errors/guard-instantiation.error.js +1 -1
- package/dist/lib/cjs/errors/guard-instantiation.error.js.map +1 -1
- package/dist/lib/cjs/factories/authenticator.factory.js +11 -0
- package/dist/lib/cjs/factories/authenticator.factory.js.map +1 -1
- package/dist/lib/cjs/factories/guard.factory.js +11 -0
- package/dist/lib/cjs/factories/guard.factory.js.map +1 -1
- package/dist/lib/cjs/guards/role.guard.js +26 -0
- package/dist/lib/cjs/guards/role.guard.js.map +1 -1
- package/dist/lib/cjs/interfaces/interfaces.js +2 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
- package/dist/lib/cjs/managers/authentication.manager.js +16 -1
- package/dist/lib/cjs/managers/authentication.manager.js.map +1 -1
- package/dist/lib/cjs/managers/authorizer.manager.js +16 -0
- package/dist/lib/cjs/managers/authorizer.manager.js.map +1 -1
- package/dist/lib/cjs/managers/managers.js +1 -1
- package/dist/lib/cjs/managers/managers.js.map +1 -1
- package/dist/lib/cjs/managers/permission.manager.js +16 -0
- package/dist/lib/cjs/managers/permission.manager.js.map +1 -1
- package/dist/lib/cjs/providers/default-identity.provider.js +2 -0
- package/dist/lib/cjs/providers/default-identity.provider.js.map +1 -1
- package/dist/lib/cjs/security.module.js +3 -0
- package/dist/lib/cjs/security.module.js.map +1 -1
- package/dist/lib/esm/decorators/authenticator.decorator.js +6 -0
- package/dist/lib/esm/decorators/authenticator.decorator.js.map +1 -1
- package/dist/lib/esm/decorators/guard.decorator.js +6 -0
- package/dist/lib/esm/decorators/guard.decorator.js.map +1 -1
- package/dist/lib/esm/enums/resource-action.enum.js +5 -0
- package/dist/lib/esm/enums/resource-action.enum.js.map +1 -1
- package/dist/lib/esm/enums/vote.enum.js +3 -0
- package/dist/lib/esm/enums/vote.enum.js.map +1 -1
- package/dist/lib/esm/enums/voting-strategy.enum.js +10 -0
- package/dist/lib/esm/enums/voting-strategy.enum.js.map +1 -1
- package/dist/lib/esm/errors/authenticator-decorator.error.js +2 -2
- package/dist/lib/esm/errors/authenticator-decorator.error.js.map +1 -1
- package/dist/lib/esm/errors/authenticator-instantiation.error.js +1 -1
- package/dist/lib/esm/errors/authenticator-instantiation.error.js.map +1 -1
- package/dist/lib/esm/errors/errors.js +1 -0
- package/dist/lib/esm/errors/errors.js.map +1 -1
- package/dist/lib/esm/errors/guard-decorator.error.js +1 -1
- package/dist/lib/esm/errors/guard-decorator.error.js.map +1 -1
- package/dist/lib/esm/errors/guard-instantiation.error.js +1 -1
- package/dist/lib/esm/errors/guard-instantiation.error.js.map +1 -1
- package/dist/lib/esm/factories/authenticator.factory.js +11 -0
- package/dist/lib/esm/factories/authenticator.factory.js.map +1 -1
- package/dist/lib/esm/factories/guard.factory.js +11 -0
- package/dist/lib/esm/factories/guard.factory.js.map +1 -1
- package/dist/lib/esm/guards/role.guard.js +26 -0
- package/dist/lib/esm/guards/role.guard.js.map +1 -1
- package/dist/lib/esm/interfaces/interfaces.js +2 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
- package/dist/lib/esm/managers/authentication.manager.js +16 -1
- package/dist/lib/esm/managers/authentication.manager.js.map +1 -1
- package/dist/lib/esm/managers/authorizer.manager.js +16 -0
- package/dist/lib/esm/managers/authorizer.manager.js.map +1 -1
- package/dist/lib/esm/managers/managers.js +1 -1
- package/dist/lib/esm/managers/managers.js.map +1 -1
- package/dist/lib/esm/managers/permission.manager.js +16 -0
- package/dist/lib/esm/managers/permission.manager.js.map +1 -1
- package/dist/lib/esm/providers/default-identity.provider.js +2 -0
- package/dist/lib/esm/providers/default-identity.provider.js.map +1 -1
- package/dist/lib/esm/security.module.js +3 -0
- package/dist/lib/esm/security.module.js.map +1 -1
- package/dist/types/decorators/authenticator.decorator.d.ts +6 -0
- package/dist/types/decorators/guard.decorator.d.ts +6 -0
- package/dist/types/enums/resource-action.enum.d.ts +5 -0
- package/dist/types/enums/vote.enum.d.ts +3 -0
- package/dist/types/enums/voting-strategy.enum.d.ts +10 -0
- package/dist/types/errors/authenticator-decorator.error.d.ts +3 -3
- package/dist/types/errors/authenticator-instantiation.error.d.ts +2 -2
- package/dist/types/errors/errors.d.ts +1 -0
- package/dist/types/errors/guard-decorator.error.d.ts +2 -2
- package/dist/types/errors/guard-instantiation.error.d.ts +2 -2
- package/dist/types/factories/authenticator.factory.d.ts +9 -0
- package/dist/types/factories/guard.factory.d.ts +9 -0
- package/dist/types/guards/role.guard.d.ts +24 -0
- package/dist/types/interfaces/authentication-manager.interface.d.ts +11 -0
- package/dist/types/interfaces/authenticator-context.interface.d.ts +12 -0
- package/dist/types/interfaces/authenticator.interface.d.ts +9 -0
- package/dist/types/interfaces/authorizer-manager.interface.d.ts +11 -0
- package/dist/types/interfaces/guard-context.interface.d.ts +13 -0
- package/dist/types/interfaces/guard.interface.d.ts +15 -0
- package/dist/types/interfaces/identity-provider.interface.d.ts +9 -0
- package/dist/types/interfaces/interfaces.d.ts +2 -0
- package/dist/types/interfaces/voter.interface.d.ts +14 -0
- package/dist/types/managers/authentication.manager.d.ts +16 -0
- package/dist/types/managers/authorizer.manager.d.ts +16 -0
- package/dist/types/managers/managers.d.ts +1 -1
- package/dist/types/managers/permission.manager.d.ts +16 -0
- package/dist/types/providers/default-identity.provider.d.ts +2 -0
- package/package.json +6 -5
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resource action enum specifies the most common actions that can be taken on a resource.
|
|
3
|
+
* It's used in the voters to validate if a user is authorized to execute that action.
|
|
4
|
+
* More actions can be defined in more specified enum based on the resource type.
|
|
5
|
+
*/
|
|
1
6
|
export var ResourceActionEnum;
|
|
2
7
|
(function (ResourceActionEnum) {
|
|
3
8
|
ResourceActionEnum["List"] = "LIST";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-action.enum.js","sourceRoot":"","sources":["../../../../src/enums/resource-action.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,mCAAa,CAAA;IACb,mCAAa,CAAA;IACb,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;AACrB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B"}
|
|
1
|
+
{"version":3,"file":"resource-action.enum.js","sourceRoot":"","sources":["../../../../src/enums/resource-action.enum.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,mCAAa,CAAA;IACb,mCAAa,CAAA;IACb,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;AACrB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vote.enum.js","sourceRoot":"","sources":["../../../../src/enums/vote.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,+BAAmB,CAAA;AACvB,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB"}
|
|
1
|
+
{"version":3,"file":"vote.enum.js","sourceRoot":"","sources":["../../../../src/enums/vote.enum.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,+BAAmB,CAAA;AACvB,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB"}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The voting strategy enum defines the different strategies that the permission manager uses to
|
|
3
|
+
* merge the results of all the voter.
|
|
4
|
+
*/
|
|
1
5
|
export var VotingStrategyEnum;
|
|
2
6
|
(function (VotingStrategyEnum) {
|
|
7
|
+
/**
|
|
8
|
+
* When all the voters abstain from voting, the access is granted.
|
|
9
|
+
*/
|
|
3
10
|
VotingStrategyEnum["GrantOnUnanimousAbstention"] = "GRANT_ON_UNANIMOUS_ABSTENTION";
|
|
11
|
+
/**
|
|
12
|
+
* When all the voters abstain from voting, the access is denied.
|
|
13
|
+
*/
|
|
4
14
|
VotingStrategyEnum["DenyOnUnanimousAbstention"] = "DENY_ON_UNANIMOUS_ABSTENTION";
|
|
5
15
|
})(VotingStrategyEnum || (VotingStrategyEnum = {}));
|
|
6
16
|
//# sourceMappingURL=voting-strategy.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voting-strategy.enum.js","sourceRoot":"","sources":["../../../../src/enums/voting-strategy.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"voting-strategy.enum.js","sourceRoot":"","sources":["../../../../src/enums/voting-strategy.enum.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAN,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC1B;;OAEG;IACH,kFAA4D,CAAA;IAE5D;;OAEG;IACH,gFAA0D,CAAA;AAC9D,CAAC,EAVW,kBAAkB,KAAlB,kBAAkB,QAU7B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
1
2
|
/**
|
|
2
|
-
* This Error is thrown when there's an error
|
|
3
|
+
* This Error is thrown when there's an error with the authenticator decorator.
|
|
3
4
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
5
|
export class AuthenticatorDecoratorError extends LoggableError {
|
|
6
6
|
constructor(message, authenticator, options, target, propertyKey, descriptor) {
|
|
7
7
|
super(message, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticator-decorator.error.js","sourceRoot":"","sources":["../../../../src/errors/authenticator-decorator.error.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"authenticator-decorator.error.js","sourceRoot":"","sources":["../../../../src/errors/authenticator-decorator.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,aAAa;IAE1D,YAAmB,OAAe,EAAE,aAAgD,EAAE,OAAY,EAAE,MAAW,EAC5F,WAAoB,EACpB,UAA+B;QAC9C,KAAK,CAAC,OAAO,EAAE;YACX,OAAO;YACP,aAAa;YACb,OAAO;YACP,MAAM;YACN,WAAW;YACX,UAAU;SACb,CAAC,CAAC;QAEH,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACvE,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
1
2
|
/**
|
|
2
3
|
* This Error is thrown when there's an error that happens when the authenticator are being initialized
|
|
3
4
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
5
|
export class AuthenticatorInstantiationError extends LoggableError {
|
|
6
6
|
constructor(message, instantiatedAuthenticator, authenticatorContext) {
|
|
7
7
|
super(message, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticator-instantiation.error.js","sourceRoot":"","sources":["../../../../src/errors/authenticator-instantiation.error.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"authenticator-instantiation.error.js","sourceRoot":"","sources":["../../../../src/errors/authenticator-instantiation.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,+BAAgC,SAAQ,aAAa;IAG9D,YAAmB,OAAe,EAAE,yBAA4D,EAAE,oBAAyB;QACvH,KAAK,CAAC,OAAO,EAAE;YACX,yBAAyB;YACzB,oBAAoB;SACvB,CAAC,CAAC;QAEH,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,+BAA+B,CAAC,SAAS,CAAC,CAAC;IAC3E,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
1
2
|
/**
|
|
2
3
|
* This Error is thrown when there's an error that happens when the guards ere being initialized
|
|
3
4
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
5
|
export class GuardDecoratorError extends LoggableError {
|
|
6
6
|
constructor(message, guard, options, target, propertyKey, descriptor) {
|
|
7
7
|
super(message, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard-decorator.error.js","sourceRoot":"","sources":["../../../../src/errors/guard-decorator.error.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"guard-decorator.error.js","sourceRoot":"","sources":["../../../../src/errors/guard-decorator.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IAElD,YAAmB,OAAe,EAAE,KAAgC,EAAE,OAAY,EAAE,MAAW,EAC5E,WAAoB,EACpB,UAA+B;QAC9C,KAAK,CAAC,OAAO,EAAE;YACX,OAAO;YACP,KAAK;YACL,OAAO;YACP,MAAM;YACN,WAAW;YACX,UAAU;SACb,CAAC,CAAC;QAEH,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC/D,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
1
2
|
/**
|
|
2
3
|
* This Error is thrown when there's an error that happens when the guards ere being initialized
|
|
3
4
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
5
|
export class GuardInstantiationError extends LoggableError {
|
|
6
6
|
constructor(message, instantiatedGuard, guardContext) {
|
|
7
7
|
super(message, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard-instantiation.error.js","sourceRoot":"","sources":["../../../../src/errors/guard-instantiation.error.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"guard-instantiation.error.js","sourceRoot":"","sources":["../../../../src/errors/guard-instantiation.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,aAAa;IACtD,YAAmB,OAAe,EAAE,iBAA4C,EAAE,YAAiB;QAC/F,KAAK,CAAC,OAAO,EAAE;YACX,iBAAiB;YACjB,YAAY;SACf,CAAC,CAAC;QAEH,gCAAgC;QAChC,kDAAkD;QAClD,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC;CACJ"}
|
|
@@ -6,10 +6,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { injectable } from "tsyringe";
|
|
8
8
|
import { AuthenticatorInstantiationError } from "../errors/authenticator-instantiation.error";
|
|
9
|
+
/**
|
|
10
|
+
* The AuthenticatorFactory returns the proper instantiated authenticator.
|
|
11
|
+
*/
|
|
9
12
|
let AuthenticatorFactory = class AuthenticatorFactory {
|
|
13
|
+
/**
|
|
14
|
+
* This function takes the authenticator context and returns the proper instantiated authenticator.
|
|
15
|
+
* It also validates that the authenticator is valid (it implements the AuthenticatorInterface).
|
|
16
|
+
* @param authenticatorContext The authenticator context that holds the authenticator and options to use.
|
|
17
|
+
* @param container The dependency container from which to retrieve the instantiated authenticator.
|
|
18
|
+
*/
|
|
10
19
|
fromContext(authenticatorContext, container) {
|
|
11
20
|
// Check if the guard needs to be instantiated
|
|
12
21
|
let instantiatedAuthenticator = authenticatorContext.authenticator;
|
|
22
|
+
// If authenticatorContext.authenticator is a function, we resolve that function through the container.
|
|
23
|
+
// TODO: validate if this is good.
|
|
13
24
|
if (typeof instantiatedAuthenticator === 'function') {
|
|
14
25
|
instantiatedAuthenticator = container.resolve(instantiatedAuthenticator);
|
|
15
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticator.factory.js","sourceRoot":"","sources":["../../../../src/factories/authenticator.factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAsB,UAAU,EAAC,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAC,+BAA+B,EAAC,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"authenticator.factory.js","sourceRoot":"","sources":["../../../../src/factories/authenticator.factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAsB,UAAU,EAAC,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAC,+BAA+B,EAAC,MAAM,6CAA6C,CAAC;AAE5F;;GAEG;AAEH,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAE7B;;;;;OAKG;IACH,WAAW,CAAC,oBAAmD,EAAE,SAA8B;QAC3F,8CAA8C;QAC9C,IAAI,yBAAyB,GAA2B,oBAAoB,CAAC,aAAuC,CAAC;QAErH,uGAAuG;QACvG,kCAAkC;QAClC,IAAI,OAAO,yBAAyB,KAAK,UAAU,EAAE;YACjD,yBAAyB,GAAG,SAAS,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;SAC5E;QAED,uDAAuD;QACvD,IAAI,OAAO,yBAAyB,CAAC,YAAY,KAAK,UAAU,EAAE;YAC9D,MAAM,IAAI,+BAA+B,CAAC,oGAAoG,EAAE,yBAAyB,EAAE,oBAAoB,CAAC,CAAC;SACpM;QAED,qDAAqD;QACrD,IAAI,OAAO,yBAAyB,CAAC,UAAU,KAAK,UAAU,EAAE;YAC5D,MAAM,IAAI,+BAA+B,CAAC,kGAAkG,EAAE,yBAAyB,EAAE,oBAAoB,CAAC,CAAC;SAClM;QAED,OAAO,yBAAyB,CAAC;IACrC,CAAC;CACJ,CAAA;AA9BY,oBAAoB;IADhC,UAAU,EAAE;GACA,oBAAoB,CA8BhC;SA9BY,oBAAoB"}
|
|
@@ -6,10 +6,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { injectable } from "tsyringe";
|
|
8
8
|
import { GuardInstantiationError } from "../errors/guard-instantiation.error";
|
|
9
|
+
/**
|
|
10
|
+
* The GuardFactory returns the proper instantiated guard.
|
|
11
|
+
*/
|
|
9
12
|
let GuardFactory = class GuardFactory {
|
|
13
|
+
/**
|
|
14
|
+
* This function takes the guard context and returns the proper instantiated guard.
|
|
15
|
+
* It also validates that the guard is valid (it implements the GuardInterface).
|
|
16
|
+
* @param guardContext The guard context that contains the guard and the options to use.
|
|
17
|
+
* @param container The dependency container from which to retrieve the instantiated guard.
|
|
18
|
+
*/
|
|
10
19
|
fromContext(guardContext, container) {
|
|
11
20
|
// Check if the guard needs to be instantiated
|
|
12
21
|
let instantiatedGuard = guardContext.guard;
|
|
22
|
+
// If guardContext.guard is a function, we resolve that function through the container.
|
|
23
|
+
// TODO: validate if this is good.
|
|
13
24
|
if (typeof instantiatedGuard === 'function') {
|
|
14
25
|
instantiatedGuard = container.resolve(instantiatedGuard);
|
|
15
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.factory.js","sourceRoot":"","sources":["../../../../src/factories/guard.factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAsB,UAAU,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"guard.factory.js","sourceRoot":"","sources":["../../../../src/factories/guard.factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAsB,UAAU,EAAC,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAE5E;;GAEG;AAEH,IAAa,YAAY,GAAzB,MAAa,YAAY;IAErB;;;;;OAKG;IACH,WAAW,CAAC,YAAmC,EAAE,SAA8B;QAC3E,8CAA8C;QAC9C,IAAI,iBAAiB,GAAmB,YAAY,CAAC,KAAuB,CAAC;QAE7E,wFAAwF;QACxF,kCAAkC;QAClC,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE;YACzC,iBAAiB,GAAG,SAAS,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;SAC5D;QAED,uDAAuD;QACvD,IAAI,OAAO,iBAAiB,CAAC,YAAY,KAAK,UAAU,EAAE;YACtD,MAAM,IAAI,uBAAuB,CAAC,wDAAwD,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;SAChI;QAED,qDAAqD;QACrD,IAAI,OAAO,iBAAiB,CAAC,UAAU,KAAK,UAAU,EAAE;YACpD,MAAM,IAAI,uBAAuB,CAAC,sDAAsD,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;SAC9H;QAED,OAAO,iBAAiB,CAAC;IAC7B,CAAC;CACJ,CAAA;AA9BY,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CA8BxB;SA9BY,YAAY"}
|
|
@@ -20,33 +20,59 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
import { inject, injectable } from "tsyringe";
|
|
23
|
+
/**
|
|
24
|
+
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
25
|
+
*/
|
|
23
26
|
let RoleGuard = class RoleGuard {
|
|
27
|
+
/**
|
|
28
|
+
* The role guard is a guard that validates if the identity making the request has the required roles.
|
|
29
|
+
* @param rolesClaimKey The key in the claims of the access token where the roles are defined.
|
|
30
|
+
*/
|
|
24
31
|
constructor(rolesClaimKey) {
|
|
25
32
|
this.rolesClaimKey = rolesClaimKey;
|
|
33
|
+
/**
|
|
34
|
+
* The keyname of the guard.
|
|
35
|
+
*/
|
|
26
36
|
this.keyname = "role";
|
|
27
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Sets the context for the guard.
|
|
40
|
+
* @param context The context for the guard to use.
|
|
41
|
+
*/
|
|
28
42
|
setContext(context) {
|
|
29
43
|
this.guardContext = context;
|
|
30
44
|
return Promise.resolve();
|
|
31
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns whether or not the guard authorizes the request.
|
|
48
|
+
* For the role guard, it validates that the identity making the request has the requested roles.
|
|
49
|
+
* The identity needs all of the requested roles to be authorized.
|
|
50
|
+
* @param request The request to authorize.
|
|
51
|
+
* @param identity The identity making the request.
|
|
52
|
+
*/
|
|
32
53
|
isAuthorized(request, identity) {
|
|
33
54
|
var _a;
|
|
34
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
56
|
const neededRoles = [];
|
|
57
|
+
// If we have no context we deny.
|
|
36
58
|
if (this.guardContext === undefined) {
|
|
37
59
|
return false;
|
|
38
60
|
}
|
|
61
|
+
// Find what roles are needed based on the context.
|
|
39
62
|
if (this.guardContext.options && this.guardContext.options.hasOwnProperty("roles") && Array.isArray(this.guardContext.options.roles)) {
|
|
40
63
|
neededRoles.push(...this.guardContext.options.roles);
|
|
41
64
|
}
|
|
65
|
+
// If the identity does not have a roles claim, we deny.
|
|
42
66
|
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]))) {
|
|
43
67
|
return false;
|
|
44
68
|
}
|
|
69
|
+
// If the identity is missing one of the needed roles, we deny.
|
|
45
70
|
for (const role of neededRoles) {
|
|
46
71
|
if (!(identity === null || identity === void 0 ? void 0 : identity.claims[this.rolesClaimKey].includes(role))) {
|
|
47
72
|
return false;
|
|
48
73
|
}
|
|
49
74
|
}
|
|
75
|
+
// If the identity has all the requested roles we authorize.
|
|
50
76
|
return true;
|
|
51
77
|
});
|
|
52
78
|
}
|
|
@@ -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;
|
|
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;AAEH,IAAa,SAAS,GAAtB,MAAa,SAAS;IAWlB;;;OAGG;IACH,YAA0E,aAAqB;QAArB,kBAAa,GAAb,aAAa,CAAQ;QAd/F;;WAEG;QACI,YAAO,GAAG,MAAM,CAAC;IAYxB,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,OAAY;QACnB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAE5B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACG,YAAY,CAAC,OAAgB,EAAE,QAA4B;;;YAC7D,MAAM,WAAW,GAAa,EAAE,CAAC;YAEjC,iCAAiC;YACjC,IAAG,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;gBAChC,OAAO,KAAK,CAAC;aAChB;YAED,mDAAmD;YACnD,IAAG,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC;gBAChI,WAAW,CAAC,IAAI,CAAC,GAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;aACzD;YAED,wDAAwD;YACxD,IAAG,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,0CAAE,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,MAAK,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAC;gBAClJ,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,OAAO,KAAK,CAAC;iBAChB;aACJ;YAED,4DAA4D;YAC5D,OAAO,IAAI,CAAC;;KACf;CACJ,CAAA;AA/DY,SAAS;IADrB,UAAU,EAAE;IAgBI,WAAA,MAAM,CAAC,mCAAmC,CAAC,CAAA;;GAf/C,SAAS,CA+DrB;SA/DY,SAAS"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./authentication-manager.interface";
|
|
2
2
|
export * from "./authenticator.interface";
|
|
3
|
+
export * from "./authenticator-context.interface";
|
|
3
4
|
export * from "./authorizer-manager.interface";
|
|
4
5
|
export * from "./guard.interface";
|
|
5
6
|
export * from "./guard-context.interface";
|
|
7
|
+
export * from "./identity-provider.interface";
|
|
6
8
|
export * from "./voter.interface";
|
|
7
9
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC"}
|
|
@@ -23,12 +23,28 @@ import { inject, injectable, injectAll } from "tsyringe";
|
|
|
23
23
|
import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
|
|
24
24
|
import { AuthenticatorFactory } from "../factories/authenticator.factory";
|
|
25
25
|
import { SecurityModuleKeyname } from "../security.module.keyname";
|
|
26
|
+
/**
|
|
27
|
+
* The authentication manager provides authentication by returning the identity executing the action.
|
|
28
|
+
* It is tagged and can be injected using AuthenticationManagerInterface which facilitates mocking.
|
|
29
|
+
*/
|
|
26
30
|
let AuthenticationManager = class AuthenticationManager {
|
|
31
|
+
/**
|
|
32
|
+
* The authentication manager provides authentication by returning the identity executing the action.
|
|
33
|
+
* @param identityProviders The identity providers to use to provide the identity. All services tagged with ServiceDefinitionTagEnum.IdentityProvider will be injected here.
|
|
34
|
+
* @param logHandler The log handler to output logs.
|
|
35
|
+
* @param authenticatorFactory The factory to create the authenticator.
|
|
36
|
+
*/
|
|
27
37
|
constructor(identityProviders, logHandler, authenticatorFactory) {
|
|
28
38
|
this.identityProviders = identityProviders;
|
|
29
39
|
this.logHandler = logHandler;
|
|
30
40
|
this.authenticatorFactory = authenticatorFactory;
|
|
31
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Authenticates a request by providing the identity that made the request.
|
|
44
|
+
* @param request The request to authenticate
|
|
45
|
+
* @param routeContext The context associated with the route.
|
|
46
|
+
* @param container The dependency container from which to resolve the authenticator.
|
|
47
|
+
*/
|
|
32
48
|
authenticate(request, routeContext, container) {
|
|
33
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
50
|
if (!routeContext || routeContext.authenticator === undefined) {
|
|
@@ -50,7 +66,6 @@ let AuthenticationManager = class AuthenticationManager {
|
|
|
50
66
|
}
|
|
51
67
|
catch (e) {
|
|
52
68
|
this.logHandler.error(e.message, { e }, SecurityModuleKeyname);
|
|
53
|
-
identity = undefined;
|
|
54
69
|
throw e;
|
|
55
70
|
}
|
|
56
71
|
return identity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.manager.js","sourceRoot":"","sources":["../../../../src/managers/authentication.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAE5E,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAInG,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"authentication.manager.js","sourceRoot":"","sources":["../../../../src/managers/authentication.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAE5E,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAInG,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAIjE;;;GAGG;AAIH,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;IAE9B;;;;;OAKG;IACH,YAC2E,iBAA8C,EACrE,UAA+B,EAC/C,oBAA0C;QAFH,sBAAiB,GAAjB,iBAAiB,CAA6B;QACrE,eAAU,GAAV,UAAU,CAAq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AoDjC;SApDY,qBAAqB"}
|
|
@@ -23,11 +23,27 @@ import { inject, injectable } from "tsyringe";
|
|
|
23
23
|
import { moduleScoped, tag } from "@pristine-ts/common";
|
|
24
24
|
import { GuardFactory } from "../factories/guard.factory";
|
|
25
25
|
import { SecurityModuleKeyname } from "../security.module.keyname";
|
|
26
|
+
/**
|
|
27
|
+
* The authorizer manager provides authorization by authorizing the action.
|
|
28
|
+
* It is tagged and can be injected using AuthorizerManagerInterface which facilitates mocking.
|
|
29
|
+
*/
|
|
26
30
|
let AuthorizerManager = class AuthorizerManager {
|
|
31
|
+
/**
|
|
32
|
+
* The authorizer manager provides authorization by authorizing the action.
|
|
33
|
+
* @param logHandler The log handler to output logs.
|
|
34
|
+
* @param guardFactory The factory to create the guard.
|
|
35
|
+
*/
|
|
27
36
|
constructor(logHandler, guardFactory) {
|
|
28
37
|
this.logHandler = logHandler;
|
|
29
38
|
this.guardFactory = guardFactory;
|
|
30
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns whether or not the request is authorized to access the route.
|
|
42
|
+
* @param request The request to authorize.
|
|
43
|
+
* @param routeContext The route context.
|
|
44
|
+
* @param container The dependency container to resolve the guard from.
|
|
45
|
+
* @param identity The identity making the request.
|
|
46
|
+
*/
|
|
31
47
|
isAuthorized(request, routeContext, container, identity) {
|
|
32
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
49
|
// If there are no guards defined, we simply return that it is authorized.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorizer.manager.js","sourceRoot":"","sources":["../../../../src/managers/authorizer.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAsB,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAoB,YAAY,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAC,qBAAq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AAC,EAAE;oBACN,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;oBACxD,YAAY,GAAG,KAAK,CAAC;iBACxB;aACJ;YAED,OAAO,YAAY,CAAC;QACxB,CAAC;KAAA;CACJ,CAAA;AA3CY,iBAAiB;IAH7B,YAAY,CAAC,qBAAqB,CAAC;IACnC,GAAG,CAAC,4BAA4B,CAAC;IACjC,UAAU,EAAE;IAQW,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;6CACC,YAAY;GARrD,iBAAiB,CA2C7B;SA3CY,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"managers.js","sourceRoot":"","sources":["../../../../src/managers/managers.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"managers.js","sourceRoot":"","sources":["../../../../src/managers/managers.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC"}
|
|
@@ -24,11 +24,27 @@ import { VotingStrategyEnum } from "../enums/voting-strategy.enum";
|
|
|
24
24
|
import { VoteEnum } from "../enums/vote.enum";
|
|
25
25
|
import { ServiceDefinitionTagEnum } from "@pristine-ts/common";
|
|
26
26
|
import { SecurityModuleKeyname } from "../security.module.keyname";
|
|
27
|
+
/**
|
|
28
|
+
* The permission manager verifies if the correct permission are there to access and take an action on a resource.
|
|
29
|
+
*/
|
|
27
30
|
let PermissionManager = class PermissionManager {
|
|
31
|
+
/**
|
|
32
|
+
* The permission manager verifies if the correct permission are there to access and take an action on a resource.
|
|
33
|
+
* @param voters The voters that determine if access is granted.
|
|
34
|
+
* All services with the tag ServiceDefinitionTagEnum.Voter will be injected here
|
|
35
|
+
* @param logHandler The log handler to output logs.
|
|
36
|
+
*/
|
|
28
37
|
constructor(voters, logHandler) {
|
|
29
38
|
this.voters = voters;
|
|
30
39
|
this.logHandler = logHandler;
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns whether or not the permission manager grants access to the resource.
|
|
43
|
+
* @param identity The identity trying to have access to a resource.
|
|
44
|
+
* @param action The action trying to be executed on the resource.
|
|
45
|
+
* @param resource The resource being accessed.
|
|
46
|
+
* @param votingStrategy The voting strategy that defines how to merge the votes. Default is DenyOnUnanimousAbstention.
|
|
47
|
+
*/
|
|
32
48
|
hasAccessToResource(identity, action, resource, votingStrategy = VotingStrategyEnum.DenyOnUnanimousAbstention) {
|
|
33
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
50
|
if (this.voters.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.manager.js","sourceRoot":"","sources":["../../../../src/managers/permission.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAEvD,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAoB,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"permission.manager.js","sourceRoot":"","sources":["../../../../src/managers/permission.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAEvD,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAoB,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAEjE;;GAEG;A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9
|
import { injectable } from "tsyringe";
|
|
10
10
|
/**
|
|
11
|
+
* This default identity provider is here so that there is always at least one service tagged with IdentityProvider
|
|
11
12
|
* Until there's a fix for: https://github.com/microsoft/tsyringe/issues/63
|
|
13
|
+
* It resolves the same identity it is passed.
|
|
12
14
|
*/
|
|
13
15
|
let DefaultIdentityProvider = class DefaultIdentityProvider {
|
|
14
16
|
provide(identity) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-identity.provider.js","sourceRoot":"","sources":["../../../../src/providers/default-identity.provider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC
|
|
1
|
+
{"version":3,"file":"default-identity.provider.js","sourceRoot":"","sources":["../../../../src/providers/default-identity.provider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAoB,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC;;;;GAIG;AAIH,IAAa,uBAAuB,GAApC,MAAa,uBAAuB;IAChC,OAAO,CAAC,QAA2B;QAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;CACJ,CAAA;AAJY,uBAAuB;IAHnC,UAAU,EAAE;IACZ,GAAG,CAAC,wBAAwB,CAAC,gBAAgB,CAAC;IAC9C,YAAY,CAAC,qBAAqB,CAAC;GACvB,uBAAuB,CAInC;SAJY,uBAAuB"}
|
|
@@ -17,6 +17,9 @@ export const SecurityModule = {
|
|
|
17
17
|
],
|
|
18
18
|
providerRegistrations: [],
|
|
19
19
|
configurationDefinitions: [
|
|
20
|
+
/**
|
|
21
|
+
* The key in the claims of the access token where the roles are defined.
|
|
22
|
+
*/
|
|
20
23
|
{
|
|
21
24
|
parameterName: SecurityModuleKeyname + ".rolesClaimKey",
|
|
22
25
|
isRequired: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.module.js","sourceRoot":"","sources":["../../../src/security.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AAEvE,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAE1C,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC3C,OAAO,EAAE,qBAAqB;IAC9B,aAAa,EAAE;QACX,aAAa;KAChB;IACD,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE;QACtB;YACI,aAAa,EAAE,qBAAqB,GAAG,gBAAgB;YACvD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,OAAO;YACrB,gBAAgB,EAAE;gBACd,IAAI,2BAA2B,CAAC,mCAAmC,CAAC;aACvE;SACJ;KACJ;CAEJ,CAAA"}
|
|
1
|
+
{"version":3,"file":"security.module.js","sourceRoot":"","sources":["../../../src/security.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AAEvE,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAE1C,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC3C,OAAO,EAAE,qBAAqB;IAC9B,aAAa,EAAE;QACX,aAAa;KAChB;IACD,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE;QACtB;;WAEG;QACH;YACI,aAAa,EAAE,qBAAqB,GAAG,gBAAgB;YACvD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,OAAO;YACrB,gBAAgB,EAAE;gBACd,IAAI,2BAA2B,CAAC,mCAAmC,CAAC;aACvE;SACJ;KACJ;CAEJ,CAAA"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { AuthenticatorInterface } from "../interfaces/authenticator.interface";
|
|
2
|
+
/**
|
|
3
|
+
* This decorator specifies the authenticator that should be used to authenticate a request.
|
|
4
|
+
* It should be used either on a controller class or directly on a method.
|
|
5
|
+
* @param authenticator The authenticator to use.
|
|
6
|
+
* @param options Any options that will be passed on to the authenticator.
|
|
7
|
+
*/
|
|
2
8
|
export declare const authenticator: (authenticator: AuthenticatorInterface | Function, options?: any) => (target: any, propertyKey?: string | undefined, descriptor?: PropertyDescriptor | undefined) => void;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { GuardInterface } from "../interfaces/guard.interface";
|
|
2
|
+
/**
|
|
3
|
+
* This decorator specifies the guard that should be used to authorize a request.
|
|
4
|
+
* It should be used either on a controller class or directly on a method.
|
|
5
|
+
* @param guard
|
|
6
|
+
* @param options Any options that will be passed on to the guard.
|
|
7
|
+
*/
|
|
2
8
|
export declare const guard: (guard: GuardInterface | Function, options?: any) => (target: any, propertyKey?: string | undefined, descriptor?: PropertyDescriptor | undefined) => void;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resource action enum specifies the most common actions that can be taken on a resource.
|
|
3
|
+
* It's used in the voters to validate if a user is authorized to execute that action.
|
|
4
|
+
* More actions can be defined in more specified enum based on the resource type.
|
|
5
|
+
*/
|
|
1
6
|
export declare enum ResourceActionEnum {
|
|
2
7
|
List = "LIST",
|
|
3
8
|
Read = "READ",
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The voting strategy enum defines the different strategies that the permission manager uses to
|
|
3
|
+
* merge the results of all the voter.
|
|
4
|
+
*/
|
|
1
5
|
export declare enum VotingStrategyEnum {
|
|
6
|
+
/**
|
|
7
|
+
* When all the voters abstain from voting, the access is granted.
|
|
8
|
+
*/
|
|
2
9
|
GrantOnUnanimousAbstention = "GRANT_ON_UNANIMOUS_ABSTENTION",
|
|
10
|
+
/**
|
|
11
|
+
* When all the voters abstain from voting, the access is denied.
|
|
12
|
+
*/
|
|
3
13
|
DenyOnUnanimousAbstention = "DENY_ON_UNANIMOUS_ABSTENTION"
|
|
4
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This Error is thrown when there's an error that happens when the guards ere being initialized
|
|
3
|
-
*/
|
|
4
1
|
import { LoggableError } from "@pristine-ts/common";
|
|
5
2
|
import { AuthenticatorInterface } from "../interfaces/authenticator.interface";
|
|
3
|
+
/**
|
|
4
|
+
* This Error is thrown when there's an error with the authenticator decorator.
|
|
5
|
+
*/
|
|
6
6
|
export declare class AuthenticatorDecoratorError extends LoggableError {
|
|
7
7
|
constructor(message: string, authenticator: AuthenticatorInterface | Function, options: any, target: any, propertyKey?: string, descriptor?: PropertyDescriptor);
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { AuthenticatorInterface } from "../interfaces/authenticator.interface";
|
|
1
3
|
/**
|
|
2
4
|
* This Error is thrown when there's an error that happens when the authenticator are being initialized
|
|
3
5
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
|
-
import { AuthenticatorInterface } from "../interfaces/authenticator.interface";
|
|
6
6
|
export declare class AuthenticatorInstantiationError extends LoggableError {
|
|
7
7
|
previousError?: Error;
|
|
8
8
|
constructor(message: string, instantiatedAuthenticator: AuthenticatorInterface | Function, authenticatorContext: any);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { GuardInterface } from "../interfaces/guard.interface";
|
|
1
3
|
/**
|
|
2
4
|
* This Error is thrown when there's an error that happens when the guards ere being initialized
|
|
3
5
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
|
-
import { GuardInterface } from "../interfaces/guard.interface";
|
|
6
6
|
export declare class GuardDecoratorError extends LoggableError {
|
|
7
7
|
constructor(message: string, guard: GuardInterface | Function, options: any, target: any, propertyKey?: string, descriptor?: PropertyDescriptor);
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { GuardInterface } from "../interfaces/guard.interface";
|
|
1
3
|
/**
|
|
2
4
|
* This Error is thrown when there's an error that happens when the guards ere being initialized
|
|
3
5
|
*/
|
|
4
|
-
import { LoggableError } from "@pristine-ts/common";
|
|
5
|
-
import { GuardInterface } from "../interfaces/guard.interface";
|
|
6
6
|
export declare class GuardInstantiationError extends LoggableError {
|
|
7
7
|
constructor(message: string, instantiatedGuard: GuardInterface | Function, guardContext: any);
|
|
8
8
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { DependencyContainer } from "tsyringe";
|
|
2
2
|
import { AuthenticatorContextInterface } from "../interfaces/authenticator-context.interface";
|
|
3
3
|
import { AuthenticatorInterface } from "../interfaces/authenticator.interface";
|
|
4
|
+
/**
|
|
5
|
+
* The AuthenticatorFactory returns the proper instantiated authenticator.
|
|
6
|
+
*/
|
|
4
7
|
export declare class AuthenticatorFactory {
|
|
8
|
+
/**
|
|
9
|
+
* This function takes the authenticator context and returns the proper instantiated authenticator.
|
|
10
|
+
* It also validates that the authenticator is valid (it implements the AuthenticatorInterface).
|
|
11
|
+
* @param authenticatorContext The authenticator context that holds the authenticator and options to use.
|
|
12
|
+
* @param container The dependency container from which to retrieve the instantiated authenticator.
|
|
13
|
+
*/
|
|
5
14
|
fromContext(authenticatorContext: AuthenticatorContextInterface, container: DependencyContainer): AuthenticatorInterface;
|
|
6
15
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { DependencyContainer } from "tsyringe";
|
|
2
2
|
import { GuardContextInterface } from "../interfaces/guard-context.interface";
|
|
3
3
|
import { GuardInterface } from "../interfaces/guard.interface";
|
|
4
|
+
/**
|
|
5
|
+
* The GuardFactory returns the proper instantiated guard.
|
|
6
|
+
*/
|
|
4
7
|
export declare class GuardFactory {
|
|
8
|
+
/**
|
|
9
|
+
* This function takes the guard context and returns the proper instantiated guard.
|
|
10
|
+
* It also validates that the guard is valid (it implements the GuardInterface).
|
|
11
|
+
* @param guardContext The guard context that contains the guard and the options to use.
|
|
12
|
+
* @param container The dependency container from which to retrieve the instantiated guard.
|
|
13
|
+
*/
|
|
5
14
|
fromContext(guardContext: GuardContextInterface, container: DependencyContainer): GuardInterface;
|
|
6
15
|
}
|