Search in sources :

Example 1 with UnauthorizedException

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

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

the class SnapshotAuthzIamStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) {
    FlightMap workingMap = context.getWorkingMap();
    UUID snapshotId = workingMap.get(SnapshotWorkingMapKeys.SNAPSHOT_ID, UUID.class);
    try {
        sam.deleteSnapshotResource(userReq, snapshotId);
    // We do not need to remove the ACL from the files or BigQuery. It disappears
    // when SAM deletes the ACL. How 'bout that!
    } catch (UnauthorizedException ex) {
        // suppress exception
        logger.error("NEEDS CLEANUP: delete sam resource for snapshot " + snapshotId.toString());
        logger.warn(ex.getMessage());
    }
    return StepResult.getStepResultSuccess();
}
Also used : UnauthorizedException(bio.terra.common.exception.UnauthorizedException) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID)

Example 3 with UnauthorizedException

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

the class OidcApiController method getUserIdFromSam.

private String getUserIdFromSam() {
    try {
        var header = request.getHeader("authorization");
        if (header == null)
            throw new UnauthorizedException("User is not authorized");
        var accessToken = BearerTokenParser.parse(header);
        return samService.samUsersApi(accessToken).getUserStatusInfo().getUserSubjectId();
    } catch (ApiException e) {
        throw new ExternalCredsException(e, e.getCode() == HttpStatus.NOT_FOUND.value() ? HttpStatus.FORBIDDEN : HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : ExternalCredsException(bio.terra.externalcreds.ExternalCredsException) UnauthorizedException(bio.terra.common.exception.UnauthorizedException) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException)

Aggregations

UnauthorizedException (bio.terra.common.exception.UnauthorizedException)3 FlightMap (bio.terra.stairway.FlightMap)2 UUID (java.util.UUID)2 NotFoundException (bio.terra.common.exception.NotFoundException)1 ExternalCredsException (bio.terra.externalcreds.ExternalCredsException)1 ApiException (org.broadinstitute.dsde.workbench.client.sam.ApiException)1