@uniorganization/uni-lib 4.0.51 → 4.1.1
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/entities/active-loads.entity.d.ts +1 -0
- package/dist/entities/active-loads.entity.js +4 -0
- package/dist/entities/applications.entity.d.ts +1 -0
- package/dist/entities/applications.entity.js +4 -0
- package/dist/entities/audit.entity.d.ts +1 -0
- package/dist/entities/audit.entity.js +4 -0
- package/dist/entities/autofail-reasons.entity.d.ts +1 -0
- package/dist/entities/autofail-reasons.entity.js +4 -0
- package/dist/entities/blacklist.entity.d.ts +1 -0
- package/dist/entities/blacklist.entity.js +5 -1
- package/dist/entities/bp-alerts.entity.d.ts +1 -0
- package/dist/entities/bp-alerts.entity.js +4 -0
- package/dist/entities/business-schedule-day.entity.d.ts +1 -0
- package/dist/entities/business-schedule-day.entity.js +4 -0
- package/dist/entities/business-schedule.entity.d.ts +1 -0
- package/dist/entities/business-schedule.entity.js +4 -0
- package/dist/entities/call-driver-data.entity.d.ts +1 -0
- package/dist/entities/call-driver-data.entity.js +4 -0
- package/dist/entities/call-drivers.entity.d.ts +1 -0
- package/dist/entities/call-drivers.entity.js +4 -0
- package/dist/entities/cb-completed-reasons.entity.d.ts +1 -0
- package/dist/entities/cb-completed-reasons.entity.js +4 -0
- package/dist/entities/change-alert.entity.d.ts +1 -0
- package/dist/entities/change-alert.entity.js +4 -0
- package/dist/entities/claim-report.entity.d.ts +1 -0
- package/dist/entities/claim-report.entity.js +6 -2
- package/dist/entities/client-credential.entity.d.ts +17 -0
- package/dist/entities/client-credential.entity.js +87 -0
- package/dist/entities/client.entity.d.ts +12 -0
- package/dist/entities/client.entity.js +67 -0
- package/dist/entities/config.entity.d.ts +1 -0
- package/dist/entities/config.entity.js +4 -0
- package/dist/entities/contact-search.entity.d.ts +1 -0
- package/dist/entities/contact-search.entity.js +17 -13
- package/dist/entities/daily-payment-status.entity.d.ts +1 -0
- package/dist/entities/daily-payment-status.entity.js +4 -0
- package/dist/entities/daily-payment.entity.d.ts +58 -0
- package/dist/entities/daily-payment.entity.js +248 -0
- package/dist/entities/daily-pending.entity.d.ts +1 -0
- package/dist/entities/daily-pending.entity.js +5 -1
- package/dist/entities/depreciation-categories.entity.d.ts +1 -0
- package/dist/entities/depreciation-categories.entity.js +4 -0
- package/dist/entities/depreciation-details.entity.d.ts +1 -0
- package/dist/entities/depreciation-details.entity.js +4 -0
- package/dist/entities/detail-type.entity.d.ts +1 -0
- package/dist/entities/detail-type.entity.js +4 -0
- package/dist/entities/dispute-request.entity.d.ts +1 -0
- package/dist/entities/dispute-request.entity.js +4 -0
- package/dist/entities/enr-calculation-log.entity.d.ts +1 -0
- package/dist/entities/enr-calculation-log.entity.js +4 -0
- package/dist/entities/enr-inventory.entity.d.ts +1 -0
- package/dist/entities/enr-inventory.entity.js +4 -0
- package/dist/entities/enr-results.entity.d.ts +1 -0
- package/dist/entities/enr-results.entity.js +4 -0
- package/dist/entities/escalation-category.entity.d.ts +1 -0
- package/dist/entities/escalation-category.entity.js +4 -0
- package/dist/entities/escalation-notes.entity.d.ts +1 -0
- package/dist/entities/escalation-notes.entity.js +4 -0
- package/dist/entities/escalation-outcome.entity.d.ts +1 -0
- package/dist/entities/escalation-outcome.entity.js +4 -0
- package/dist/entities/escalation-status-log.entity.d.ts +1 -0
- package/dist/entities/escalation-status-log.entity.js +4 -0
- package/dist/entities/escalation-status.entity.d.ts +1 -0
- package/dist/entities/escalation-status.entity.js +4 -0
- package/dist/entities/escalation-type.entity.d.ts +1 -0
- package/dist/entities/escalation-type.entity.js +4 -0
- package/dist/entities/escalations.entity.d.ts +1 -0
- package/dist/entities/escalations.entity.js +4 -0
- package/dist/entities/evaluation-autofail-reasons.entity.d.ts +1 -0
- package/dist/entities/evaluation-autofail-reasons.entity.js +4 -0
- package/dist/entities/evaluation-data.entity.d.ts +1 -0
- package/dist/entities/evaluation-data.entity.js +4 -0
- package/dist/entities/evaluation-forms.entity.d.ts +1 -0
- package/dist/entities/evaluation-forms.entity.js +4 -0
- package/dist/entities/evaluation-questions.entity.d.ts +1 -0
- package/dist/entities/evaluation-questions.entity.js +4 -0
- package/dist/entities/evaluations.entity.d.ts +1 -0
- package/dist/entities/evaluations.entity.js +4 -0
- package/dist/entities/feedback.entity.d.ts +1 -0
- package/dist/entities/feedback.entity.js +4 -0
- package/dist/entities/file-contents.entity.d.ts +1 -0
- package/dist/entities/file-contents.entity.js +4 -0
- package/dist/entities/file-type.entity.d.ts +1 -0
- package/dist/entities/file-type.entity.js +5 -2
- package/dist/entities/file-upload.entity.d.ts +1 -0
- package/dist/entities/file-upload.entity.js +4 -0
- package/dist/entities/file.entity.d.ts +1 -0
- package/dist/entities/file.entity.js +4 -0
- package/dist/entities/form-definition.entity.d.ts +1 -0
- package/dist/entities/form-definition.entity.js +4 -0
- package/dist/entities/form-fields.entity.d.ts +1 -0
- package/dist/entities/form-fields.entity.js +4 -0
- package/dist/entities/form.entity.d.ts +1 -0
- package/dist/entities/form.entity.js +4 -0
- package/dist/entities/inbox/agent-extension-backup.entity.d.ts +1 -0
- package/dist/entities/inbox/agent-extension-backup.entity.js +10 -2
- package/dist/entities/inbox/agent-extension.entity.d.ts +1 -0
- package/dist/entities/inbox/agent-extension.entity.js +6 -2
- package/dist/entities/inbox/assignment.entity.d.ts +1 -0
- package/dist/entities/inbox/assignment.entity.js +5 -3
- package/dist/entities/inbox/case-event.entity.d.ts +1 -0
- package/dist/entities/inbox/case-event.entity.js +4 -0
- package/dist/entities/inbox/case-file.entity.d.ts +1 -0
- package/dist/entities/inbox/case-file.entity.js +4 -0
- package/dist/entities/inbox/case-link.entity.d.ts +1 -0
- package/dist/entities/inbox/case-link.entity.js +4 -0
- package/dist/entities/inbox/case-note.entity.d.ts +1 -0
- package/dist/entities/inbox/case-note.entity.js +4 -0
- package/dist/entities/inbox/case-tag.entity.d.ts +1 -0
- package/dist/entities/inbox/case-tag.entity.js +4 -0
- package/dist/entities/inbox/case-text.entity.d.ts +1 -0
- package/dist/entities/inbox/case-text.entity.js +5 -3
- package/dist/entities/inbox/contact-attempt.entity.d.ts +1 -0
- package/dist/entities/inbox/contact-attempt.entity.js +4 -0
- package/dist/entities/inbox/inbound-message.entity.d.ts +1 -0
- package/dist/entities/inbox/inbound-message.entity.js +5 -1
- package/dist/entities/inbox/message-case.entity.d.ts +1 -0
- package/dist/entities/inbox/message-case.entity.js +9 -3
- package/dist/entities/inbox/notification.entity.d.ts +1 -0
- package/dist/entities/inbox/notification.entity.js +4 -0
- package/dist/entities/inbox/sla-policy.entity.d.ts +1 -0
- package/dist/entities/inbox/sla-policy.entity.js +7 -2
- package/dist/entities/inbox/tag.entity.d.ts +1 -0
- package/dist/entities/inbox/tag.entity.js +7 -2
- package/dist/entities/incoterms.entity.d.ts +1 -0
- package/dist/entities/incoterms.entity.js +4 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +2 -0
- package/dist/entities/inventory.entity.d.ts +1 -0
- package/dist/entities/inventory.entity.js +4 -0
- package/dist/entities/kenko.entity.d.ts +1 -0
- package/dist/entities/kenko.entity.js +4 -0
- package/dist/entities/lob-assignment.entity.d.ts +1 -0
- package/dist/entities/lob-assignment.entity.js +4 -0
- package/dist/entities/lob-call-drivers.entity.d.ts +1 -0
- package/dist/entities/lob-call-drivers.entity.js +4 -0
- package/dist/entities/location-addresses.entity.d.ts +1 -0
- package/dist/entities/location-addresses.entity.js +4 -0
- package/dist/entities/ltp-history-transactions.entity.d.ts +1 -0
- package/dist/entities/ltp-history-transactions.entity.js +4 -0
- package/dist/entities/ltp-stm-roster.entity.d.ts +1 -0
- package/dist/entities/ltp-stm-roster.entity.js +4 -0
- package/dist/entities/modules-roles.entity.d.ts +1 -0
- package/dist/entities/modules-roles.entity.js +4 -0
- package/dist/entities/offphone-activities.entity.d.ts +1 -0
- package/dist/entities/offphone-activities.entity.js +4 -0
- package/dist/entities/onsite-ordering.entity.d.ts +1 -0
- package/dist/entities/onsite-ordering.entity.js +4 -0
- package/dist/entities/ost.entity.d.ts +1 -0
- package/dist/entities/ost.entity.js +4 -0
- package/dist/entities/otwe-offers.entity.d.ts +1 -0
- package/dist/entities/otwe-offers.entity.js +4 -0
- package/dist/entities/outbound-ticket-history.entity.d.ts +1 -0
- package/dist/entities/outbound-ticket-history.entity.js +4 -0
- package/dist/entities/p1-service-center.entity.d.ts +1 -0
- package/dist/entities/p1-service-center.entity.js +4 -0
- package/dist/entities/p1-service-network.entity.d.ts +1 -0
- package/dist/entities/p1-service-network.entity.js +4 -0
- package/dist/entities/pending-ticket-history.entity.d.ts +1 -0
- package/dist/entities/pending-ticket-history.entity.js +4 -0
- package/dist/entities/product-codes.entity.d.ts +1 -0
- package/dist/entities/product-codes.entity.js +4 -0
- package/dist/entities/question-group.entity.d.ts +1 -0
- package/dist/entities/question-group.entity.js +4 -0
- package/dist/entities/questions.entity.d.ts +1 -0
- package/dist/entities/questions.entity.js +4 -0
- package/dist/entities/raw_roster.entity.d.ts +1 -0
- package/dist/entities/raw_roster.entity.js +4 -0
- package/dist/entities/regional-service-mgr.entity.d.ts +1 -0
- package/dist/entities/regional-service-mgr.entity.js +4 -0
- package/dist/entities/role-definition.entity.d.ts +1 -0
- package/dist/entities/role-definition.entity.js +4 -0
- package/dist/entities/role-privileges.entity.d.ts +1 -0
- package/dist/entities/role-privileges.entity.js +4 -0
- package/dist/entities/roster-personnel.entity.d.ts +1 -0
- package/dist/entities/roster-personnel.entity.js +4 -0
- package/dist/entities/sap-raw-data.entity.d.ts +1 -0
- package/dist/entities/sap-raw-data.entity.js +4 -0
- package/dist/entities/service-center-distance-cache.entity.d.ts +1 -0
- package/dist/entities/service-center-distance-cache.entity.js +5 -1
- package/dist/entities/service-center-geocode-cache.entity.d.ts +1 -0
- package/dist/entities/service-center-geocode-cache.entity.js +5 -1
- package/dist/entities/service-center-interaction.entity.d.ts +1 -0
- package/dist/entities/service-center-interaction.entity.js +4 -0
- package/dist/entities/service-center-phone.entity.d.ts +1 -0
- package/dist/entities/service-center-phone.entity.js +4 -0
- package/dist/entities/service-center-ranking.entity.d.ts +1 -0
- package/dist/entities/service-center-ranking.entity.js +4 -0
- package/dist/entities/service-center-review.entity.d.ts +1 -0
- package/dist/entities/service-center-review.entity.js +4 -0
- package/dist/entities/service-center-unsupported-model.entity.d.ts +1 -0
- package/dist/entities/service-center-unsupported-model.entity.js +5 -1
- package/dist/entities/service-center.entity.d.ts +1 -0
- package/dist/entities/service-center.entity.js +6 -2
- package/dist/entities/service-type.entity.d.ts +1 -0
- package/dist/entities/service-type.entity.js +4 -0
- package/dist/entities/skipped-ticket.entity.d.ts +1 -0
- package/dist/entities/skipped-ticket.entity.js +4 -0
- package/dist/entities/state.entity.d.ts +1 -0
- package/dist/entities/state.entity.js +4 -0
- package/dist/entities/template.entity.d.ts +1 -0
- package/dist/entities/template.entity.js +4 -0
- package/dist/entities/ticket-queue.entity.d.ts +1 -0
- package/dist/entities/ticket-queue.entity.js +4 -0
- package/dist/entities/ticket-service-center-match-loa-pricing.entity.d.ts +1 -0
- package/dist/entities/ticket-service-center-match-loa-pricing.entity.js +4 -0
- package/dist/entities/ticket-service-center-match-process.entity.d.ts +1 -0
- package/dist/entities/ticket-service-center-match-process.entity.js +4 -0
- package/dist/entities/transactions.entity.d.ts +1 -0
- package/dist/entities/transactions.entity.js +4 -0
- package/dist/entities/user-campaign.entity.d.ts +1 -0
- package/dist/entities/user-campaign.entity.js +4 -0
- package/dist/entities/user-roles.entity.d.ts +4 -0
- package/dist/entities/user-roles.entity.js +22 -3
- package/dist/entities/usr.entity.d.ts +1 -0
- package/dist/entities/usr.entity.js +4 -0
- package/dist/entities/vw-escalation-age.d.ts +1 -0
- package/dist/entities/vw-escalation-age.js +4 -0
- package/dist/entities/warranty-category.entity.d.ts +1 -0
- package/dist/entities/warranty-category.entity.js +4 -0
- package/dist/middlewares/index.d.ts +1 -0
- package/dist/middlewares/index.js +17 -0
- package/dist/middlewares/version-checker.middleware.d.ts +2 -0
- package/dist/middlewares/version-checker.middleware.js +27 -0
- package/dist/modules/common/common.module.js +5 -4
- package/dist/modules/common/jwt-auth.guard.d.ts +5 -2
- package/dist/modules/common/jwt-auth.guard.js +20 -12
- package/dist/modules/common/jwt.strategy.d.ts +6 -18
- package/dist/modules/common/jwt.strategy.js +80 -16
- package/dist/modules/common/logged-user.decorator.js +2 -2
- package/dist/modules/common/skip-jwt-auth.decorator.d.ts +3 -1
- package/dist/modules/common/skip-jwt-auth.decorator.js +5 -2
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/modules/tenant/current-tenant.decorator.d.ts +1 -0
- package/dist/modules/tenant/current-tenant.decorator.js +14 -0
- package/dist/modules/tenant/index.d.ts +21 -0
- package/dist/modules/tenant/index.js +37 -0
- package/dist/modules/tenant/master-tenant.decorator.d.ts +1 -0
- package/dist/modules/tenant/master-tenant.decorator.js +7 -0
- package/dist/modules/tenant/master-tenant.guard.d.ts +7 -0
- package/dist/modules/tenant/master-tenant.guard.js +44 -0
- package/dist/modules/tenant/redis-tenant-state.store.d.ts +21 -0
- package/dist/modules/tenant/redis-tenant-state.store.js +165 -0
- package/dist/modules/tenant/tenant-audit.types.d.ts +15 -0
- package/dist/modules/tenant/tenant-audit.types.js +2 -0
- package/dist/modules/tenant/tenant-authorization.keys.d.ts +3 -0
- package/dist/modules/tenant/tenant-authorization.keys.js +28 -0
- package/dist/modules/tenant/tenant-authorization.service.d.ts +24 -0
- package/dist/modules/tenant/tenant-authorization.service.js +235 -0
- package/dist/modules/tenant/tenant-authorization.store.d.ts +8 -0
- package/dist/modules/tenant/tenant-authorization.store.js +4 -0
- package/dist/modules/tenant/tenant-authorization.types.d.ts +36 -0
- package/dist/modules/tenant/tenant-authorization.types.js +2 -0
- package/dist/modules/tenant/tenant-context.errors.d.ts +3 -0
- package/dist/modules/tenant/tenant-context.errors.js +10 -0
- package/dist/modules/tenant/tenant-context.interceptor.d.ts +9 -0
- package/dist/modules/tenant/tenant-context.interceptor.js +69 -0
- package/dist/modules/tenant/tenant-context.service.d.ts +15 -0
- package/dist/modules/tenant/tenant-context.service.js +56 -0
- package/dist/modules/tenant/tenant-context.storage.d.ts +6 -0
- package/dist/modules/tenant/tenant-context.storage.js +34 -0
- package/dist/modules/tenant/tenant-credential.guard.d.ts +13 -0
- package/dist/modules/tenant/tenant-credential.guard.js +119 -0
- package/dist/modules/tenant/tenant-ownership.service.d.ts +7 -0
- package/dist/modules/tenant/tenant-ownership.service.js +28 -0
- package/dist/modules/tenant/tenant-query.helpers.d.ts +12 -0
- package/dist/modules/tenant/tenant-query.helpers.js +37 -0
- package/dist/modules/tenant/tenant-runner.service.d.ts +7 -0
- package/dist/modules/tenant/tenant-runner.service.js +41 -0
- package/dist/modules/tenant/tenant-security-state.service.d.ts +11 -0
- package/dist/modules/tenant/tenant-security-state.service.js +75 -0
- package/dist/modules/tenant/tenant-security-state.store.d.ts +7 -0
- package/dist/modules/tenant/tenant-security-state.store.js +4 -0
- package/dist/modules/tenant/tenant.constants.d.ts +7 -0
- package/dist/modules/tenant/tenant.constants.js +10 -0
- package/dist/modules/tenant/tenant.module.d.ts +2 -0
- package/dist/modules/tenant/tenant.module.js +70 -0
- package/dist/modules/tenant/tenant.types.d.ts +69 -0
- package/dist/modules/tenant/tenant.types.js +2 -0
- package/package.json +2 -1
|
@@ -8,9 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
12
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
13
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -24,33 +21,100 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
21
|
exports.JwtStrategy = void 0;
|
|
25
22
|
const common_1 = require("@nestjs/common");
|
|
26
23
|
const passport_1 = require("@nestjs/passport");
|
|
27
|
-
const typeorm_1 = require("@nestjs/typeorm");
|
|
28
24
|
const passport_jwt_1 = require("passport-jwt");
|
|
29
|
-
const
|
|
30
|
-
const typeorm_2 = require("typeorm");
|
|
25
|
+
const tenant_1 = require("../tenant");
|
|
31
26
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
32
|
-
constructor(
|
|
27
|
+
constructor(authorization, securityState) {
|
|
33
28
|
super({
|
|
34
29
|
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
35
|
-
ignoreExpiration:
|
|
30
|
+
ignoreExpiration: process.env.JWT_IGNORE_EXPIRATION === 'true',
|
|
36
31
|
secretOrKey: process.env.JWT_SECRET,
|
|
37
32
|
});
|
|
38
|
-
this.
|
|
33
|
+
this.authorization = authorization;
|
|
34
|
+
this.securityState = securityState;
|
|
39
35
|
}
|
|
40
36
|
validate(payload) {
|
|
41
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
const signedUser = payload === null || payload === void 0 ? void 0 : payload.user;
|
|
40
|
+
const effectiveClientId = Number(signedUser === null || signedUser === void 0 ? void 0 : signedUser.clientId);
|
|
41
|
+
const homeClientId = Number(signedUser === null || signedUser === void 0 ? void 0 : signedUser.homeClientId);
|
|
42
|
+
const originalClientId = (_a = signedUser === null || signedUser === void 0 ? void 0 : signedUser.originalClientId) !== null && _a !== void 0 ? _a : null;
|
|
43
|
+
const now = Math.floor(Date.now() / 1000);
|
|
44
|
+
if ((payload === null || payload === void 0 ? void 0 : payload.type) !== 'access' ||
|
|
45
|
+
!signedUser ||
|
|
46
|
+
!Number.isInteger(signedUser.id) ||
|
|
47
|
+
String(signedUser.id) !== payload.sub ||
|
|
48
|
+
!Number.isInteger(effectiveClientId) ||
|
|
49
|
+
effectiveClientId <= 0 ||
|
|
50
|
+
!Number.isInteger(homeClientId) ||
|
|
51
|
+
homeClientId <= 0 ||
|
|
52
|
+
!Number.isInteger(payload.exp) ||
|
|
53
|
+
payload.exp <= now ||
|
|
54
|
+
!this.validTokenIdentifier(payload.jti) ||
|
|
55
|
+
signedUser.jti !== payload.jti ||
|
|
56
|
+
signedUser.tokenExpiresAt !== payload.exp) {
|
|
57
|
+
throw new common_1.UnauthorizedException();
|
|
58
|
+
}
|
|
59
|
+
if (yield this.securityState.isAccessTokenRevoked(payload.jti)) {
|
|
60
|
+
throw new common_1.UnauthorizedException();
|
|
45
61
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
62
|
+
const impersonating = originalClientId !== null;
|
|
63
|
+
if ((impersonating &&
|
|
64
|
+
(originalClientId !== tenant_1.NEWTECH_CLIENT_ID ||
|
|
65
|
+
homeClientId !== tenant_1.NEWTECH_CLIENT_ID ||
|
|
66
|
+
effectiveClientId === tenant_1.NEWTECH_CLIENT_ID ||
|
|
67
|
+
!((_b = signedUser.roles) === null || _b === void 0 ? void 0 : _b.includes(tenant_1.TENANT_IMPERSONATOR_ROLE)) ||
|
|
68
|
+
!signedUser.impersonatedAt ||
|
|
69
|
+
!signedUser.impersonationReason)) ||
|
|
70
|
+
(!impersonating && ((_c = signedUser.roles) === null || _c === void 0 ? void 0 : _c.includes(tenant_1.TENANT_IMPERSONATOR_ROLE)))) {
|
|
71
|
+
throw new common_1.UnauthorizedException();
|
|
72
|
+
}
|
|
73
|
+
const resolved = impersonating
|
|
74
|
+
? yield this.authorization.resolveImpersonation(signedUser.id, homeClientId, effectiveClientId)
|
|
75
|
+
: yield this.authorization.resolve(signedUser.id, effectiveClientId, homeClientId);
|
|
76
|
+
const { identity, snapshot } = resolved;
|
|
77
|
+
const isMasterTenantAdmin = !impersonating &&
|
|
78
|
+
snapshot.clientId === tenant_1.NEWTECH_CLIENT_ID &&
|
|
79
|
+
snapshot.roles.some((role) => role.moduleName.toLowerCase() === 'root' &&
|
|
80
|
+
role.roleName.toLowerCase() === 'sysadmin');
|
|
81
|
+
return {
|
|
82
|
+
id: identity.id,
|
|
83
|
+
first_name: identity.firstName,
|
|
84
|
+
username: identity.username,
|
|
85
|
+
last_name: identity.lastName,
|
|
86
|
+
division: identity.division,
|
|
87
|
+
lob: identity.lob,
|
|
88
|
+
fullName: identity.fullName,
|
|
89
|
+
ntgid: identity.ntgid,
|
|
90
|
+
profile: identity.profile,
|
|
91
|
+
password_expired: identity.passwordExpired,
|
|
92
|
+
viewEvaluations: identity.viewEvaluations,
|
|
93
|
+
ern: identity.ern,
|
|
94
|
+
homeClientId: identity.homeClientId,
|
|
95
|
+
clientId: snapshot.clientId,
|
|
96
|
+
clientAlias: snapshot.clientAlias,
|
|
97
|
+
clientName: snapshot.clientName,
|
|
98
|
+
jti: payload.jti,
|
|
99
|
+
tokenExpiresAt: payload.exp,
|
|
100
|
+
originalClientId,
|
|
101
|
+
impersonatedAt: impersonating ? signedUser.impersonatedAt : null,
|
|
102
|
+
impersonationReason: impersonating
|
|
103
|
+
? signedUser.impersonationReason
|
|
104
|
+
: null,
|
|
105
|
+
roles: Array.from(new Set(snapshot.roles.map((role) => role.roleName))),
|
|
106
|
+
privileges: snapshot.privileges,
|
|
107
|
+
isMasterTenantAdmin,
|
|
108
|
+
};
|
|
48
109
|
});
|
|
49
110
|
}
|
|
111
|
+
validTokenIdentifier(value) {
|
|
112
|
+
return /^[A-Za-z0-9._:-]{1,128}$/.test(value || '');
|
|
113
|
+
}
|
|
50
114
|
};
|
|
51
115
|
exports.JwtStrategy = JwtStrategy;
|
|
52
116
|
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
53
117
|
(0, common_1.Injectable)(),
|
|
54
|
-
|
|
55
|
-
|
|
118
|
+
__metadata("design:paramtypes", [tenant_1.TenantAuthorizationService,
|
|
119
|
+
tenant_1.TenantSecurityStateService])
|
|
56
120
|
], JwtStrategy);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoggedUser = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.LoggedUser = (0, common_1.createParamDecorator)((
|
|
5
|
+
exports.LoggedUser = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
6
6
|
const request = ctx.switchToHttp().getRequest();
|
|
7
|
-
return request
|
|
7
|
+
return request.user;
|
|
8
8
|
});
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { PublicRouteOptions } from '../tenant';
|
|
1
2
|
export declare const SKIP_JWT_AUTH_KEY = "skipJwtAuth";
|
|
2
|
-
export declare const
|
|
3
|
+
export declare const Public: (options?: PublicRouteOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
4
|
+
export declare const SkipJwtAuth: () => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SkipJwtAuth = exports.SKIP_JWT_AUTH_KEY = void 0;
|
|
3
|
+
exports.SkipJwtAuth = exports.Public = exports.SKIP_JWT_AUTH_KEY = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tenant_1 = require("../tenant");
|
|
5
6
|
exports.SKIP_JWT_AUTH_KEY = 'skipJwtAuth';
|
|
6
|
-
const
|
|
7
|
+
const Public = (options = { tenant: 'tenantless' }) => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.SKIP_JWT_AUTH_KEY, true), (0, common_1.SetMetadata)(tenant_1.PUBLIC_ROUTE_METADATA_KEY, options));
|
|
8
|
+
exports.Public = Public;
|
|
9
|
+
const SkipJwtAuth = () => (0, exports.Public)({ tenant: 'tenantless' });
|
|
7
10
|
exports.SkipJwtAuth = SkipJwtAuth;
|
package/dist/modules/index.d.ts
CHANGED
package/dist/modules/index.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./google-maps/google-maps.module"), exports);
|
|
|
21
21
|
__exportStar(require("./google-maps/google-maps.service"), exports);
|
|
22
22
|
__exportStar(require("./google-maps/google-maps.types"), exports);
|
|
23
23
|
__exportStar(require("./file-storage"), exports);
|
|
24
|
+
__exportStar(require("./tenant"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CurrentTenant: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentTenant = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tenant_context_errors_1 = require("./tenant-context.errors");
|
|
6
|
+
exports.CurrentTenant = (0, common_1.createParamDecorator)((_data, context) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const request = context.switchToHttp().getRequest();
|
|
9
|
+
const clientId = (_a = request.tenantContext) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
10
|
+
if (!Number.isInteger(clientId) || !clientId || clientId <= 0) {
|
|
11
|
+
throw new tenant_context_errors_1.MissingTenantContextError();
|
|
12
|
+
}
|
|
13
|
+
return clientId;
|
|
14
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './current-tenant.decorator';
|
|
2
|
+
export * from './master-tenant.decorator';
|
|
3
|
+
export * from './master-tenant.guard';
|
|
4
|
+
export * from './redis-tenant-state.store';
|
|
5
|
+
export * from './tenant-audit.types';
|
|
6
|
+
export * from './tenant-authorization.keys';
|
|
7
|
+
export * from './tenant-authorization.service';
|
|
8
|
+
export * from './tenant-authorization.store';
|
|
9
|
+
export * from './tenant-authorization.types';
|
|
10
|
+
export * from './tenant.constants';
|
|
11
|
+
export * from './tenant-context.interceptor';
|
|
12
|
+
export * from './tenant-context.errors';
|
|
13
|
+
export * from './tenant-context.service';
|
|
14
|
+
export * from './tenant-credential.guard';
|
|
15
|
+
export * from './tenant.module';
|
|
16
|
+
export * from './tenant-ownership.service';
|
|
17
|
+
export * from './tenant-query.helpers';
|
|
18
|
+
export * from './tenant-runner.service';
|
|
19
|
+
export * from './tenant-security-state.service';
|
|
20
|
+
export * from './tenant-security-state.store';
|
|
21
|
+
export * from './tenant.types';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./current-tenant.decorator"), exports);
|
|
18
|
+
__exportStar(require("./master-tenant.decorator"), exports);
|
|
19
|
+
__exportStar(require("./master-tenant.guard"), exports);
|
|
20
|
+
__exportStar(require("./redis-tenant-state.store"), exports);
|
|
21
|
+
__exportStar(require("./tenant-audit.types"), exports);
|
|
22
|
+
__exportStar(require("./tenant-authorization.keys"), exports);
|
|
23
|
+
__exportStar(require("./tenant-authorization.service"), exports);
|
|
24
|
+
__exportStar(require("./tenant-authorization.store"), exports);
|
|
25
|
+
__exportStar(require("./tenant-authorization.types"), exports);
|
|
26
|
+
__exportStar(require("./tenant.constants"), exports);
|
|
27
|
+
__exportStar(require("./tenant-context.interceptor"), exports);
|
|
28
|
+
__exportStar(require("./tenant-context.errors"), exports);
|
|
29
|
+
__exportStar(require("./tenant-context.service"), exports);
|
|
30
|
+
__exportStar(require("./tenant-credential.guard"), exports);
|
|
31
|
+
__exportStar(require("./tenant.module"), exports);
|
|
32
|
+
__exportStar(require("./tenant-ownership.service"), exports);
|
|
33
|
+
__exportStar(require("./tenant-query.helpers"), exports);
|
|
34
|
+
__exportStar(require("./tenant-runner.service"), exports);
|
|
35
|
+
__exportStar(require("./tenant-security-state.service"), exports);
|
|
36
|
+
__exportStar(require("./tenant-security-state.store"), exports);
|
|
37
|
+
__exportStar(require("./tenant.types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MasterTenant: () => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MasterTenant = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tenant_constants_1 = require("./tenant.constants");
|
|
6
|
+
const MasterTenant = () => (0, common_1.SetMetadata)(tenant_constants_1.MASTER_TENANT_METADATA_KEY, true);
|
|
7
|
+
exports.MasterTenant = MasterTenant;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
export declare class MasterTenantGuard implements CanActivate {
|
|
4
|
+
private readonly reflector;
|
|
5
|
+
constructor(reflector: Reflector);
|
|
6
|
+
canActivate(context: ExecutionContext): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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.MasterTenantGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const tenant_constants_1 = require("./tenant.constants");
|
|
16
|
+
let MasterTenantGuard = class MasterTenantGuard {
|
|
17
|
+
constructor(reflector) {
|
|
18
|
+
this.reflector = reflector;
|
|
19
|
+
}
|
|
20
|
+
canActivate(context) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
const required = this.reflector.getAllAndOverride(tenant_constants_1.MASTER_TENANT_METADATA_KEY, [context.getHandler(), context.getClass()]);
|
|
23
|
+
if (!required) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const request = context.switchToHttp().getRequest();
|
|
27
|
+
if (!request.user || request.user === true) {
|
|
28
|
+
throw new common_1.UnauthorizedException();
|
|
29
|
+
}
|
|
30
|
+
const effectiveClientId = ((_a = request.tenantContext) === null || _a === void 0 ? void 0 : _a.clientId) || request.user.clientId;
|
|
31
|
+
const originalClientId = (_d = (_c = (_b = request.tenantContext) === null || _b === void 0 ? void 0 : _b.originalClientId) !== null && _c !== void 0 ? _c : request.user.originalClientId) !== null && _d !== void 0 ? _d : null;
|
|
32
|
+
if (effectiveClientId !== tenant_constants_1.NEWTECH_CLIENT_ID ||
|
|
33
|
+
originalClientId !== null ||
|
|
34
|
+
!request.user.isMasterTenantAdmin) {
|
|
35
|
+
throw new common_1.ForbiddenException();
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.MasterTenantGuard = MasterTenantGuard;
|
|
41
|
+
exports.MasterTenantGuard = MasterTenantGuard = __decorate([
|
|
42
|
+
(0, common_1.Injectable)(),
|
|
43
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
44
|
+
], MasterTenantGuard);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { TenantAuthorizationStore } from './tenant-authorization.store';
|
|
3
|
+
import { TenantAuthorizationSnapshot } from './tenant-authorization.types';
|
|
4
|
+
import { TenantSecurityStateStore } from './tenant-security-state.store';
|
|
5
|
+
export declare class RedisTenantStateStore implements TenantAuthorizationStore, TenantSecurityStateStore, OnModuleDestroy {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private client;
|
|
8
|
+
get(key: string): Promise<TenantAuthorizationSnapshot | null>;
|
|
9
|
+
set(key: string, value: TenantAuthorizationSnapshot, ttlSeconds: number): Promise<void>;
|
|
10
|
+
delete(key: string): Promise<void>;
|
|
11
|
+
deleteMany(keys: readonly string[]): Promise<void>;
|
|
12
|
+
isRevoked(key: string): Promise<boolean>;
|
|
13
|
+
revoke(key: string, ttlSeconds: number): Promise<void>;
|
|
14
|
+
createPreAuth(key: string, userId: number, ttlSeconds: number): Promise<void>;
|
|
15
|
+
consumePreAuth(key: string, userId: number): Promise<boolean>;
|
|
16
|
+
onModuleDestroy(): Promise<void>;
|
|
17
|
+
private execute;
|
|
18
|
+
private getClient;
|
|
19
|
+
private positiveInteger;
|
|
20
|
+
private isAuthorizationSnapshot;
|
|
21
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var RedisTenantStateStore_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.RedisTenantStateStore = void 0;
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const ioredis_1 = require("ioredis");
|
|
22
|
+
let RedisTenantStateStore = RedisTenantStateStore_1 = class RedisTenantStateStore {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.logger = new common_1.Logger(RedisTenantStateStore_1.name);
|
|
25
|
+
this.client = null;
|
|
26
|
+
}
|
|
27
|
+
get(key) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const serialized = yield this.execute((client) => client.get(key));
|
|
30
|
+
if (serialized === null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const snapshot = JSON.parse(serialized);
|
|
34
|
+
if (!this.isAuthorizationSnapshot(snapshot)) {
|
|
35
|
+
throw new Error('Invalid cached authorization snapshot');
|
|
36
|
+
}
|
|
37
|
+
return snapshot;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
set(key, value, ttlSeconds) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield this.execute((client) => client.set(key, JSON.stringify(value), 'EX', ttlSeconds));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
delete(key) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield this.execute((client) => client.del(key));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
deleteMany(keys) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
for (let offset = 0; offset < keys.length; offset += 500) {
|
|
53
|
+
const batch = keys.slice(offset, offset + 500);
|
|
54
|
+
yield this.execute((client) => client.del(...batch));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
isRevoked(key) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return (yield this.execute((client) => client.exists(key))) === 1;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
revoke(key, ttlSeconds) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
yield this.execute((client) => client.set(key, '1', 'EX', ttlSeconds));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
createPreAuth(key, userId, ttlSeconds) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const result = yield this.execute((client) => client.set(key, String(userId), 'EX', ttlSeconds, 'NX'));
|
|
71
|
+
if (result !== 'OK') {
|
|
72
|
+
throw new Error('Pre-auth security state already exists');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
consumePreAuth(key, userId) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const result = yield this.execute((client) => client.eval('if redis.call("GET", KEYS[1]) == ARGV[1] then return redis.call("DEL", KEYS[1]) else return 0 end', 1, key, String(userId)));
|
|
79
|
+
return Number(result) === 1;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
onModuleDestroy() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
if (!this.client) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const client = this.client;
|
|
88
|
+
this.client = null;
|
|
89
|
+
try {
|
|
90
|
+
if (client.status === 'ready') {
|
|
91
|
+
yield client.quit();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
client.disconnect();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
client.disconnect();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
execute(operation) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const client = this.getClient();
|
|
105
|
+
return operation(client);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getClient() {
|
|
109
|
+
if (this.client && this.client.status !== 'end') {
|
|
110
|
+
return this.client;
|
|
111
|
+
}
|
|
112
|
+
const url = process.env.TENANT_REDIS_URL || process.env.REDIS_URL;
|
|
113
|
+
const host = process.env.TENANT_REDIS_HOST || process.env.REDIS_HOST;
|
|
114
|
+
if (!url && !host) {
|
|
115
|
+
throw new Error('Tenant Redis is not configured');
|
|
116
|
+
}
|
|
117
|
+
const options = {
|
|
118
|
+
connectTimeout: this.positiveInteger(process.env.TENANT_REDIS_CONNECT_TIMEOUT_MS, 2000),
|
|
119
|
+
maxRetriesPerRequest: 1,
|
|
120
|
+
username: process.env.TENANT_REDIS_USERNAME || process.env.REDIS_USERNAME,
|
|
121
|
+
password: process.env.TENANT_REDIS_PASSWORD || process.env.REDIS_PASSWORD,
|
|
122
|
+
tls: process.env.TENANT_REDIS_TLS === 'true' ? {} : undefined,
|
|
123
|
+
};
|
|
124
|
+
this.client = url
|
|
125
|
+
? new ioredis_1.default(url, options)
|
|
126
|
+
: new ioredis_1.default(Object.assign(Object.assign({}, options), { host, port: this.positiveInteger(process.env.TENANT_REDIS_PORT || process.env.REDIS_PORT, 6379) }));
|
|
127
|
+
this.client.on('error', () => {
|
|
128
|
+
this.logger.error('Tenant Redis connection is unavailable');
|
|
129
|
+
});
|
|
130
|
+
return this.client;
|
|
131
|
+
}
|
|
132
|
+
positiveInteger(value, fallback) {
|
|
133
|
+
const parsed = Number(value);
|
|
134
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
135
|
+
}
|
|
136
|
+
isAuthorizationSnapshot(value) {
|
|
137
|
+
var _a;
|
|
138
|
+
return Boolean(value &&
|
|
139
|
+
Number.isInteger(value.userId) &&
|
|
140
|
+
value.userId > 0 &&
|
|
141
|
+
Number.isInteger(value.homeClientId) &&
|
|
142
|
+
value.homeClientId > 0 &&
|
|
143
|
+
Number.isInteger(value.clientId) &&
|
|
144
|
+
value.clientId > 0 &&
|
|
145
|
+
typeof value.clientName === 'string' &&
|
|
146
|
+
typeof value.clientAlias === 'string' &&
|
|
147
|
+
Array.isArray(value.roles) &&
|
|
148
|
+
value.roles.length > 0 &&
|
|
149
|
+
value.roles.every((role) => Number.isInteger(role.roleId) &&
|
|
150
|
+
role.roleId > 0 &&
|
|
151
|
+
typeof role.roleName === 'string' &&
|
|
152
|
+
Number.isInteger(role.moduleId) &&
|
|
153
|
+
role.moduleId > 0 &&
|
|
154
|
+
typeof role.moduleName === 'string') &&
|
|
155
|
+
Array.isArray(value.privileges) &&
|
|
156
|
+
value.privileges.every((privilege) => typeof privilege === 'string') &&
|
|
157
|
+
((_a = value.identity) === null || _a === void 0 ? void 0 : _a.id) === value.userId &&
|
|
158
|
+
value.identity.homeClientId === value.homeClientId &&
|
|
159
|
+
typeof value.cachedAt === 'string');
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
exports.RedisTenantStateStore = RedisTenantStateStore;
|
|
163
|
+
exports.RedisTenantStateStore = RedisTenantStateStore = RedisTenantStateStore_1 = __decorate([
|
|
164
|
+
(0, common_1.Injectable)()
|
|
165
|
+
], RedisTenantStateStore);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TenantAuthenticationType } from './tenant.types';
|
|
2
|
+
export interface TenantAuditMetadata {
|
|
3
|
+
actorUserId: number | null;
|
|
4
|
+
originalClientId: number | null;
|
|
5
|
+
effectiveClientId: number;
|
|
6
|
+
authenticationType: TenantAuthenticationType;
|
|
7
|
+
impersonationReason: string | null;
|
|
8
|
+
correlationId: string;
|
|
9
|
+
service: string;
|
|
10
|
+
operation: string;
|
|
11
|
+
route?: string;
|
|
12
|
+
entityType?: string;
|
|
13
|
+
entityId?: string | number;
|
|
14
|
+
result?: 'success' | 'failure';
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tenantAuthorizationKey = tenantAuthorizationKey;
|
|
4
|
+
exports.revokedAccessTokenKey = revokedAccessTokenKey;
|
|
5
|
+
exports.preAuthTokenKey = preAuthTokenKey;
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const TOKEN_IDENTIFIER = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
8
|
+
function positiveInteger(value, field) {
|
|
9
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
10
|
+
throw new common_1.UnauthorizedException(`Invalid ${field}`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function tokenIdentifier(value) {
|
|
15
|
+
if (!TOKEN_IDENTIFIER.test(value || '')) {
|
|
16
|
+
throw new common_1.UnauthorizedException('Invalid token identifier');
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function tenantAuthorizationKey(clientId, userId) {
|
|
21
|
+
return `client:${positiveInteger(clientId, 'clientId')}:authz:user:${positiveInteger(userId, 'userId')}`;
|
|
22
|
+
}
|
|
23
|
+
function revokedAccessTokenKey(jti) {
|
|
24
|
+
return `security:access-token:revoked:${tokenIdentifier(jti)}`;
|
|
25
|
+
}
|
|
26
|
+
function preAuthTokenKey(jti) {
|
|
27
|
+
return `security:pre-auth:${tokenIdentifier(jti)}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { Client } from '../../entities/client.entity';
|
|
3
|
+
import { UserRoles } from '../../entities/user-roles.entity';
|
|
4
|
+
import { Users } from '../../entities/usr.entity';
|
|
5
|
+
import { TenantAuthorizationStore } from './tenant-authorization.store';
|
|
6
|
+
import { ResolvedTenantAuthorization } from './tenant-authorization.types';
|
|
7
|
+
export declare const TENANT_AUTHORIZATION_TTL_SECONDS = 60;
|
|
8
|
+
export declare class TenantAuthorizationService {
|
|
9
|
+
private readonly store;
|
|
10
|
+
private readonly userRepository;
|
|
11
|
+
private readonly clientRepository;
|
|
12
|
+
private readonly userRoleRepository;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
constructor(store: TenantAuthorizationStore, userRepository: Repository<Users>, clientRepository: Repository<Client>, userRoleRepository: Repository<UserRoles>);
|
|
15
|
+
resolve(userId: number, clientId: number, expectedHomeClientId: number): Promise<ResolvedTenantAuthorization>;
|
|
16
|
+
resolveImpersonation(userId: number, homeClientId: number, targetClientId: number): Promise<ResolvedTenantAuthorization>;
|
|
17
|
+
invalidate(userId: number, clientId: number): Promise<void>;
|
|
18
|
+
invalidateMany(clientId: number, userIds: readonly number[]): Promise<void>;
|
|
19
|
+
private loadFromDatabase;
|
|
20
|
+
private readCache;
|
|
21
|
+
private writeCache;
|
|
22
|
+
private assertPositiveInteger;
|
|
23
|
+
private isFresh;
|
|
24
|
+
}
|