Search in sources :

Example 1 with ResourceAndAccessPolicy

use of org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy 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 ResourceAndAccessPolicy

use of org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy in project terra-workspace-manager by DataBiosphere.

the class SamService method listWorkspaceIds.

/**
 * List all workspace IDs in Sam this user has access to. Note that in environments shared with
 * Rawls, some of these workspaces will be Rawls managed and WSM will not know about them.
 */
@Traced
public List<UUID> listWorkspaceIds(AuthenticatedUserRequest userRequest) throws InterruptedException {
    ResourcesApi resourceApi = samResourcesApi(userRequest.getRequiredToken());
    List<UUID> workspaceIds = new ArrayList<>();
    try {
        List<ResourceAndAccessPolicy> resourceAndPolicies = SamRetry.retry(() -> resourceApi.listResourcesAndPolicies(SamConstants.SamResource.WORKSPACE));
        for (var resourceAndPolicy : resourceAndPolicies) {
            try {
                workspaceIds.add(UUID.fromString(resourceAndPolicy.getResourceId()));
            } catch (IllegalArgumentException e) {
                // ignored here.
                continue;
            }
        }
    } catch (ApiException apiException) {
        throw SamExceptionFactory.create("Error listing Workspace Ids in Sam", apiException);
    }
    return workspaceIds;
}
Also used : ArrayList(java.util.ArrayList) ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi) ResourceAndAccessPolicy(org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy) UUID(java.util.UUID) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ApiException (org.broadinstitute.dsde.workbench.client.sam.ApiException)2 ResourcesApi (org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi)2 ResourceAndAccessPolicy (org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy)2 DataRepoException (bio.terra.common.exception.DataRepoException)1 PolicyModel (bio.terra.model.PolicyModel)1 UserStatusInfo (bio.terra.model.UserStatusInfo)1 ConfigurationService (bio.terra.service.configuration.ConfigurationService)1 AuthenticatedUserRequest (bio.terra.service.iam.AuthenticatedUserRequest)1 IamAction (bio.terra.service.iam.IamAction)1 IamProviderInterface (bio.terra.service.iam.IamProviderInterface)1 IamResourceType (bio.terra.service.iam.IamResourceType)1 IamRole (bio.terra.service.iam.IamRole)1 IamBadRequestException (bio.terra.service.iam.exception.IamBadRequestException)1 IamInternalServerErrorException (bio.terra.service.iam.exception.IamInternalServerErrorException)1 IamNotFoundException (bio.terra.service.iam.exception.IamNotFoundException)1 IamUnauthorizedException (bio.terra.service.iam.exception.IamUnauthorizedException)1 HttpStatusCodes (com.google.api.client.http.HttpStatusCodes)1 Traced (io.opencensus.contrib.spring.aop.Traced)1