changed OICP authorization
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -8,10 +8,14 @@ import ChargingStation from '../types/ChargingStation';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
import CpoOCPIClient from '../client/ocpi/CpoOCPIClient';
+import CpoOICPClient from '../client/oicp/CpoOICPClient';
import Logging from '../utils/Logging';
import NotificationHandler from '../notification/NotificationHandler';
import OCPIClientFactory from '../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../types/ocpi/OCPIRole';
+import OICPClientFactory from '../client/oicp/OICPClientFactory';
+import { OICPDefaultTagId } from '../types/oicp/OICPIdentification';
+import { OICPRole } from '../types/oicp/OICPRole';
import { PricingSettingsType } from '../types/Setting';
import { ServerAction } from '../types/Server';
import SessionHashService from '../server/rest/v1/service/SessionHashService';
@@ -767,14 +771,36 @@ export default class Authorizations {
}
// Get Tag
let tag = await TagStorage.getTag(tenantID, tagID, { withUser: true });
- if (!tag) {
- // Unknown User -> OICP component activated -> return virtual user (do not create inactive Tag)
+
+ if (!tag || !tag?.active) {
+ // Check OICP User
+ // OICP Active?
if (Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) {
- // FIXME: No tag will be created if OICP component is activated. What if unknown user is no OICP User? No information beforehand.
- // You have to try the OICP authorization first (with a successful OICP authorization the session starts)
- // Problem: Even if the user is no roaming user, the OICP virtual user will be returned
- return UserStorage.getUserByEmail(tenantID, Constants.OICP_VIRTUAL_USER_EMAIL);
+ // OICP user
+ const virtualOICPUser = await UserStorage.getUserByEmail(tenantID, Constants.OICP_VIRTUAL_USER_EMAIL);
+
+ if (tagID === OICPDefaultTagId.RemoteIdentification) {
+ return virtualOICPUser;
}
+ const oicpClient = await OICPClientFactory.getAvailableOicpClient(tenant, OICPRole.CPO) as CpoOICPClient;
+ if (!oicpClient) {
+ throw new BackendError({
+ action: ServerAction.AUTHORIZE,
+ module: MODULE_NAME,
+ method: 'handleAuthorize',
+ message: 'OICP component requires at least one CPO endpoint to start a Session'
+ });
+ }
+ // Call Hubject
+ const response = await oicpClient.authorizeStart(tagID);
+ if (response.SessionID) {
+ virtualOICPUser.authorizationID = response.SessionID;
+ return virtualOICPUser;
+ }
+ }
+ }
+
+ if (!tag) {
// Create the tag as inactive
tag = {
id: tagID,

MODIFY
src/client/oicp/CpoOICPClient.ts
src/client/oicp/CpoOICPClient.ts
@@ -595,15 +595,14 @@ export default class CpoOICPClient extends OICPClient {
/**
* ERoaming Authorize Start
*/
- public async authorizeStart(tagID: string, user: User, transactionId?: number): Promise<OICPAuthorizeStartCpoReceive> {
+ public async authorizeStart(tagID: string, transactionId?: number): Promise<OICPAuthorizeStartCpoReceive> {
let authorizeResponse = {} as OICPAuthorizeStartCpoReceive;
let requestError: any;
if (!tagID) {
throw new BackendError({
action: ServerAction.OICP_AUTHORIZE_START,
message: 'No Tag ID for OICP Authorization',
- module: MODULE_NAME, method: 'authorizeStart',
- user: user
+ module: MODULE_NAME, method: 'authorizeStart'
});
}
const identification = OICPUtils.convertTagID2OICPIdentification(tagID);
@@ -623,7 +622,6 @@ export default class CpoOICPClient extends OICPClient {
// Log
Logging.logDebug({
tenantID: this.tenant.id,
- user: user,
action: ServerAction.OICP_AUTHORIZE_START,
message: 'Start Authorization',
module: MODULE_NAME, method: 'authorizeStart',
@@ -641,7 +639,6 @@ export default class CpoOICPClient extends OICPClient {
}
if (requestError) {
throw new BackendError({
- user: user,
action: ServerAction.OICP_AUTHORIZE_START,
message: `'authorizeStart' Error: '${authorizeResponse?.StatusCode?.AdditionalInfo ? authorizeResponse?.StatusCode?.AdditionalInfo : authorizeResponse?.StatusCode?.Description}' '${String(requestError?.message)}`,
module: MODULE_NAME, method: 'authorizeStart',
@@ -652,12 +649,12 @@ export default class CpoOICPClient extends OICPClient {
payload: payload
}
});
- } else if (authorizeResponse?.AuthorizationStatus !== OICPAuthorizationStatus.Authorized) {
+ }
+ if (authorizeResponse?.AuthorizationStatus !== OICPAuthorizationStatus.Authorized) {
throw new BackendError({
- user: user,
action: ServerAction.OICP_AUTHORIZE_START,
module: MODULE_NAME, method: 'authorizeStart',
- message: `User '${user.id}' with Authorization '${tagID}' cannot ${TransactionAction.START} Transaction thought OICP protocol due to missing Authorization`,
+ message: `User with Authorization '${tagID}' cannot ${TransactionAction.START} Transaction thought OICP protocol due to missing Authorization`,
detailedMessages: {
response: authorizeResponse
}
@@ -666,9 +663,8 @@ export default class CpoOICPClient extends OICPClient {
// Log
Logging.logInfo({
tenantID: this.tenant.id,
- user: user,
action: ServerAction.OICP_AUTHORIZE_START,
- message: `User '${user.id}' with Authorization '${tagID}' authorized thought OICP protocol`,
+ message: `User with Authorization '${tagID}' authorized thought OICP protocol`,
module: MODULE_NAME, method: 'authorizeStart',
detailedMessages: { authorizeResponse }
});

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -481,29 +481,10 @@ export default class OCPPService {
const user = await Authorizations.isAuthorizedOnChargingStation(headers.tenantID, chargingStation,
authorize.idTag, ServerAction.AUTHORIZE, Action.AUTHORIZE);
// Roaming User
- if (user && !user.issuer) {
+ if (user && !user.issuer && user.authorizationID) {
if (chargingStation.public) {
- const tenant: Tenant = await TenantStorage.getTenant(headers.tenantID);
- // OCPI User
- if (Utils.isTenantComponentActive(tenant, TenantComponents.OCPI) && user.authorizationID) {
// Keep the Auth ID
authorize.authorizationId = user.authorizationID;
- } else if (Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) {
- // OICP user
- const oicpClient = await OICPClientFactory.getAvailableOicpClient(tenant, OICPRole.CPO) as CpoOICPClient;
- if (!oicpClient) {
- throw new BackendError({
- user: user,
- action: ServerAction.AUTHORIZE,
- module: MODULE_NAME,
- method: 'handleAuthorize',
- message: 'OICP component requires at least one CPO endpoint to start a Session'
- });
- }
- // Call Hubject
- const response = await oicpClient.authorizeStart(authorize.idTag, user);
- authorize.authorizationId = response.SessionID;
- }
} else {
throw new BackendError({
user: user,
@@ -1146,8 +1127,6 @@ export default class OCPPService {
}
// OICP: Post the CDR
if (lastTransaction.oicpData?.session) {
- const user = await UserStorage.getUser(tenantID, lastTransaction.userID);
- lastTransaction.user = user;
await this.checkAndSendOICPTransactionCdr(tenantID, lastTransaction, chargingStation);
}
// Save

changed OICP authorization