@Test public void chargingStationHasNoAuthProvidersThenAuthShouldNotBeValid() { when(localAuthProvider.validate(IDENTIFYING_TOKEN, CHARGING_STATION_ID)).thenReturn(IDENTIFYING_TOKEN_ACCEPTED); when(ocpiAuthProvider.validate(IDENTIFYING_TOKEN, CHARGING_STATION_ID)).thenReturn(IDENTIFYING_TOKEN_ACCEPTED); when(chargingStation.getAuthorizationProvidersAsList()).thenReturn( new ArrayList<String>() ); assertFalse(service.validate(IDENTIFYING_TOKEN, CHARGING_STATION_ID).isValid()); }
@Override 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; } ChargingStation chargingStation = repository.findOne(chargingStationId.getId()); if (chargingStation == null) { LOG.warn("Charging station not found in repository: {}", chargingStationId); return token; } List<String> chargingStationAuthorizationProviders = chargingStation.getAuthorizationProvidersAsList(); if (chargingStationAuthorizationProviders.isEmpty()) { LOG.warn("No authorization providers configured for charging station: {}", chargingStationId); return token; } for (String authorizationProvider:chargingStationAuthorizationProviders) { AuthorizationProvider provider = providers.get(authorizationProvider); if (provider != null) { IdentifyingToken validatedToken = provider.validate(token, chargingStationId); if (validatedToken.isValid()) { return validatedToken; } } } return token; }
SelectiveIdentificationAuthorizationService implements IdentificationAuthorizationService { @Override 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; } ChargingStation chargingStation = repository.findOne(chargingStationId.getId()); if (chargingStation == null) { LOG.warn("Charging station not found in repository: {}", chargingStationId); return token; } List<String> chargingStationAuthorizationProviders = chargingStation.getAuthorizationProvidersAsList(); if (chargingStationAuthorizationProviders.isEmpty()) { LOG.warn("No authorization providers configured for charging station: {}", chargingStationId); return token; } for (String authorizationProvider:chargingStationAuthorizationProviders) { AuthorizationProvider provider = providers.get(authorizationProvider); if (provider != null) { IdentifyingToken validatedToken = provider.validate(token, chargingStationId); if (validatedToken.isValid()) { return validatedToken; } } } return token; } }
SelectiveIdentificationAuthorizationService implements IdentificationAuthorizationService { @Override 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; } ChargingStation chargingStation = repository.findOne(chargingStationId.getId()); if (chargingStation == null) { LOG.warn("Charging station not found in repository: {}", chargingStationId); return token; } List<String> chargingStationAuthorizationProviders = chargingStation.getAuthorizationProvidersAsList(); if (chargingStationAuthorizationProviders.isEmpty()) { LOG.warn("No authorization providers configured for charging station: {}", chargingStationId); return token; } for (String authorizationProvider:chargingStationAuthorizationProviders) { AuthorizationProvider provider = providers.get(authorizationProvider); if (provider != null) { IdentifyingToken validatedToken = provider.validate(token, chargingStationId); if (validatedToken.isValid()) { return validatedToken; } } } return token; }  }
SelectiveIdentificationAuthorizationService implements IdentificationAuthorizationService { @Override 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; } ChargingStation chargingStation = repository.findOne(chargingStationId.getId()); if (chargingStation == null) { LOG.warn("Charging station not found in repository: {}", chargingStationId); return token; } List<String> chargingStationAuthorizationProviders = chargingStation.getAuthorizationProvidersAsList(); if (chargingStationAuthorizationProviders.isEmpty()) { LOG.warn("No authorization providers configured for charging station: {}", chargingStationId); return token; } for (String authorizationProvider:chargingStationAuthorizationProviders) { AuthorizationProvider provider = providers.get(authorizationProvider); if (provider != null) { IdentifyingToken validatedToken = provider.validate(token, chargingStationId); if (validatedToken.isValid()) { return validatedToken; } } } return token; }  void setProviders(Map<String, AuthorizationProvider> providers); void setRepository(ChargingStationRepository repository); @Override IdentifyingToken validate(IdentifyingToken token, @Nullable ChargingStationId chargingStationId); void setDefaultAuthorizationProviders(String defaultAuthorizationProviders); }
SelectiveIdentificationAuthorizationService implements IdentificationAuthorizationService { @Override 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; } ChargingStation chargingStation = repository.findOne(chargingStationId.getId()); if (chargingStation == null) { LOG.warn("Charging station not found in repository: {}", chargingStationId); return token; } List<String> chargingStationAuthorizationProviders = chargingStation.getAuthorizationProvidersAsList(); if (chargingStationAuthorizationProviders.isEmpty()) { LOG.warn("No authorization providers configured for charging station: {}", chargingStationId); return token; } for (String authorizationProvider:chargingStationAuthorizationProviders) { AuthorizationProvider provider = providers.get(authorizationProvider); if (provider != null) { IdentifyingToken validatedToken = provider.validate(token, chargingStationId); if (validatedToken.isValid()) { return validatedToken; } } } return token; }  void setProviders(Map<String, AuthorizationProvider> providers); void setRepository(ChargingStationRepository repository); @Override IdentifyingToken validate(IdentifyingToken token, @Nullable ChargingStationId chargingStationId); void setDefaultAuthorizationProviders(String defaultAuthorizationProviders);  }