Search in sources :

Example 1 with ProviderProperties

use of bio.terra.externalcreds.config.ProviderProperties 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;
}
Also used : AuditLogEvent(bio.terra.externalcreds.auditLogging.AuditLogEvent) VisaVerificationDetails(bio.terra.externalcreds.models.VisaVerificationDetails) LinkedAccount(bio.terra.externalcreds.models.LinkedAccount) AuditLogger(bio.terra.externalcreds.auditLogging.AuditLogger) OAuth2AuthorizationException(org.springframework.security.oauth2.core.OAuth2AuthorizationException) WebClient(org.springframework.web.reactive.function.client.WebClient) NotFoundException(bio.terra.common.exception.NotFoundException) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) ExternalCredsException(bio.terra.externalcreds.ExternalCredsException) OAuth2State(bio.terra.externalcreds.models.OAuth2State) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ProviderProperties(bio.terra.externalcreds.config.ProviderProperties) AuditLogEventType(bio.terra.externalcreds.auditLogging.AuditLogEventType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) Mono(reactor.core.publisher.Mono) CannotDecodeOAuth2State(bio.terra.externalcreds.models.CannotDecodeOAuth2State) Instant(java.time.Instant) OAuth2ErrorCodes(org.springframework.security.oauth2.core.OAuth2ErrorCodes) ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) ExternalCredsConfig(bio.terra.externalcreds.config.ExternalCredsConfig) Objects(java.util.Objects) HttpStatus(org.springframework.http.HttpStatus) LinkedAccountWithPassportAndVisas(bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas) Slf4j(lombok.extern.slf4j.Slf4j) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) BadRequestException(bio.terra.common.exception.BadRequestException) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) OAuth2RefreshToken(org.springframework.security.oauth2.core.OAuth2RefreshToken) Collections(java.util.Collections) HttpStatus(org.springframework.http.HttpStatus) NotFoundException(bio.terra.common.exception.NotFoundException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BadRequestException (bio.terra.common.exception.BadRequestException)1 NotFoundException (bio.terra.common.exception.NotFoundException)1 ExternalCredsException (bio.terra.externalcreds.ExternalCredsException)1 AuditLogEvent (bio.terra.externalcreds.auditLogging.AuditLogEvent)1 AuditLogEventType (bio.terra.externalcreds.auditLogging.AuditLogEventType)1 AuditLogger (bio.terra.externalcreds.auditLogging.AuditLogger)1 ExternalCredsConfig (bio.terra.externalcreds.config.ExternalCredsConfig)1 ProviderProperties (bio.terra.externalcreds.config.ProviderProperties)1 CannotDecodeOAuth2State (bio.terra.externalcreds.models.CannotDecodeOAuth2State)1 LinkedAccount (bio.terra.externalcreds.models.LinkedAccount)1 LinkedAccountWithPassportAndVisas (bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas)1 OAuth2State (bio.terra.externalcreds.models.OAuth2State)1 VisaVerificationDetails (bio.terra.externalcreds.models.VisaVerificationDetails)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SecureRandom (java.security.SecureRandom)1 Timestamp (java.sql.Timestamp)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1