Search in sources :

Example 1 with IamUnauthorizedException

use of bio.terra.service.iam.exception.IamUnauthorizedException in project jade-data-repo by DataBiosphere.

the class RepositoryApiController method createSnapshot.

@Override
public ResponseEntity<JobModel> createSnapshot(@Valid @RequestBody SnapshotRequestModel snapshotRequestModel) {
    AuthenticatedUserRequest userReq = getAuthenticatedInfo();
    List<UUID> snapshotSourceDatasetIds = snapshotService.getSourceDatasetIdsFromSnapshotRequest(snapshotRequestModel);
    // TODO auth should be put into flight?
    List<UUID> unauthorized = getUnauthorizedSources(snapshotSourceDatasetIds, userReq);
    if (unauthorized.isEmpty()) {
        String jobId = snapshotService.createSnapshot(snapshotRequestModel, userReq);
        // we can retrieve the job we just created
        return jobToResponse(jobService.retrieveJob(jobId, userReq));
    }
    throw new IamUnauthorizedException("User is not authorized to create snapshots for these datasets " + unauthorized);
}
Also used : IamUnauthorizedException(bio.terra.service.iam.exception.IamUnauthorizedException) AuthenticatedUserRequest(bio.terra.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID)

Aggregations

AuthenticatedUserRequest (bio.terra.service.iam.AuthenticatedUserRequest)1 IamUnauthorizedException (bio.terra.service.iam.exception.IamUnauthorizedException)1 UUID (java.util.UUID)1