Search in sources :

Example 21 with GroupDto

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

the class GroupPermissionDaoTest method delete_project_permission_from_anybody.

@Test
public void delete_project_permission_from_anybody() {
    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, "perm4", group1.getOrganizationUuid(), null, project1.getId());
    dbSession.commit();
    assertThatNoPermission("perm4");
    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 22 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 23 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 24 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)

Example 25 with GroupDto

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

the class OrganizationCreationImpl method insertOwnersGroup.

/**
   * Owners group has an hard coded name, a description based on the organization's name and has all global permissions.
   */
private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) {
    GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto().setOrganizationUuid(organization.getUuid()).setName(OWNERS_GROUP_NAME).setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName())));
    OrganizationPermission.all().forEach(p -> addPermissionToGroup(dbSession, group, p));
    return group;
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)424 Test (org.junit.Test)387 UserDto (org.sonar.db.user.UserDto)148 ComponentDto (org.sonar.db.component.ComponentDto)127 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)70 OrganizationDto (org.sonar.db.organization.OrganizationDto)42 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)36 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)34 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)28 DbSession (org.sonar.db.DbSession)20 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)17 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)13 UserGroupDto (org.sonar.db.user.UserGroupDto)12 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)12 TestResponse (org.sonar.server.ws.TestResponse)11 Qualitygates (org.sonarqube.ws.Qualitygates)10 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)9 SearchGroupsResponse (org.sonarqube.ws.Qualityprofiles.SearchGroupsResponse)9