truncateId,
} from '../../../utils/index.js'
import { AuthContext } from '../auth/index.js'
-import { isIdTagAuthorized } from '../IdTagAuthorization.js'
import { OCPPConstants } from '../OCPPConstants.js'
import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService.js'
+import { isIdTagAuthorized } from '../OCPPServiceOperations.js'
import {
buildMeterValue,
createPayloadValidatorMap,
+++ /dev/null
-import type { ChargingStation } from '../../charging-station/index.js'
-
-import { logger, truncateId } from '../../utils/index.js'
-import {
- AuthContext,
- AuthenticationMethod,
- AuthorizationStatus,
- IdentifierType,
- OCPPAuthServiceFactory,
-} from './auth/index.js'
-
-export const isIdTagAuthorized = async (
- chargingStation: ChargingStation,
- connectorId: number,
- idTag: string,
- context?: AuthContext
-): Promise<boolean> => {
- try {
- logger.debug(
- `${chargingStation.logPrefix()} Authorizing idTag '${truncateId(idTag)}' on connector ${connectorId.toString()}`
- )
-
- const authService = OCPPAuthServiceFactory.getInstance(chargingStation)
-
- const authResult = await authService.authorize({
- allowOffline: false,
- connectorId,
- context: context ?? AuthContext.TRANSACTION_START,
- identifier: {
- type: IdentifierType.ID_TAG,
- value: idTag,
- },
- timestamp: new Date(),
- })
-
- logger.debug(
- `${chargingStation.logPrefix()} Authorization result for idTag '${truncateId(idTag)}': ${authResult.status} using ${authResult.method} method`
- )
-
- if (authResult.status === AuthorizationStatus.ACCEPTED) {
- const connectorStatus = chargingStation.getConnectorStatus(connectorId)
- if (connectorStatus != null) {
- switch (authResult.method) {
- case AuthenticationMethod.CACHE:
- case AuthenticationMethod.LOCAL_LIST:
- case AuthenticationMethod.OFFLINE_FALLBACK:
- connectorStatus.localAuthorizeIdTag = idTag
- connectorStatus.idTagLocalAuthorized = true
- break
- case AuthenticationMethod.CERTIFICATE_BASED:
- case AuthenticationMethod.NONE:
- case AuthenticationMethod.REMOTE_AUTHORIZATION:
- break
- }
- }
- return true
- }
-
- return false
- } catch (error) {
- logger.error(`${chargingStation.logPrefix()} Authorization failed`, error)
- return false
- }
-}
type StartTransactionResult,
type StopTransactionResult,
} from '../../types/index.js'
-import { generateUUID, logger } from '../../utils/index.js'
+import { generateUUID, logger, truncateId } from '../../utils/index.js'
import { OCPP16ServiceUtils } from './1.6/OCPP16ServiceUtils.js'
import { OCPP20ServiceUtils } from './2.0/OCPP20ServiceUtils.js'
+import {
+ AuthContext,
+ AuthenticationMethod,
+ AuthorizationStatus as AuthStatus,
+ IdentifierType,
+ OCPPAuthServiceFactory,
+} from './auth/index.js'
import { mapStopReasonToOCPP20 } from './OCPPServiceUtils.js'
/**
return undefined
}
}
+
+export const isIdTagAuthorized = async (
+ chargingStation: ChargingStation,
+ connectorId: number,
+ idTag: string,
+ context?: AuthContext
+): Promise<boolean> => {
+ try {
+ logger.debug(
+ `${chargingStation.logPrefix()} Authorizing idTag '${truncateId(idTag)}' on connector ${connectorId.toString()}`
+ )
+
+ const authService = OCPPAuthServiceFactory.getInstance(chargingStation)
+
+ const authResult = await authService.authorize({
+ allowOffline: false,
+ connectorId,
+ context: context ?? AuthContext.TRANSACTION_START,
+ identifier: {
+ type: IdentifierType.ID_TAG,
+ value: idTag,
+ },
+ timestamp: new Date(),
+ })
+
+ logger.debug(
+ `${chargingStation.logPrefix()} Authorization result for idTag '${truncateId(idTag)}': ${authResult.status} using ${authResult.method} method`
+ )
+
+ if (authResult.status === AuthStatus.ACCEPTED) {
+ const connectorStatus = chargingStation.getConnectorStatus(connectorId)
+ if (connectorStatus != null) {
+ switch (authResult.method) {
+ case AuthenticationMethod.CACHE:
+ case AuthenticationMethod.LOCAL_LIST:
+ case AuthenticationMethod.OFFLINE_FALLBACK:
+ connectorStatus.localAuthorizeIdTag = idTag
+ connectorStatus.idTagLocalAuthorized = true
+ break
+ case AuthenticationMethod.CERTIFICATE_BASED:
+ case AuthenticationMethod.NONE:
+ case AuthenticationMethod.REMOTE_AUTHORIZATION:
+ break
+ }
+ }
+ return true
+ }
+
+ return false
+ } catch (error) {
+ logger.error(`${chargingStation.logPrefix()} Authorization failed`, error)
+ return false
+ }
+}
export { buildTransactionEvent, OCPP20ServiceUtils } from './2.0/OCPP20ServiceUtils.js'
export { OCPP20VariableManager } from './2.0/OCPP20VariableManager.js'
export { OCPPAuthServiceFactory } from './auth/index.js'
-export { isIdTagAuthorized } from './IdTagAuthorization.js'
export { OCPPConstants } from './OCPPConstants.js'
export { OCPPIncomingRequestService } from './OCPPIncomingRequestService.js'
export { OCPPRequestService } from './OCPPRequestService.js'
export {
buildBootNotificationRequest,
flushQueuedTransactionMessages,
+ isIdTagAuthorized,
startTransactionOnConnector,
stopRunningTransactions,
stopTransactionOnConnector,
AuthorizationStatus,
OCPPAuthServiceFactory,
} from '../../../src/charging-station/ocpp/auth/index.js'
-import { isIdTagAuthorized } from '../../../src/charging-station/ocpp/IdTagAuthorization.js'
+import { isIdTagAuthorized } from '../../../src/charging-station/ocpp/OCPPServiceOperations.js'
import { OCPPVersion } from '../../../src/types/index.js'
import { standardCleanup } from '../../helpers/TestLifecycleHelpers.js'
import { createMockChargingStation } from '../ChargingStationTestUtils.js'