Search in sources :

Example 1 with AuthenticatedUserRequest

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

the class SamIam method listAuthorizedResourcesInner.

private List<UUID> listAuthorizedResourcesInner(AuthenticatedUserRequest userReq, IamResourceType iamResourceType) throws ApiException {
    ResourcesApi samResourceApi = samResourcesApi(userReq.getRequiredToken());
    List<ResourceAndAccessPolicy> resources = samResourceApi.listResourcesAndPolicies(iamResourceType.toString());
    return resources.stream().map(resource -> UUID.fromString(resource.getResourceId())).collect(Collectors.toList());
}
Also used : DataRepoException(bio.terra.common.exception.DataRepoException) Arrays(java.util.Arrays) IamResourceType(bio.terra.service.iam.IamResourceType) AccessPolicyMembership(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyMembership) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IamUnauthorizedException(bio.terra.service.iam.exception.IamUnauthorizedException) HashMap(java.util.HashMap) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException) IamInternalServerErrorException(bio.terra.service.iam.exception.IamInternalServerErrorException) ArrayList(java.util.ArrayList) IamAction(bio.terra.service.iam.IamAction) GoogleApi(org.broadinstitute.dsde.workbench.client.sam.api.GoogleApi) Map(java.util.Map) ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi) Pair(org.broadinstitute.dsde.workbench.client.sam.Pair) AccessPolicyResponseEntry(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyResponseEntry) PolicyModel(bio.terra.model.PolicyModel) Logger(org.slf4j.Logger) ApiClient(org.broadinstitute.dsde.workbench.client.sam.ApiClient) IamBadRequestException(bio.terra.service.iam.exception.IamBadRequestException) ResourceAndAccessPolicy(org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy) IamProviderInterface(bio.terra.service.iam.IamProviderInterface) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IamRole(bio.terra.service.iam.IamRole) Component(org.springframework.stereotype.Component) List(java.util.List) HttpStatusCodes(com.google.api.client.http.HttpStatusCodes) UserStatusInfo(bio.terra.model.UserStatusInfo) UsersApi(org.broadinstitute.dsde.workbench.client.sam.api.UsersApi) AuthenticatedUserRequest(bio.terra.service.iam.AuthenticatedUserRequest) ConfigurationService(bio.terra.service.configuration.ConfigurationService) Collections(java.util.Collections) IamNotFoundException(bio.terra.service.iam.exception.IamNotFoundException) ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi) ResourceAndAccessPolicy(org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy)

Example 2 with AuthenticatedUserRequest

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

the class JobService method submitAndWait.

// submit a new job to stairway, wait for it to finish, then return the result
// protected method intended to be called only from JobBuilder
protected <T> T submitAndWait(Class<? extends Flight> flightClass, FlightMap parameterMap, Class<T> resultClass) {
    String jobId = submit(flightClass, parameterMap);
    waitForJob(jobId);
    AuthenticatedUserRequest userReq = parameterMap.get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
    return retrieveJobResult(jobId, resultClass, userReq).getResult();
}
Also used : AuthenticatedUserRequest(bio.terra.service.iam.AuthenticatedUserRequest)

Example 3 with AuthenticatedUserRequest

use of bio.terra.service.iam.AuthenticatedUserRequest 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)

Example 4 with AuthenticatedUserRequest

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

the class RepositoryApiController method ingestFile.

@Override
public ResponseEntity<JobModel> ingestFile(@PathVariable("id") String id, @Valid @RequestBody FileLoadModel ingestFile) {
    AuthenticatedUserRequest userReq = getAuthenticatedInfo();
    iamService.verifyAuthorization(userReq, IamResourceType.DATASET, id, IamAction.INGEST_DATA);
    String jobId = fileService.ingestFile(id, ingestFile, userReq);
    // we can retrieve the job we just created
    return jobToResponse(jobService.retrieveJob(jobId, userReq));
}
Also used : AuthenticatedUserRequest(bio.terra.service.iam.AuthenticatedUserRequest)

Example 5 with AuthenticatedUserRequest

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

the class RepositoryApiController method deleteSnapshot.

@Override
public ResponseEntity<JobModel> deleteSnapshot(@PathVariable("id") String id) {
    AuthenticatedUserRequest userReq = getAuthenticatedInfo();
    iamService.verifyAuthorization(userReq, IamResourceType.DATASNAPSHOT, id, IamAction.DELETE);
    String jobId = snapshotService.deleteSnapshot(UUID.fromString(id), userReq);
    // we can retrieve the job we just created
    return jobToResponse(jobService.retrieveJob(jobId, userReq));
}
Also used : AuthenticatedUserRequest(bio.terra.service.iam.AuthenticatedUserRequest)

Aggregations

AuthenticatedUserRequest (bio.terra.service.iam.AuthenticatedUserRequest)17 IamUnauthorizedException (bio.terra.service.iam.exception.IamUnauthorizedException)3 UUID (java.util.UUID)3 DataRepoException (bio.terra.common.exception.DataRepoException)2 PolicyModel (bio.terra.model.PolicyModel)2 UserStatusInfo (bio.terra.model.UserStatusInfo)2 ConfigurationService (bio.terra.service.configuration.ConfigurationService)2 IamAction (bio.terra.service.iam.IamAction)2 IamProviderInterface (bio.terra.service.iam.IamProviderInterface)2 IamResourceType (bio.terra.service.iam.IamResourceType)2 IamRole (bio.terra.service.iam.IamRole)2 IamBadRequestException (bio.terra.service.iam.exception.IamBadRequestException)2 IamInternalServerErrorException (bio.terra.service.iam.exception.IamInternalServerErrorException)2 IamNotFoundException (bio.terra.service.iam.exception.IamNotFoundException)2 HttpStatusCodes (com.google.api.client.http.HttpStatusCodes)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2