Handle OICP/OCPI cannot be both activated + Handle user in master tenant with new auth framework
MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -366,7 +366,7 @@ export default class CentralRestServerService {
// Parse the action
const action = req.params.action as ServerAction;
// Check if User has been updated and require new login
- if ((await SessionHashService.isSessionHashUpdated(req, res, next))) {
+ if ((await SessionHashService.areTokenUserAndTenantStillValid(req, res, next))) {
return;
}
// Check HTTP Verbs

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -60,7 +60,7 @@ export default class AuthService {
public static async checkSessionHash(req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if User has been updated and require new login
- if (!await SessionHashService.isSessionHashUpdated(req, res, next)) {
+ if (!await SessionHashService.areTokenUserAndTenantStillValid(req, res, next)) {
next();
}
}

MODIFY
src/server/rest/v1/service/SessionHashService.ts
src/server/rest/v1/service/SessionHashService.ts
import { NextFunction, Request, Response } from 'express';
+import User, { UserStatus } from '../../../../types/User';
import AppError from '../../../../exception/AppError';
import Constants from '../../../../utils/Constants';
@@ -8,33 +9,39 @@ import Logging from '../../../../utils/Logging';
import { ServerAction } from '../../../../types/Server';
import Tenant from '../../../../types/Tenant';
import TenantStorage from '../../../../storage/mongodb/TenantStorage';
-import User from '../../../../types/User';
import UserStorage from '../../../../storage/mongodb/UserStorage';
import Utils from '../../../../utils/Utils';
const MODULE_NAME = 'SessionHashService';
export default class SessionHashService {
- public static async isSessionHashUpdated(req: Request, res: Response, next: NextFunction): Promise<boolean> {
+ public static async areTokenUserAndTenantStillValid(req: Request, res: Response, next: NextFunction): Promise<boolean> {
// Get tenant id, user id and hash ID
const userID = req.user.id;
const tenantID = req.user.tenantID;
const userHashID = req.user.userHashID;
const tenantHashID = req.user.tenantHashID;
- // No session hash in master tenant
+ try {
+ // Get Tenant
+ let tenant: Tenant;
if (tenantID === Constants.DEFAULT_TENANT) {
- return false;
+ tenant = { id: Constants.DEFAULT_TENANT } as Tenant;
+ } else {
+ tenant = await TenantStorage.getTenant(tenantID);
}
- const tenant = await TenantStorage.getTenant(tenantID);
+ // Get User
const user = await UserStorage.getUser(tenantID, userID);
- try {
// User or Tenant no longer exists
if (!tenant || !user) {
return true;
}
- // Set
+ // Set in HTTP request
req.user.user = user;
req.tenant = tenant;
+ // No session hash in master tenant
+ if (tenantID === Constants.DEFAULT_TENANT) {
+ return false;
+ }
// Check User's Hash
if (userHashID !== this.buildUserHashID(user)) {
throw new AppError({

MODIFY
src/server/rest/v1/validator/TenantValidator.ts
src/server/rest/v1/validator/TenantValidator.ts
@@ -77,6 +77,16 @@ export default class TenantValidator extends SchemaValidator {
private validateComponentDependencies(tenant: Tenant): void {
if (tenant.components) {
+ // Both OICP and OCPI cannot be active
+ if (tenant.components.oicp && tenant.components.ocpi &&
+ tenant.components.oicp.active && tenant.components.ocpi.active) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'Both OICP and OCPI roaming components cannot be active',
+ module: this.moduleName, method: 'validateComponentDependencies'
+ });
+ }
// Smart Charging active: Organization must be active
if (tenant.components.smartCharging && tenant.components.organization &&
tenant.components.smartCharging.active && !tenant.components.organization.active) {
@@ -84,7 +94,7 @@ export default class TenantValidator extends SchemaValidator {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Organization must be active to use the Smart Charging component',
- module: this.moduleName, method: 'validateTenantUpdateRequestSuperAdmin'
+ module: this.moduleName, method: 'validateComponentDependencies'
});
}
// Asset active: Organization must be active
@@ -94,7 +104,7 @@ export default class TenantValidator extends SchemaValidator {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Organization must be active to use the Asset component',
- module: this.moduleName, method: 'validateTenantUpdateRequestSuperAdmin'
+ module: this.moduleName, method: 'validateComponentDependencies'
});
}
// Car Connector active: Car must be active
@@ -104,7 +114,7 @@ export default class TenantValidator extends SchemaValidator {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Car must be active to use the Car Connector component',
- module: this.moduleName, method: 'validateTenantUpdateRequestSuperAdmin'
+ module: this.moduleName, method: 'validateComponentDependencies'
});
}
// Billing active: Pricing must be active
@@ -114,7 +124,7 @@ export default class TenantValidator extends SchemaValidator {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Pricing must be active to use the Billing component',
- module: this.moduleName, method: 'validateTenantUpdateRequestSuperAdmin'
+ module: this.moduleName, method: 'validateComponentDependencies'
});
}
// Refund active: Pricing must be active
@@ -124,7 +134,7 @@ export default class TenantValidator extends SchemaValidator {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Pricing must be active to use the Refund component',
- module: this.moduleName, method: 'validateTenantUpdateRequestSuperAdmin'
+ module: this.moduleName, method: 'validateComponentDependencies'
});
}
}

Handle OICP/OCPI cannot be both activated + Handle user in master tenant with new auth framework