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