@Override public IdentifyingToken validate(IdentifyingToken identifyingToken, @Nullable ChargingStationId chargingStationId) { LOG.debug("validate({}, {})", identifyingToken.getToken(), chargingStationId); String stationIdentifier = null; if (chargingStationId != null) { stationIdentifier = chargingStationId.getId(); } LocalToken localToken = tokenRepository.findToken(identifyingToken.getToken(), stationIdentifier); if (localToken != null) { if (localToken.isValid()) { LOG.debug("Token valid: {}", localToken.getHiddenId()); return new TextualToken(localToken.getHiddenId(), IdentifyingToken.AuthenticationStatus.ACCEPTED, null, localToken.getVisualId()); } else { LOG.debug("Token not valid: {}", localToken.getHiddenId()); } } else { LOG.debug("Token {} not found for charging station {}", identifyingToken.getToken(), chargingStationId); } return identifyingToken; }
private Set<LocalAuthorization> toLocalAuthorizationSet(Set<IdentifyingToken> identifyingTokens) { Set<LocalAuthorization> localAuthorizations = Sets.newHashSet(); for (IdentifyingToken identifyingToken : identifyingTokens) { LocalAuthorization localAuthorization = new LocalAuthorization(); localAuthorization.setToken(identifyingToken.getToken()); localAuthorization.setAuthenticationStatus(identifyingToken.getAuthenticationStatus()); localAuthorizations.add(localAuthorization); } return localAuthorizations; }
public IdentifyingToken validate(IdentifyingToken token, @Nullable ChargingStationId chargingStationId) { if (chargingStationId == null) { LOG.warn("No charging station id passed to validation request for token {}", token.getToken()); return token; if (validatedToken.isValid()) { return validatedToken;
LOG.debug("validate({}, {})", identification.getToken(), chargingStationId); String hiddenId = identification.getToken(); String visibleId = identification.getVisibleId(); Token token = null; if (hiddenId != null) { LOG.debug("Token valid: {}", token.getUid()); return new TextualToken(identification.getToken(), AuthenticationStatus.ACCEPTED, token.getIssuingCompany(), token.getVisualNumber()); } else { LOG.debug("Token not found: {}", identification.getToken());
@EventHandler public void handle(TransactionStartedEvent event) { LOG.debug("TransactionStartedEvent for [{}] received!", event.getChargingStationId()); StartTransactionInfo startTransactionInfo = event.getStartTransactionInfo(); IdentifyingToken identifyingToken = startTransactionInfo.getIdentifyingToken(); Transaction transaction = new Transaction(event.getChargingStationId().getId(), event.getTransactionId().getId(), startTransactionInfo.getEvseId(), identifyingToken.getToken(), startTransactionInfo.getMeterStart(), startTransactionInfo.getTimestamp(), identifyingToken.getMobilityServiceProvider(), identifyingToken.getVisibleId()); repository.createOrUpdate(transaction); }
/** * Validates the token with the configured authentication providers, as soon * as one provider provides valid authorization this will be the result. * * @param token identifying token for which authorization is required * @param chargingStationId optional charging station id for this authorization * @return validated IdentifyingToken */ @Override public IdentifyingToken validate(IdentifyingToken token, @Nullable ChargingStationId chargingStationId) { for (AuthorizationProvider provider : providers) { IdentifyingToken validatedToken = provider.validate(token, chargingStationId); if (validatedToken.isValid()) { return validatedToken; } } return token; }
/** * Listens for {@code AuthorizationRequestedEvent} and requests the {@code IdentificationAuthorizationService} to * execute the authorization. Sends a {@code GrantAuthorizationCommand} if identification is successful, * {@code DenyAuthorizationCommand} if not. The passed correlation id will be added to the outgoing command if * it's not null or empty. * * @param event the authorization request event. * @param correlationToken correlation token which will be added to outgoing command if it's not null or empty. */ @EventHandler protected void onEvent(AuthorizationRequestedEvent event, @MetaData(value = CorrelationToken.KEY, required = false) CorrelationToken correlationToken) { IdentifyingToken identifyingToken = event.getIdentifyingToken(); identifyingToken = identificationAuthorizationService.validate(identifyingToken, event.getChargingStationId()); CommandMessage commandMessage; IdentityContext identityContext = new IdentityContext(addOnIdentity, new NullUserIdentity()); if (identifyingToken.isValid()) { commandMessage = asCommandMessage(new GrantAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } else { commandMessage = asCommandMessage(new DenyAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } if (correlationToken != null) { commandMessage = commandMessage.andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); } commandGateway.send(commandMessage); }
/** * Generates a transaction identifier and starts a transaction by dispatching a StartTransactionCommand. * * @param chargingStationId identifier of the charging station. * @param evseId evse identifier on which the transaction is started. * @param idTag the identification which started the transaction. * @param futureEventCallback will be called once the authorize result event occurs. * @param addOnIdentity identity of the add on that calls this method. */ public void startTransaction(ChargingStationId chargingStationId, EvseId evseId, IdentifyingToken idTag, FutureEventCallback futureEventCallback, AddOnIdentity addOnIdentity) { ChargingStation chargingStation = this.checkChargingStationExistsAndIsRegisteredAndConfigured(chargingStationId); if (evseId.getNumberedId() > chargingStation.getNumberOfEvses()) { throw new IllegalStateException("Cannot start transaction on a unknown evse."); } // authorize the token, the future contains the call to start the transaction authorize(chargingStationId, idTag.getToken(), futureEventCallback, addOnIdentity); }
authData.setIdTag(token.getToken()); IdentifyingToken.AuthenticationStatus status = token.getAuthenticationStatus(); if (status != null && !IdentifyingToken.AuthenticationStatus.DELETED.equals(status)) { IdTagInfo info = new IdTagInfo(); switch (token.getAuthenticationStatus()) { case ACCEPTED: info.setStatus(AuthorizationStatus.ACCEPTED); break; default: throw new AssertionError(String.format("Unknown authentication status [%s] in given identifying token [%s].", token.getAuthenticationStatus(), token.getToken()));
public SourceAuthorizeResponse authorize(SourceAuthorizeRequest sourceAuthorizeRequest) { LOG.trace("Authorize called"); SourceAuthorizeResponse sourceAuthorizeResponse; if (identificationAuthorizationService.validate(new TextualToken(sourceAuthorizeRequest.getUserIdentifier()), null).isValid()) { DestinationEndpoint destinationEndpoint = destinationEndpointRepository.findDestinationEndpointByPmsIdentifier(sourceAuthorizeRequest.getServicePms()); if (destinationEndpoint != null) { DestinationClient destinationClient = new DestinationClient(destinationEndpoint.getDestinationEndpointUrl()); sourceAuthorizeResponse = destinationClient.authorize(sourceAuthorizeRequest); createSessionInfo(sourceAuthorizeRequest, sourceAuthorizeResponse); } else { ResponseError responseError = new ResponseError(); responseError.setErrorMsg("PMS Unknown: " + sourceAuthorizeRequest.getServicePms()); responseError.setErrorCode("400"); sourceAuthorizeResponse = new SourceAuthorizeResponse(responseError); } } else { ResponseError responseError = new ResponseError(); responseError.setErrorMsg("Invalid userIdentifier"); responseError.setErrorCode("400"); sourceAuthorizeResponse = new SourceAuthorizeResponse(responseError); } return sourceAuthorizeResponse; }
/** * {@inheritDoc} */ @Override public boolean startTransaction(ChargingStationId id, IdentifyingToken identifyingToken, EvseId evseId) { LOG.info("Requesting remote start transaction on {}", id); ChargePointService chargePointService = this.createChargingStationService(id); RemoteStartTransactionRequest request = new RemoteStartTransactionRequest(); request.setIdTag(identifyingToken.getToken()); request.setConnectorId(evseId.getNumberedId()); RemoteStartTransactionResponse response = chargePointService.remoteStartTransaction(request, id.getId()); boolean willTransactionStart; switch (response.getStatus()) { case ACCEPTED: LOG.info("Remote start transaction request on {} has been accepted", id); willTransactionStart = true; break; case REJECTED: LOG.info("Remote start transaction request on {} has been rejected", id); willTransactionStart = false; break; default: throw new AssertionError("Start transaction returned unknown response status " + response.getStatus()); } return willTransactionStart; }
public void sendLocalList(ChargingStationId chargingStationId, AuthorizationListUpdateType updateType, Set<IdentifyingToken> authorizationList, int authorizationListVersion, String authorizationListHash, CorrelationToken correlationToken) { List<LocalAuthorisationList> localList = Lists.newArrayList(); for (IdentifyingToken token : authorizationList) { LocalAuthorisationList localListEntry = new LocalAuthorisationList(); localListEntry.setIdTag(token.getToken()); IdTagInfo_ idTagInfo = new IdTagInfo_(); idTagInfo.setStatus(convertAuthenticationStatus(token.getAuthenticationStatus())); localListEntry.setIdTagInfo(idTagInfo); localList.add(localListEntry); } Sendlocallist sendLocalListRequest = new Sendlocallist(); sendLocalListRequest.setLocalAuthorisationList(localList); sendLocalListRequest.setUpdateType(AuthorizationListUpdateType.FULL.equals(updateType) ? Sendlocallist.UpdateType.FULL : Sendlocallist.UpdateType.DIFFERENTIAL); sendLocalListRequest.setListVersion(authorizationListVersion); sendLocalListRequest.setHash(authorizationListHash); responseHandlers.put(correlationToken.getToken(), new SendLocalListResponseHandler(authorizationListVersion, updateType, authorizationList, correlationToken)); WampMessage wampMessage = new WampMessage(WampMessage.CALL, correlationToken.getToken(), MessageProcUri.SEND_LOCALLIST, sendLocalListRequest); sendWampMessage(wampMessage, chargingStationId); }
/** * {@inheritDoc} */ @Override public boolean startTransaction(ChargingStationId id, IdentifyingToken identifyingToken, EvseId evseId) { LOG.info("Requesting remote start transaction on {}", id); ChargePointService chargePointService = this.createChargingStationService(id); RemoteStartTransactionRequest request = new RemoteStartTransactionRequest(); request.setIdTag(identifyingToken.getToken()); request.setConnectorId(evseId.getNumberedId()); RemoteStartTransactionResponse response = chargePointService.remoteStartTransaction(request, id.getId()); boolean willTransactionStart; switch (response.getStatus()) { case ACCEPTED: LOG.info("Remote start transaction request on {} has been accepted", id); willTransactionStart = true; break; case REJECTED: LOG.info("Remote start transaction request on {} has been rejected", id); willTransactionStart = false; break; default: throw new AssertionError("Start transaction returned unknown response status " + response.getStatus()); } return willTransactionStart; }
public void reserveNow(ChargingStationId chargingStationId, EvseId evseId, IdentifyingToken identifyingToken, IdentifyingToken parentIdentifyingToken, Date expiryDate, CorrelationToken correlationToken) { NumberedReservationId reservationId = domainService.generateReservationIdentifier(chargingStationId, PROTOCOL_IDENTIFIER); Reservenow reserveNowRequest = new Reservenow(); reserveNowRequest.setConnectorId(evseId.getNumberedId()); reserveNowRequest.setIdTag(identifyingToken.getToken()); if (parentIdentifyingToken != null) { reserveNowRequest.setParentIdTag(parentIdentifyingToken.getToken()); } reserveNowRequest.setExpiryDate(expiryDate); reserveNowRequest.setReservationId(reservationId.getNumber()); responseHandlers.put(correlationToken.getToken(), new ReserveNowResponseHandler(reservationId, evseId, expiryDate, correlationToken)); WampMessage wampMessage = new WampMessage(WampMessage.CALL, correlationToken.getToken(), MessageProcUri.RESERVE_NOW, reserveNowRequest); sendWampMessage(wampMessage, chargingStationId); }
public void remoteStartTransaction(ChargingStationId chargingStationId, EvseId evseId, IdentifyingToken identifyingToken, CorrelationToken correlationToken) { Remotestarttransaction remoteStartTransactionRequest = new Remotestarttransaction(); remoteStartTransactionRequest.setConnectorId(evseId.getNumberedId()); remoteStartTransactionRequest.setIdTag(identifyingToken.getToken()); responseHandlers.put(correlationToken.getToken(), new RemoteStartTransactionResponseHandler(correlationToken)); WampMessage wampMessage = new WampMessage(WampMessage.CALL, correlationToken.getToken(), MessageProcUri.REMOTE_START_TRANSACTION, remoteStartTransactionRequest); sendWampMessage(wampMessage, chargingStationId); }
/** * Handles the {@code AuthorizationResultEvent} and wraps the result in a {@code AuthorizationResult} which is * written to the 'result' member. Returns true if the event is of type {@code AuthorizationResultEvent}, otherwise * false. Does a countDown on the countDownLatch to indicate the 'wait' is over. * * @param event event message * @return true if the event is of type {@code AuthorizationResultEvent}, otherwise false. */ @Override public boolean onEvent(EventMessage<?> event) { AuthorizationResultEvent resultEvent; if (event.getPayload() instanceof AuthorizationResultEvent) { resultEvent = (AuthorizationResultEvent) event.getPayload(); this.setResult(new AuthorizationResult(resultEvent.getIdentifyingToken().getToken(), resultEvent.getAuthenticationStatus())); this.countDownLatch(); if (continuation != null) { // no need to wait for the continuation timeout, resume it now continuation.resume(); } return true; } else { // not the right type of event... not 'handled' return false; } }
@EventHandler protected void onEvent(TransactionStartedEvent event) { LOG.info("Sending notifyRequestResult for a TransactionStartedEvent to the source PMS"); String authorizationIdentifier = event.getStartTransactionInfo().getIdentifyingToken().getToken(); Integer transactionId = ((NumberedTransactionId) event.getTransactionId()).getNumber(); SessionInfo sessionInfo = destinationSessionRepository.findSessionInfoByAuthorizationId(authorizationIdentifier); sessionInfo.setTransactionId(transactionId); sessionInfo.getSessionStateMachine().eventStartOk(); sessionInfo.setMeterStart(event.getStartTransactionInfo().getMeterStart()); sessionInfo.setStartTimestamp(event.getStartTransactionInfo().getTimestamp()); destinationSessionRepository.insertOrUpdateSessionInfo(sessionInfo); String requestIdentifier = sessionInfo.getRequestIdentifier(); SourceEndpoint sourceEndpoint = sourceEndpointRepository.findSourceEndpointByPmsIdentifier(sessionInfo.getPmsIdentifier()); SourceClient sourceClient = new SourceClient(sourceEndpoint.getSourceEndpointUrl()); DestinationNotifyRequestResultRequest destinationNotifyRequestResultRequest = new DestinationNotifyRequestResultRequest(requestIdentifier); sourceClient.notifyRequestResult(destinationNotifyRequestResultRequest); LOG.info("Received a notifyRequestResultResponse from the source PMS"); }