/** * 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; }
if (validatedToken.isValid()) { return validatedToken;
/** * 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); }
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; }