Search in sources :

Example 46 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method delete_global_permission_from_group.

@Test
public void delete_global_permission_from_group() {
    OrganizationDto org = db.organizations().insert();
    GroupDto group1 = db.users().insertGroup(org);
    ComponentDto project1 = db.components().insertProject(org);
    db.users().insertPermissionOnAnyone(org, "perm1");
    db.users().insertPermissionOnGroup(group1, "perm2");
    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
    db.users().insertProjectPermissionOnAnyone("perm4", project1);
    underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
    dbSession.commit();
    assertThatNoPermission("perm2");
    assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 47 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method select_groups_by_query_with_project_permissions.

@Test
public void select_groups_by_query_with_project_permissions() {
    GroupDto group1 = db.users().insertGroup();
    GroupDto group2 = db.users().insertGroup();
    GroupDto group3 = db.users().insertGroup();
    ComponentDto project = db.components().insertProject();
    ComponentDto anotherProject = db.components().insertProject();
    db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
    db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
    db.users().insertProjectPermissionOnAnyone(USER, project);
    db.users().insertProjectPermissionOnGroup(group1, SYSTEM_ADMIN, anotherProject);
    db.users().insertProjectPermissionOnAnyone(SYSTEM_ADMIN, anotherProject);
    db.users().insertProjectPermissionOnGroup(group3, SCAN_EXECUTION, anotherProject);
    db.users().insertPermissionOnGroup(group2, SCAN);
    PermissionQuery.Builder builderOnComponent = PermissionQuery.builder().setComponentUuid(project.uuid());
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.withAtLeastOnePermission().build())).containsOnlyOnce(group1.getName());
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.setPermission(SCAN_EXECUTION).build())).containsOnlyOnce(group1.getName());
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.setPermission(USER).build())).containsOnlyOnce(ANYONE);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 48 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method selectGroupNamesByQuery_with_search_query.

@Test
public void selectGroupNamesByQuery_with_search_query() {
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group-anyone");
    db.users().insertGroup(db.getDefaultOrganization(), "unknown");
    db.users().insertPermissionOnGroup(group, SCAN);
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().setSearchQuery("any").build())).containsOnlyOnce(ANYONE, group.getName());
}
Also used : GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 49 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method selectGroupNamesByQuery_does_not_return_anyone_when_group_roles_is_empty.

@Test
public void selectGroupNamesByQuery_does_not_return_anyone_when_group_roles_is_empty() {
    GroupDto group = db.users().insertGroup();
    assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().build())).doesNotContain(ANYONE).containsExactly(group.getName());
}
Also used : GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 50 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class UserIdentityAuthenticator method syncGroups.

private void syncGroups(DbSession dbSession, UserIdentity userIdentity, UserDto userDto) {
    if (userIdentity.shouldSyncGroups()) {
        String userLogin = userIdentity.getLogin();
        Set<String> userGroups = new HashSet<>(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(userLogin)).get(userLogin));
        Set<String> identityGroups = userIdentity.getGroups();
        LOGGER.debug("List of groups returned by the identity provider '{}'", identityGroups);
        Collection<String> groupsToAdd = Sets.difference(identityGroups, userGroups);
        Collection<String> groupsToRemove = Sets.difference(userGroups, identityGroups);
        Collection<String> allGroups = new ArrayList<>(groupsToAdd);
        allGroups.addAll(groupsToRemove);
        DefaultOrganization defaultOrganization = defaultOrganizationProvider.get();
        Map<String, GroupDto> groupsByName = dbClient.groupDao().selectByNames(dbSession, defaultOrganization.getUuid(), allGroups).stream().collect(uniqueIndex(GroupDto::getName));
        addGroups(dbSession, userDto, groupsToAdd, groupsByName);
        removeGroups(dbSession, userDto, groupsToRemove, groupsByName);
        dbSession.commit();
    }
}
Also used : ArrayList(java.util.ArrayList) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) HashSet(java.util.HashSet) DefaultOrganization(org.sonar.server.organization.DefaultOrganization)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)177 Test (org.junit.Test)158 OrganizationDto (org.sonar.db.organization.OrganizationDto)74 UserDto (org.sonar.db.user.UserDto)67 ComponentDto (org.sonar.db.component.ComponentDto)38 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)31 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)18 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)17 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 UserGroupDto (org.sonar.db.user.UserGroupDto)12 DbSession (org.sonar.db.DbSession)11 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)3 System2 (org.sonar.api.utils.System2)3 DbClient (org.sonar.db.DbClient)3 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)3 Strings (com.google.common.base.Strings)2