@spinajs/rbac-http 2.0.28 → 2.0.44
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/lib/2fa/SpeakEasy2FaToken.d.ts +13 -0
- package/lib/2fa/SpeakEasy2FaToken.js +91 -0
- package/lib/2fa/SpeakEasy2FaToken.js.map +1 -0
- package/lib/config/rbac-http.js +19 -0
- package/lib/config/rbac-http.js.map +1 -1
- package/lib/controllers/LoginController.d.ts +26 -4
- package/lib/controllers/LoginController.js +240 -24
- package/lib/controllers/LoginController.js.map +1 -1
- package/lib/controllers/TwoFactorAuthController.d.ts +11 -0
- package/lib/controllers/TwoFactorAuthController.js +71 -0
- package/lib/controllers/TwoFactorAuthController.js.map +1 -0
- package/lib/controllers/UserController.d.ts +1 -1
- package/lib/controllers/UserController.js +7 -11
- package/lib/controllers/UserController.js.map +1 -1
- package/lib/controllers/UserMetadata.js +4 -0
- package/lib/controllers/UserMetadata.js.map +1 -1
- package/lib/decorators.js +6 -10
- package/lib/decorators.js.map +1 -1
- package/lib/dto/login-dto.d.ts +1 -6
- package/lib/dto/login-dto.js +7 -8
- package/lib/dto/login-dto.js.map +1 -1
- package/lib/dto/restore-password-dto.d.ts +23 -0
- package/lib/dto/restore-password-dto.js +34 -0
- package/lib/dto/restore-password-dto.js.map +1 -0
- package/lib/dto/token-dto.d.ts +15 -0
- package/lib/dto/token-dto.js +32 -0
- package/lib/dto/token-dto.js.map +1 -0
- package/lib/dto/userLogin-dto.d.ts +21 -0
- package/lib/dto/userLogin-dto.js +34 -0
- package/lib/dto/userLogin-dto.js.map +1 -0
- package/lib/events/UserLoginFailed.d.ts +5 -0
- package/lib/events/UserLoginFailed.js +25 -0
- package/lib/events/UserLoginFailed.js.map +1 -0
- package/lib/events/UserLoginSuccess.d.ts +5 -0
- package/lib/events/UserLoginSuccess.js +25 -0
- package/lib/events/UserLoginSuccess.js.map +1 -0
- package/lib/events/UserPassordRestore.d.ts +6 -0
- package/lib/events/UserPassordRestore.js +26 -0
- package/lib/events/UserPassordRestore.js.map +1 -0
- package/lib/fingerprint/FingerprintJs.d.ts +3 -0
- package/lib/fingerprint/FingerprintJs.js +18 -0
- package/lib/fingerprint/FingerprintJs.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +35 -0
- package/lib/interfaces.js +7 -0
- package/lib/interfaces.js.map +1 -1
- package/lib/middlewares/AttributeFilter.d.ts +10 -0
- package/lib/middlewares/AttributeFilter.js +19 -0
- package/lib/middlewares/AttributeFilter.js.map +1 -0
- package/lib/middlewares.d.ts +1 -1
- package/lib/middlewares.js +1 -1
- package/lib/middlewares.js.map +1 -1
- package/lib/policies/2FaPolicy.d.ts +7 -0
- package/lib/policies/2FaPolicy.js +32 -0
- package/lib/policies/2FaPolicy.js.map +1 -0
- package/lib/policies/AuthPolicy.d.ts +9 -0
- package/lib/policies/AuthPolicy.js +23 -0
- package/lib/policies/AuthPolicy.js.map +1 -0
- package/lib/policies/LoggedPolicy.d.ts +9 -0
- package/lib/policies/LoggedPolicy.js +23 -0
- package/lib/policies/LoggedPolicy.js.map +1 -0
- package/lib/policies/NotLoggedPolicy.d.ts +9 -0
- package/lib/policies/NotLoggedPolicy.js +22 -0
- package/lib/policies/NotLoggedPolicy.js.map +1 -0
- package/lib/policies/RbacPolicy.d.ts +15 -0
- package/lib/policies/RbacPolicy.js +60 -0
- package/lib/policies/RbacPolicy.js.map +1 -0
- package/lib/policies/captchaPolicy.d.ts +0 -0
- package/lib/policies/captchaPolicy.js +1 -0
- package/lib/policies/captchaPolicy.js.map +1 -0
- package/package.json +19 -13
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterAttribute = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
/**
|
|
6
|
+
* Filters attributes of db models
|
|
7
|
+
*/
|
|
8
|
+
class FilterAttribute extends http_1.RouteMiddleware {
|
|
9
|
+
async onResponse() { }
|
|
10
|
+
isEnabled(_action, _instance) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
// tslint:disable-next-line: no-empty
|
|
14
|
+
async onBefore() { }
|
|
15
|
+
// tslint:disable-next-line: no-empty
|
|
16
|
+
async onAfter() { }
|
|
17
|
+
}
|
|
18
|
+
exports.FilterAttribute = FilterAttribute;
|
|
19
|
+
//# sourceMappingURL=AttributeFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeFilter.js","sourceRoot":"","sources":["../../src/middlewares/AttributeFilter.ts"],"names":[],"mappings":";;;AAAA,wCAAqE;AAErE;;GAEG;AACH,MAAa,eAAgB,SAAQ,sBAAe;IAC3C,KAAK,CAAC,UAAU,KAAmB,CAAC;IAEpC,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qCAAqC;IAC9B,KAAK,CAAC,QAAQ,KAAmB,CAAC;IAEzC,qCAAqC;IAC9B,KAAK,CAAC,OAAO,KAAmB,CAAC;CACzC;AAZD,0CAYC"}
|
package/lib/middlewares.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Request as sRequest, ServerMiddleware } from '@spinajs/http';
|
|
|
5
5
|
export declare class RbacMiddleware extends ServerMiddleware {
|
|
6
6
|
protected CoockieSecret: string;
|
|
7
7
|
protected SessionProvider: SessionProvider;
|
|
8
|
-
|
|
8
|
+
resolve(): Promise<void>;
|
|
9
9
|
before(): (req: sRequest, res: express.Response, next: express.NextFunction) => void;
|
|
10
10
|
after(): (req: sRequest, res: express.Response, next: express.NextFunction) => void;
|
|
11
11
|
}
|
package/lib/middlewares.js
CHANGED
|
@@ -40,7 +40,7 @@ const configuration_1 = require("@spinajs/configuration");
|
|
|
40
40
|
const cs = __importStar(require("cookie-signature"));
|
|
41
41
|
const http_1 = require("@spinajs/http");
|
|
42
42
|
let RbacMiddleware = class RbacMiddleware extends http_1.ServerMiddleware {
|
|
43
|
-
async
|
|
43
|
+
async resolve() {
|
|
44
44
|
if (!this.CoockieSecret) {
|
|
45
45
|
throw new Error('http.cookie.secres is not set, cannot start UserFromSessionMiddleware. Set this value in configuration file !');
|
|
46
46
|
}
|
package/lib/middlewares.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAsD;AACtD,oCAAqD;AACrD,4BAA0B;AAE1B,0DAAgD;AAChD,qDAAuC;AACvC,wCAAsE;AAGtE,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,uBAAgB;IAO3C,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAsD;AACtD,oCAAqD;AACrD,4BAA0B;AAE1B,0DAAgD;AAChD,qDAAuC;AACvC,wCAAsE;AAGtE,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,uBAAgB;IAO3C,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,+GAA+G,CAAC,CAAC;SAClI;IACH,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,EAAE,GAAa,EAAE,IAAsB,EAAE,IAA0B,EAAE,EAAE;YACjF,IAAI;gBACF,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;oBACpB,MAAM,IAAI,GAAmB,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;oBAC7E,IAAI,IAAI,EAAE;wBACR,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;wBACzD,IAAI,OAAO,EAAE;4BACX,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;4BACtD,GAAG,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;yBAC/B;6BAAM;4BACL,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;yBACzB;qBACF;yBAAM;wBACL,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;qBACzB;iBACF;gBACD,IAAI,EAAE,CAAC;aACR;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,GAAG,CAAC,CAAC;aACX;QACH,CAAC,CAAC;IACJ,CAAC;IACM,KAAK;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AArCC;IADC,IAAA,sBAAM,EAAC,oBAAoB,CAAC;;qDACG;AAGhC;IADC,IAAA,eAAU,GAAE;8BACc,sBAAe;uDAAC;AALhC,cAAc;IAD1B,IAAA,eAAU,EAAC,uBAAgB,CAAC;GAChB,cAAc,CAuC1B;AAvCY,wCAAc"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TwoFacRouteEnabled = void 0;
|
|
13
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
14
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
15
|
+
const http_1 = require("@spinajs/http");
|
|
16
|
+
class TwoFacRouteEnabled extends http_1.BasePolicy {
|
|
17
|
+
isEnabled() {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
execute() {
|
|
21
|
+
if (this.TwoFactorConfig.enabled === false) {
|
|
22
|
+
throw new exceptions_1.InvalidOperation('2 factor auth is not enabled');
|
|
23
|
+
}
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, configuration_1.Config)('rbac.twoFactorAuth'),
|
|
29
|
+
__metadata("design:type", Object)
|
|
30
|
+
], TwoFacRouteEnabled.prototype, "TwoFactorConfig", void 0);
|
|
31
|
+
exports.TwoFacRouteEnabled = TwoFacRouteEnabled;
|
|
32
|
+
//# sourceMappingURL=2FaPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2FaPolicy.js","sourceRoot":"","sources":["../../src/policies/2FaPolicy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAuD;AACvD,0DAAgD;AAChD,wCAA2C;AAG3C,MAAa,kBAAmB,SAAQ,iBAAU;IAIzC,SAAS;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IACM,OAAO;QACZ,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,KAAK,KAAK,EAAE;YAC1C,MAAM,IAAI,6BAAgB,CAAC,8BAA8B,CAAC,CAAC;SAC5D;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAZC;IADC,IAAA,sBAAM,EAAC,oBAAoB,CAAC;;2DACkB;AAFjD,gDAcC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasePolicy, IController, IRoute, Request as sRequest } from '@spinajs/http';
|
|
2
|
+
/**
|
|
3
|
+
* Simple policy to only check if user is authorized ( do not check permissions for routes)
|
|
4
|
+
* Usefull if we want to give acces for all logged users
|
|
5
|
+
*/
|
|
6
|
+
export declare class AuthPolicy extends BasePolicy {
|
|
7
|
+
isEnabled(_action: IRoute, _instance: IController): boolean;
|
|
8
|
+
execute(req: sRequest): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthPolicy = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
6
|
+
/**
|
|
7
|
+
* Simple policy to only check if user is authorized ( do not check permissions for routes)
|
|
8
|
+
* Usefull if we want to give acces for all logged users
|
|
9
|
+
*/
|
|
10
|
+
class AuthPolicy extends http_1.BasePolicy {
|
|
11
|
+
isEnabled(_action, _instance) {
|
|
12
|
+
// acl is always on if set
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
async execute(req) {
|
|
16
|
+
if (!req.storage || !req.storage.user || !req.storage.session.Data.get('Authorized')) {
|
|
17
|
+
throw new exceptions_1.Forbidden('user not logged or session expired');
|
|
18
|
+
}
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.AuthPolicy = AuthPolicy;
|
|
23
|
+
//# sourceMappingURL=AuthPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthPolicy.js","sourceRoot":"","sources":["../../src/policies/AuthPolicy.ts"],"names":[],"mappings":";;;AAAA,wCAAqF;AACrF,oDAAgD;AAEhD;;;GAGG;AACH,MAAa,UAAW,SAAQ,iBAAU;IACjC,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,0BAA0B;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAa;QAChC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;YACpF,MAAM,IAAI,sBAAS,CAAC,oCAAoC,CAAC,CAAC;SAC3D;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAbD,gCAaC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasePolicy, IController, IRoute, Request as sRequest } from '@spinajs/http';
|
|
2
|
+
/**
|
|
3
|
+
* Simple policy to only check if user is authorized ( do not check permissions for routes)
|
|
4
|
+
* Usefull if we want to give acces for all logged users
|
|
5
|
+
*/
|
|
6
|
+
export declare class LoggedPolicy extends BasePolicy {
|
|
7
|
+
isEnabled(_action: IRoute, _instance: IController): boolean;
|
|
8
|
+
execute(req: sRequest): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggedPolicy = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
6
|
+
/**
|
|
7
|
+
* Simple policy to only check if user is authorized ( do not check permissions for routes)
|
|
8
|
+
* Usefull if we want to give acces for all logged users
|
|
9
|
+
*/
|
|
10
|
+
class LoggedPolicy extends http_1.BasePolicy {
|
|
11
|
+
isEnabled(_action, _instance) {
|
|
12
|
+
// acl is always on if set
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
async execute(req) {
|
|
16
|
+
if (!req.storage || !req.storage.user || !req.storage.session.Data.get('Authorized')) {
|
|
17
|
+
throw new exceptions_1.Forbidden('user not logged or session expired');
|
|
18
|
+
}
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.LoggedPolicy = LoggedPolicy;
|
|
23
|
+
//# sourceMappingURL=LoggedPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoggedPolicy.js","sourceRoot":"","sources":["../../src/policies/LoggedPolicy.ts"],"names":[],"mappings":";;;AAAA,wCAAqF;AACrF,oDAAgD;AAEhD;;;GAGG;AACH,MAAa,YAAa,SAAQ,iBAAU;IACnC,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,0BAA0B;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAa;QAChC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;YACpF,MAAM,IAAI,sBAAS,CAAC,oCAAoC,CAAC,CAAC;SAC3D;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAbD,oCAaC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasePolicy, IController, IRoute, Request as sRequest } from '@spinajs/http';
|
|
2
|
+
/**
|
|
3
|
+
* Simple policy to only check if user is authorized ( do not check permissions for routes)
|
|
4
|
+
* Usefull if we want to give acces for all logged users
|
|
5
|
+
*/
|
|
6
|
+
export declare class NotLoggedPolicy extends BasePolicy {
|
|
7
|
+
isEnabled(_action: IRoute, _instance: IController): boolean;
|
|
8
|
+
execute(req: sRequest): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotLoggedPolicy = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
6
|
+
/**
|
|
7
|
+
* Simple policy to only check if user is authorized ( do not check permissions for routes)
|
|
8
|
+
* Usefull if we want to give acces for all logged users
|
|
9
|
+
*/
|
|
10
|
+
class NotLoggedPolicy extends http_1.BasePolicy {
|
|
11
|
+
isEnabled(_action, _instance) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
async execute(req) {
|
|
15
|
+
if (!req.storage || !req.storage.user || !req.storage.session.Data.get('Authorized')) {
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
}
|
|
18
|
+
throw new exceptions_1.InvalidOperation('Cannot perform action when user is logged.');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.NotLoggedPolicy = NotLoggedPolicy;
|
|
22
|
+
//# sourceMappingURL=NotLoggedPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotLoggedPolicy.js","sourceRoot":"","sources":["../../src/policies/NotLoggedPolicy.ts"],"names":[],"mappings":";;;AAAA,wCAAqF;AACrF,oDAAuD;AAEvD;;;GAGG;AACH,MAAa,eAAgB,SAAQ,iBAAU;IACtC,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAa;QAChC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;YACpF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QAED,MAAM,IAAI,6BAAgB,CAAC,4CAA4C,CAAC,CAAC;IAC3E,CAAC;CACF;AAZD,0CAYC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AccessControl, Permission } from 'accesscontrol';
|
|
2
|
+
import { BasePolicy, IController, IRoute, Request as sRequest } from '@spinajs/http';
|
|
3
|
+
import { User } from '@spinajs/rbac';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if user is logged, authorized & have proper permissions
|
|
6
|
+
*/
|
|
7
|
+
export declare class RbacPolicy extends BasePolicy {
|
|
8
|
+
protected Ac: AccessControl;
|
|
9
|
+
constructor();
|
|
10
|
+
isEnabled(_action: IRoute, _instance: IController): boolean;
|
|
11
|
+
execute(req: sRequest, action: IRoute, instance: IController): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function checkRbacPermission(role: string | string[], resource: string, permission: string): Permission;
|
|
14
|
+
export declare function checkUserPermission(user: User, resource: string, permission: string): Permission;
|
|
15
|
+
export declare function checkRoutePermission(req: sRequest, resource: string, permission: string): Permission;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkRoutePermission = exports.checkUserPermission = exports.checkRbacPermission = exports.RbacPolicy = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
7
|
+
const di_1 = require("@spinajs/di");
|
|
8
|
+
/**
|
|
9
|
+
* Checks if user is logged, authorized & have proper permissions
|
|
10
|
+
*/
|
|
11
|
+
class RbacPolicy extends http_1.BasePolicy {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.Ac = di_1.DI.get('AccessControl');
|
|
15
|
+
}
|
|
16
|
+
isEnabled(_action, _instance) {
|
|
17
|
+
// acl is always on if set
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
async execute(req, action, instance) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const descriptor = Reflect.getMetadata(decorators_1.ACL_CONTROLLER_DESCRIPTOR, instance);
|
|
23
|
+
let permission = (_a = descriptor.Permission) !== null && _a !== void 0 ? _a : '';
|
|
24
|
+
// check if route has its own permission
|
|
25
|
+
if (descriptor.Routes.has(action.Method)) {
|
|
26
|
+
permission = (_b = descriptor.Routes.get(action.Method).Permission) !== null && _b !== void 0 ? _b : '';
|
|
27
|
+
}
|
|
28
|
+
if (!descriptor || !descriptor.Permission) {
|
|
29
|
+
throw new exceptions_1.Forbidden(`no route permission or resources assigned`);
|
|
30
|
+
}
|
|
31
|
+
if (!req.storage || !req.storage.user || !req.storage.session.Data.get('Authorized')) {
|
|
32
|
+
throw new exceptions_1.Forbidden('user not logged or session expired');
|
|
33
|
+
}
|
|
34
|
+
if (!checkRoutePermission(req, descriptor.Resource, permission).granted) {
|
|
35
|
+
throw new exceptions_1.Forbidden(`role(s) ${req.storage.user.Role} does not have permission ${permission} for resource ${descriptor.Resource}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.RbacPolicy = RbacPolicy;
|
|
40
|
+
function checkRbacPermission(role, resource, permission) {
|
|
41
|
+
const ac = di_1.DI.get('AccessControl');
|
|
42
|
+
return ac.can(role)[permission](resource);
|
|
43
|
+
}
|
|
44
|
+
exports.checkRbacPermission = checkRbacPermission;
|
|
45
|
+
function checkUserPermission(user, resource, permission) {
|
|
46
|
+
const ac = di_1.DI.get('AccessControl');
|
|
47
|
+
if (!user) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return ac.can(user.Role)[permission](resource);
|
|
51
|
+
}
|
|
52
|
+
exports.checkUserPermission = checkUserPermission;
|
|
53
|
+
function checkRoutePermission(req, resource, permission) {
|
|
54
|
+
if (!req.storage || !req.storage.user) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return checkUserPermission(req.storage.user, resource, permission);
|
|
58
|
+
}
|
|
59
|
+
exports.checkRoutePermission = checkRoutePermission;
|
|
60
|
+
//# sourceMappingURL=RbacPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RbacPolicy.js","sourceRoot":"","sources":["../../src/policies/RbacPolicy.ts"],"names":[],"mappings":";;;AACA,wCAAqF;AACrF,oDAAgD;AAChD,8CAA0D;AAE1D,oCAAiC;AAGjC;;GAEG;AACH,MAAa,UAAW,SAAQ,iBAAU;IAGxC;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,EAAE,GAAG,OAAE,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACpC,CAAC;IAEM,SAAS,CAAC,OAAe,EAAE,SAAsB;QACtD,0BAA0B;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAa,EAAE,MAAc,EAAE,QAAqB;;QACvE,MAAM,UAAU,GAAoB,OAAO,CAAC,WAAW,CAAC,sCAAyB,EAAE,QAAQ,CAAC,CAAC;QAC7F,IAAI,UAAU,GAAG,MAAA,UAAU,CAAC,UAAU,mCAAI,EAAE,CAAC;QAE7C,wCAAwC;QACxC,IAAI,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACxC,UAAU,GAAG,MAAA,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,mCAAI,EAAE,CAAC;SACpE;QAED,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;YACzC,MAAM,IAAI,sBAAS,CAAC,2CAA2C,CAAC,CAAC;SAClE;QAED,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE;YACpF,MAAM,IAAI,sBAAS,CAAC,oCAAoC,CAAC,CAAC;SAC3D;QAED,IAAI,CAAC,oBAAoB,CAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,OAAO,EAAE;YACvE,MAAM,IAAI,sBAAS,CAAC,WAAW,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,6BAA6B,UAAU,iBAAiB,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpI;IACH,CAAC;CACF;AAnCD,gCAmCC;AAED,SAAgB,mBAAmB,CAAC,IAAuB,EAAE,QAAgB,EAAE,UAAkB;IAC/F,MAAM,EAAE,GAAG,OAAE,CAAC,GAAG,CAAgB,eAAe,CAAC,CAAC;IAClD,OAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAS,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC;AACrD,CAAC;AAHD,kDAGC;AAED,SAAgB,mBAAmB,CAAC,IAAU,EAAE,QAAgB,EAAE,UAAkB;IAClF,MAAM,EAAE,GAAG,OAAE,CAAC,GAAG,CAAgB,eAAe,CAAC,CAAC;IAElD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,IAAI,CAAC;KACb;IAED,OAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAS,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC1D,CAAC;AARD,kDAQC;AAED,SAAgB,oBAAoB,CAAC,GAAa,EAAE,QAAgB,EAAE,UAAkB;IACtF,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;QACrC,OAAO,IAAI,CAAC;KACb;IAED,OAAO,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AACrE,CAAC;AAND,oDAMC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=captchaPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captchaPolicy.js","sourceRoot":"","sources":["../../src/policies/captchaPolicy.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spinajs/rbac-http",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.44",
|
|
4
4
|
"description": "HTTP API for user session & permissions",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -38,20 +38,26 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/spinajs/main#readme",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@spinajs/configuration": "^2.0.
|
|
42
|
-
"@spinajs/di": "^2.0.
|
|
43
|
-
"@spinajs/exceptions": "^2.0.
|
|
44
|
-
"@spinajs/http": "^2.0.
|
|
45
|
-
"@spinajs/log": "^2.0.
|
|
46
|
-
"@spinajs/orm": "^2.0.
|
|
47
|
-
"@spinajs/orm-http": "^2.0.
|
|
48
|
-
"@spinajs/rbac": "^2.0.
|
|
49
|
-
"@spinajs/reflection": "^2.0.
|
|
41
|
+
"@spinajs/configuration": "^2.0.44",
|
|
42
|
+
"@spinajs/di": "^2.0.44",
|
|
43
|
+
"@spinajs/exceptions": "^2.0.39",
|
|
44
|
+
"@spinajs/http": "^2.0.44",
|
|
45
|
+
"@spinajs/log": "^2.0.44",
|
|
46
|
+
"@spinajs/orm": "^2.0.44",
|
|
47
|
+
"@spinajs/orm-http": "^2.0.44",
|
|
48
|
+
"@spinajs/rbac": "^2.0.44",
|
|
49
|
+
"@spinajs/reflection": "^2.0.44",
|
|
50
50
|
"accesscontrol": "^2.2.1",
|
|
51
|
-
"luxon": "^2.
|
|
51
|
+
"luxon": "^3.2.1",
|
|
52
|
+
"qrcode": "^1.5.1",
|
|
53
|
+
"speakeasy": "^2.0.0",
|
|
54
|
+
"uuid": "^8.3.2"
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
54
|
-
"@spinajs/orm-sqlite": "^2.0.
|
|
57
|
+
"@spinajs/orm-sqlite": "^2.0.44",
|
|
58
|
+
"@types/qrcode": "^1.4.2",
|
|
59
|
+
"@types/speakeasy": "^2.0.7",
|
|
60
|
+
"@types/uuid": "^8.3.3"
|
|
55
61
|
},
|
|
56
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "1857a6e3626e0fed22ffb0b44b48d587c79898db"
|
|
57
63
|
}
|