- { errorResponse: OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_REJECTED }
- );
- }
- }
-
- /**
- * Check for authorized access on a connector with given ConnectorId and idTag for the user
- * @param {ChargingStation} chargingStation - Charging Station working on incoming request
- * @param {number} ConnectorId - Identifier of the connector at the charging station
- * @param {string} idTag - Identifier of the user
- * @param {string} parentIdTag - Identifier for a group of idTags, which is optional
- * @returns {Promise<boolean>} - 'true' if user is authorized, 'false' otherwise
- */
- private async isAuthorized(
- chargingStation: ChargingStation,
- connectorId: number,
- idTag: string,
- parentIdTag?: string
- ): Promise<boolean> {
- let authorized = false;
- const connectorStatus = chargingStation.getConnectorStatus(connectorId);
- if (
- chargingStation.getLocalAuthListEnabled() === true &&
- chargingStation.hasIdTags() === true &&
- Utils.isNotEmptyString(
- chargingStation.idTagsCache
- .getIdTags(ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo))
- ?.find((tag) => tag === idTag)
- )
- ) {
- connectorStatus.localAuthorizeIdTag = idTag;
- connectorStatus.idTagLocalAuthorized = true;
- authorized = true;
- } else if (chargingStation.getMustAuthorizeAtRemoteStart() === true) {
- connectorStatus.authorizeIdTag = idTag;
- const authorizeResponse: OCPP16AuthorizeResponse =
- await chargingStation.ocppRequestService.requestHandler<
- OCPP16AuthorizeRequest,
- OCPP16AuthorizeResponse
- >(chargingStation, OCPP16RequestCommand.AUTHORIZE, {
- idTag: idTag,
- });
- if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- authorized = true;
- }
- } else {
- logger.warn(
- `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
- );
- }
- return authorized;
- }
-
- private async handleReservedRemoteStartTransaction(
- chargingStation: ChargingStation,
- connectorId: number,
- commandPayload: RemoteStartTransactionRequest
- ): Promise<GenericResponse> {
- const reservation = chargingStation.getReservationByConnectorId(connectorId);
- if (
- !Utils.isUndefined(reservation) &&
- (await this.isAuthorized(chargingStation, connectorId, commandPayload.idTag)) &&
- reservation.idTag === commandPayload.idTag
- ) {
- const remoteStartTransactionLogMsg = `${chargingStation.logPrefix()} Transaction remotely STARTED on ${
- chargingStation.stationInfo.chargingStationId
- }#${connectorId.toString()} for idTag '${commandPayload.idTag}'`;
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Preparing
- );
- if (
- this.setRemoteStartTransactionChargingProfile(
- chargingStation,
- connectorId,
- commandPayload.chargingProfile
- ) === true
- ) {
- chargingStation.getConnectorStatus(connectorId).transactionRemoteStarted = true;
- if (
- (
- await chargingStation.ocppRequestService.requestHandler<
- OCPP16StartTransactionRequest,
- OCPP16StartTransactionResponse
- >(chargingStation, OCPP16RequestCommand.START_TRANSACTION, {
- connectorId: connectorId,
- idTag: commandPayload.idTag,
- reservationId: reservation.reservationId,
- })
- ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
- ) {
- logger.debug(remoteStartTransactionLogMsg);
- return OCPP16Constants.OCPP_RESPONSE_ACCEPTED;
- }
- }