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);
}
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);
}
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());
}
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());
}
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();
}
}
Aggregations