public static UserGroupState buildProjectAdminsUserGroup(String projectId) { String id = AuthRole.PROJECT_ADMIN.buildRoleWithSuffix(projectId); UserGroupState userGroupState = buildUserGroupState(id); return userGroupState; }
public static ResourceGroupState buildProjectExtendedMemberResourceGroup(String projectId, String groupId) { ResourceGroupState state = buildProjectExtendedMemberResourceGroup(projectId); String selfLink = AuthRole.PROJECT_MEMBER_EXTENDED.buildRoleWithSuffix(projectId, groupId); state.documentSelfLink = selfLink; return state; }
public static UserGroupState buildProjectMembersUserGroup(String projectId) { String id = AuthRole.PROJECT_MEMBER.buildRoleWithSuffix(projectId); UserGroupState userGroupState = buildUserGroupState(id); return userGroupState; }
public static UserGroupState buildProjectViewersUserGroup(String projectId) { String id = AuthRole.PROJECT_VIEWER.buildRoleWithSuffix(projectId); UserGroupState userGroupState = buildUserGroupState(id); return userGroupState; }
/** * This is currently used to workaround xenon problem, where we can't * get documents if with OData query. */ public static RoleState buildBasicUsersExtendedRole(String identifier, String userGroupLink) { String id = AuthRole.BASIC_USER_EXTENDED.buildRoleWithSuffix(identifier); String selfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); EnumSet<Action> verbs = EnumSet.allOf(Action.class); RoleState roleState = buildRoleState(selfLink, userGroupLink, BASIC_USERS_EXTENDED_RESOURCE_GROUP_LINK, verbs, Policy.ALLOW); return roleState; }
public static RoleState buildCloudAdminsRole(String identifier, String userGroupLink) { String id = AuthRole.CLOUD_ADMIN.buildRoleWithSuffix(identifier); String selfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); EnumSet<Action> verbs = EnumSet.allOf(Action.class); RoleState roleState = buildRoleState(selfLink, userGroupLink, CLOUD_ADMINS_RESOURCE_GROUP_LINK, verbs, Policy.ALLOW); return roleState; }
public static RoleState buildBasicUsersRole(String identifier, String userGroupLink) { String id = AuthRole.BASIC_USER.buildRoleWithSuffix(identifier); String selfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); EnumSet<Action> verbs = EnumSet.of(Action.GET); RoleState roleState = buildRoleState(selfLink, userGroupLink, BASIC_USERS_RESOURCE_GROUP_LINK, verbs, Policy.ALLOW); return roleState; }
public static RoleState buildProjectRole(AuthRole role, EnumSet<Action> verbs, String projectId, String userGroupLink, String resourceGroupLink) { String id; if (containsRoleSuffix(userGroupLink)) { id = role.buildRoleWithSuffix(projectId); } else { String userGroupId = Service.getId(userGroupLink); id = role.buildRoleWithSuffix(projectId, userGroupId); } String selfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); RoleState roleState = buildRoleState(selfLink, userGroupLink, resourceGroupLink, verbs, Policy.ALLOW); return roleState; }
private DeferredResult<Void> handleProjectViewerGroupUnssignment(ProjectState projectState, String groupId) { String projectId = Service.getId(projectState.documentSelfLink); String encodedGroupId = encode(groupId); String roleLink = AuthRole.PROJECT_VIEWER.buildRoleWithSuffix(projectId, encodedGroupId); String userGroupLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, encodedGroupId); return deleteRole(roleLink) .thenAccept(ignore -> projectState.viewersUserGroupLinks.remove(userGroupLink)); }
private DeferredResult<Void> handleProjectAdminGroupUnassignment(ProjectState projectState, String groupId) { String projectId = Service.getId(projectState.documentSelfLink); String encodedGroupId = encode(groupId); String roleLink = AuthRole.PROJECT_ADMIN.buildRoleWithSuffix(projectId, encodedGroupId); String userGroupLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, encodedGroupId); return deleteRole(roleLink) .thenAccept( ignore -> projectState.administratorsUserGroupLinks.remove(userGroupLink)); }
private DeferredResult<Void> deleteExtendedMemberRole(String projectId, String groupId) { String encodedGroupId = encode(groupId); String roleLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, AuthRole.PROJECT_MEMBER_EXTENDED.buildRoleWithSuffix(projectId, encodedGroupId)); String resourceGroupLink = UriUtils.buildUriPath(ResourceGroupService.FACTORY_LINK, AuthRole.PROJECT_MEMBER_EXTENDED.buildRoleWithSuffix(projectId, encodedGroupId)); Operation deleteRgOp = Operation.createDelete(service, resourceGroupLink); Operation deleteRoleOp = Operation.createDelete(service, roleLink); return service.sendWithDeferredResult(deleteRgOp) .thenCompose(ignore -> service.sendWithDeferredResult(deleteRoleOp)) .thenAccept(ignore -> { }); }
private DeferredResult<Void> handleProjectMemberGroupUnssignment(ProjectState projectState, String groupId) { String projectId = Service.getId(projectState.documentSelfLink); String encodedGroupId = encode(groupId); String roleLink = AuthRole.PROJECT_MEMBER.buildRoleWithSuffix(projectId, encodedGroupId); String userGroupLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, encodedGroupId); return deleteRole(roleLink) .thenCompose(ignore -> deleteExtendedMemberRole(projectId, encodedGroupId)) .thenAccept(ignore -> projectState.membersUserGroupLinks.remove(userGroupLink)); }
@Test public void testBuildProjectMembersUserGroup() { UserGroupState userGroupState = buildProjectMembersUserGroup(SAMPLE_PROJECT_ID); String id = AuthRole.PROJECT_MEMBER.buildRoleWithSuffix(SAMPLE_PROJECT_ID); String expectedSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, id); assertEquals(expectedSelfLink, userGroupState.documentSelfLink); assertNotNull(userGroupState.query); }
@Test public void testBuildProjectViewersUserGroup() { UserGroupState userGroupState = buildProjectViewersUserGroup(SAMPLE_PROJECT_ID); String id = AuthRole.PROJECT_VIEWER.buildRoleWithSuffix(SAMPLE_PROJECT_ID); String expectedSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, id); assertEquals(expectedSelfLink, userGroupState.documentSelfLink); assertNotNull(userGroupState.query); }
@Test public void testBuildProjectAdminsUserGroup() { UserGroupState userGroupState = buildProjectAdminsUserGroup(SAMPLE_PROJECT_ID); String id = AuthRole.PROJECT_ADMIN.buildRoleWithSuffix(SAMPLE_PROJECT_ID); String expectedSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, id); assertEquals(expectedSelfLink, userGroupState.documentSelfLink); assertNotNull(userGroupState.query); }
@Test public void testBuildProjectMembersRole() { RoleState roleState = buildProjectMembersRole(SAMPLE_PROJECT_ID, SAMPLE_USER_GROUP_LINK, SAMPLE_RESOURCE_GROUP_LINK); String id = AuthRole.PROJECT_MEMBER .buildRoleWithSuffix(SAMPLE_PROJECT_ID, SAMPLE_USER_GROUP_LINK); String expectedSelfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); assertEquals(expectedSelfLink, roleState.documentSelfLink); assertEquals(SAMPLE_USER_GROUP_LINK, roleState.userGroupLink); assertEquals(SAMPLE_RESOURCE_GROUP_LINK, roleState.resourceGroupLink); }
@Test public void testBuildProjectViewersRole() { RoleState roleState = buildProjectViewersRole(SAMPLE_PROJECT_ID, SAMPLE_USER_GROUP_LINK, SAMPLE_RESOURCE_GROUP_LINK); String id = AuthRole.PROJECT_VIEWER.buildRoleWithSuffix(SAMPLE_PROJECT_ID, SAMPLE_USER_GROUP_LINK); String expectedSelfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); assertEquals(expectedSelfLink, roleState.documentSelfLink); assertEquals(SAMPLE_USER_GROUP_LINK, roleState.userGroupLink); assertEquals(SAMPLE_RESOURCE_GROUP_LINK, roleState.resourceGroupLink); }
@Test public void testBuildResourceGroupStateWithIdentifier() { Query query = new Query(); query.occurance = Occurance.MUST_NOT_OCCUR; ResourceGroupState resourceGroupState = buildResourceGroupState(AuthRole.PROJECT_ADMIN, SAMPLE_PROJECT_ID, query); String expectedSelfLink = UriUtils .buildUriPath(ResourceGroupService.FACTORY_LINK, AuthRole.PROJECT_ADMIN .buildRoleWithSuffix(SAMPLE_PROJECT_ID)); assertEquals(expectedSelfLink, resourceGroupState.documentSelfLink); assertEquals(Occurance.MUST_NOT_OCCUR, resourceGroupState.query.occurance); }
@Test public void testBuildProjectAdminsRole() { RoleState roleState = buildProjectAdminsRole(SAMPLE_PROJECT_ID, SAMPLE_USER_GROUP_LINK, SAMPLE_RESOURCE_GROUP_LINK); String id = AuthRole.PROJECT_ADMIN .buildRoleWithSuffix(SAMPLE_PROJECT_ID, SAMPLE_USER_GROUP_LINK); String expectedSelfLink = UriUtils.buildUriPath(RoleService.FACTORY_LINK, id); assertEquals(expectedSelfLink, roleState.documentSelfLink); assertEquals(SAMPLE_USER_GROUP_LINK, roleState.userGroupLink); assertEquals(SAMPLE_RESOURCE_GROUP_LINK, roleState.resourceGroupLink); }
@Test public void testAssignRoleToUserGroup() throws Throwable { PrincipalRoleAssignment roleAssignment = new PrincipalRoleAssignment(); roleAssignment.add = new ArrayList<>(); roleAssignment.add.add(AuthRole.CLOUD_ADMIN.name()); doRoleAssignment(roleAssignment, USER_GROUP_DEVELOPERS); RoleState roleState = getDocument(RoleState.class, UriUtils.buildUriPath(RoleService.FACTORY_LINK, AuthRole.CLOUD_ADMIN .buildRoleWithSuffix(encode(USER_GROUP_DEVELOPERS)))); assertNotNull(roleState); assertEquals(UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, encode(USER_GROUP_DEVELOPERS)), roleState.userGroupLink); }