use of bio.terra.workspace.service.iam.model.RoleBinding in project terra-workspace-manager by DataBiosphere.
the class SamService method listRoleBindings.
/**
* Wrapper around Sam client to retrieve the full current permissions model of a workspace.
*
* <p>This operation is only available to MC_WORKSPACE stage workspaces, as Rawls manages
* permissions directly on other workspaces.
*/
@Traced
public List<RoleBinding> listRoleBindings(UUID workspaceId, AuthenticatedUserRequest userRequest) throws InterruptedException {
stageService.assertMcWorkspace(workspaceId, "listRoleBindings");
checkAuthz(userRequest, SamConstants.SamResource.WORKSPACE, workspaceId.toString(), SamWorkspaceAction.READ_IAM);
ResourcesApi resourceApi = samResourcesApi(userRequest.getRequiredToken());
try {
List<AccessPolicyResponseEntry> samResult = SamRetry.retry(() -> resourceApi.listResourcePolicies(SamConstants.SamResource.WORKSPACE, workspaceId.toString()));
// callers.
return samResult.stream().filter(entry -> !entry.getPolicyName().equals(WsmIamRole.MANAGER.toSamRole())).map(entry -> RoleBinding.builder().role(WsmIamRole.fromSam(entry.getPolicyName())).users(entry.getPolicy().getMemberEmails()).build()).collect(Collectors.toList());
} catch (ApiException apiException) {
throw SamExceptionFactory.create("Error listing role bindings in Sam", apiException);
}
}
use of bio.terra.workspace.service.iam.model.RoleBinding in project terra-workspace-manager by DataBiosphere.
the class SamServiceTest method listPermissionsIncludesAddedUsers.
@Test
void listPermissionsIncludesAddedUsers() throws Exception {
samService.grantWorkspaceRole(workspaceId, defaultUserRequest(), WsmIamRole.READER, userAccessUtils.getSecondUserEmail());
List<RoleBinding> policyList = samService.listRoleBindings(workspaceId, defaultUserRequest());
RoleBinding expectedOwnerBinding = RoleBinding.builder().role(WsmIamRole.OWNER).users(Collections.singletonList(userAccessUtils.getDefaultUserEmail())).build();
RoleBinding expectedReaderBinding = RoleBinding.builder().role(WsmIamRole.READER).users(Collections.singletonList(userAccessUtils.getSecondUserEmail())).build();
RoleBinding expectedWriterBinding = RoleBinding.builder().role(WsmIamRole.WRITER).users(Collections.emptyList()).build();
RoleBinding expectedApplicationBinding = RoleBinding.builder().role(WsmIamRole.APPLICATION).users(Collections.emptyList()).build();
assertThat(policyList, containsInAnyOrder(equalTo(expectedOwnerBinding), equalTo(expectedWriterBinding), equalTo(expectedReaderBinding), equalTo(expectedApplicationBinding)));
}
Aggregations