use of bio.terra.externalcreds.models.VisaVerificationDetails in project terra-external-credentials-manager by DataBiosphere.
the class ProviderService method validateVisaWithProvider.
@VisibleForTesting
boolean validateVisaWithProvider(VisaVerificationDetails visaDetails) {
var providerProperties = externalCredsConfig.getProviders().get(visaDetails.getProviderName());
if (providerProperties == null) {
throw new NotFoundException(String.format("Provider %s not found", visaDetails.getProviderName()));
}
var validationEndpoint = providerProperties.getValidationEndpoint().orElseThrow(() -> new NotFoundException(String.format("Validation endpoint for provider %s not found", visaDetails.getProviderName())));
var response = WebClient.create(validationEndpoint).get().uri(uriBuilder -> uriBuilder.queryParam("visa", visaDetails.getVisaJwt()).build()).retrieve();
var responseBody = response.onStatus(HttpStatus::isError, clientResponse -> Mono.empty()).bodyToMono(String.class).block(Duration.of(1000, ChronoUnit.MILLIS));
log.info("Got visa validation response.", Map.of("linkedAccountId", visaDetails.getLinkedAccountId(), "providerName", visaDetails.getProviderName(), "validationResponse", Objects.requireNonNullElse(responseBody, "[null]")));
var visaValid = "valid".equalsIgnoreCase(responseBody);
if (visaValid) {
passportService.updateVisaLastValidated(visaDetails.getVisaId());
}
return visaValid;
}
Aggregations