@Test(expected = UserIdentityUnauthorizedException.class) public void testHardResetCommandUnauthorized() throws UserIdentityUnauthorizedException { handler.setCommandAuthorizationService(OperatorApiJsonTestUtils.getCommandAuthorizationService(false)); JsonObject commandObject = gson.fromJson("{type:'hard'}", JsonObject.class); handler.handle(OperatorApiJsonTestUtils.CHARGING_STATION_ID_STRING, commandObject, ROOT_IDENTITY_CONTEXT); }
@Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { ChargingStationId csId = new ChargingStationId(chargingStationId); UserIdentity userIdentity = identityContext.getUserIdentity(); RequestResetChargingStationApiCommand command = gson.fromJson(commandObject, RequestResetChargingStationApiCommand.class); if("hard".equalsIgnoreCase(command.getType())) { checkAuthorization(csId, userIdentity, RequestHardResetChargingStationCommand.class); commandGateway.send(new RequestHardResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } else { checkAuthorization(csId, userIdentity, RequestSoftResetChargingStationCommand.class); commandGateway.send(new RequestSoftResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Configure command not able to parse the payload, is your json correctly formatted?", ex); } }
RequestResetChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { ChargingStationId csId = new ChargingStationId(chargingStationId); UserIdentity userIdentity = identityContext.getUserIdentity(); RequestResetChargingStationApiCommand command = gson.fromJson(commandObject, RequestResetChargingStationApiCommand.class); if("hard".equalsIgnoreCase(command.getType())) { checkAuthorization(csId, userIdentity, RequestHardResetChargingStationCommand.class); commandGateway.send(new RequestHardResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } else { checkAuthorization(csId, userIdentity, RequestSoftResetChargingStationCommand.class); commandGateway.send(new RequestSoftResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Configure command not able to parse the payload, is your json correctly formatted?", ex); } } }
RequestResetChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { ChargingStationId csId = new ChargingStationId(chargingStationId); UserIdentity userIdentity = identityContext.getUserIdentity(); RequestResetChargingStationApiCommand command = gson.fromJson(commandObject, RequestResetChargingStationApiCommand.class); if("hard".equalsIgnoreCase(command.getType())) { checkAuthorization(csId, userIdentity, RequestHardResetChargingStationCommand.class); commandGateway.send(new RequestHardResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } else { checkAuthorization(csId, userIdentity, RequestSoftResetChargingStationCommand.class); commandGateway.send(new RequestSoftResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Configure command not able to parse the payload, is your json correctly formatted?", ex); } }  }
RequestResetChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { ChargingStationId csId = new ChargingStationId(chargingStationId); UserIdentity userIdentity = identityContext.getUserIdentity(); RequestResetChargingStationApiCommand command = gson.fromJson(commandObject, RequestResetChargingStationApiCommand.class); if("hard".equalsIgnoreCase(command.getType())) { checkAuthorization(csId, userIdentity, RequestHardResetChargingStationCommand.class); commandGateway.send(new RequestHardResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } else { checkAuthorization(csId, userIdentity, RequestSoftResetChargingStationCommand.class); commandGateway.send(new RequestSoftResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Configure command not able to parse the payload, is your json correctly formatted?", ex); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext); }
RequestResetChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { ChargingStationId csId = new ChargingStationId(chargingStationId); UserIdentity userIdentity = identityContext.getUserIdentity(); RequestResetChargingStationApiCommand command = gson.fromJson(commandObject, RequestResetChargingStationApiCommand.class); if("hard".equalsIgnoreCase(command.getType())) { checkAuthorization(csId, userIdentity, RequestHardResetChargingStationCommand.class); commandGateway.send(new RequestHardResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } else { checkAuthorization(csId, userIdentity, RequestSoftResetChargingStationCommand.class); commandGateway.send(new RequestSoftResetChargingStationCommand(csId, identityContext), new CorrelationToken()); } } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Configure command not able to parse the payload, is your json correctly formatted?", ex); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext);  }