Search in sources :

Example 1 with NotFoundException

use of bio.terra.common.exception.NotFoundException in project jade-data-repo by DataBiosphere.

the class CreateDatasetAuthzIamStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    UUID datasetId = workingMap.get(DatasetWorkingMapKeys.DATASET_ID, UUID.class);
    try {
        iamClient.deleteDatasetResource(userReq, datasetId);
    } catch (UnauthorizedException ex) {
        // suppress exception
        logger.error("NEEDS CLEANUP: delete sam resource for dataset " + datasetId.toString(), ex);
    } catch (NotFoundException ex) {
    // if the SAM resource is not found, then it was likely not created -- continue undoing
    }
    return StepResult.getStepResultSuccess();
}
Also used : UnauthorizedException(bio.terra.common.exception.UnauthorizedException) NotFoundException(bio.terra.common.exception.NotFoundException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

Example 2 with NotFoundException

use of bio.terra.common.exception.NotFoundException 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)

Example 3 with NotFoundException

use of bio.terra.common.exception.NotFoundException in project terra-external-credentials-manager by DataBiosphere.

the class ProviderService method deleteLink.

public void deleteLink(String userId, String providerName) {
    var providerInfo = externalCredsConfig.getProviders().get(providerName);
    if (providerInfo == null) {
        throw new NotFoundException(String.format("Provider %s not found", providerName));
    }
    var linkedAccount = linkedAccountService.getLinkedAccount(userId, providerName).orElseThrow(() -> new NotFoundException("Link not found for user"));
    revokeAccessToken(providerInfo, linkedAccount);
    linkedAccountService.deleteLinkedAccount(userId, providerName);
}
Also used : NotFoundException(bio.terra.common.exception.NotFoundException)

Aggregations

NotFoundException (bio.terra.common.exception.NotFoundException)3 BadRequestException (bio.terra.common.exception.BadRequestException)1 UnauthorizedException (bio.terra.common.exception.UnauthorizedException)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 FlightMap (bio.terra.stairway.FlightMap)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