aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-auth/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-04-29 12:01:10 -0500
committersonartech <sonartech@sonarsource.com>2020-05-25 20:05:21 +0000
commit85b940dd935f57860f26dff7f1bfaa9de1ba8af2 (patch)
treea84f4075e6b09ec7c697c2990e18cb71fc27c4cf /server/sonar-webserver-auth/src
parent79beb640edf1fb0154d318e20aacb6bf003288e4 (diff)
downloadsonarqube-85b940dd935f57860f26dff7f1bfaa9de1ba8af2.tar.gz
sonarqube-85b940dd935f57860f26dff7f1bfaa9de1ba8af2.zip
SONAR-13221 change PK of GROUPS and update FKs
Diffstat (limited to 'server/sonar-webserver-auth/src')
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java6
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java2
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java12
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java7
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuid.java (renamed from server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupId.java)18
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuidOrAnyone.java (renamed from server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupIdOrAnyone.java)28
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java4
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java8
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java4
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java4
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java2
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java10
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java28
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java26
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupUuidOrAnyoneTest.java (renamed from server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupIdOrAnyoneTest.java)23
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java2
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java6
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java2
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java9
-rw-r--r--server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java6
20 files changed, 106 insertions, 101 deletions
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java
index 6a73311ad64..153024902f8 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserRegistrarImpl.java
@@ -200,7 +200,7 @@ public class UserRegistrarImpl implements UserRegistrar {
groupsToAdd.stream().map(groupsByName::get).filter(Objects::nonNull).forEach(
groupDto -> {
LOGGER.debug("Adding group '{}' to user '{}'", groupDto.getName(), userDto.getLogin());
- dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(groupDto.getId()).setUserId(userDto.getId()));
+ dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupUuid(groupDto.getUuid()).setUserId(userDto.getId()));
});
}
@@ -210,10 +210,10 @@ public class UserRegistrarImpl implements UserRegistrar {
.filter(Objects::nonNull)
// user should be member of default group only when organizations are disabled, as the IdentityProvider API doesn't handle yet
// organizations
- .filter(group -> !defaultGroup.isPresent() || !group.getId().equals(defaultGroup.get().getId()))
+ .filter(group -> !defaultGroup.isPresent() || !group.getUuid().equals(defaultGroup.get().getUuid()))
.forEach(groupDto -> {
LOGGER.debug("Removing group '{}' from user '{}'", groupDto.getName(), userDto.getLogin());
- dbClient.userGroupDao().delete(dbSession, groupDto.getId(), userDto.getId());
+ dbClient.userGroupDao().delete(dbSession, groupDto.getUuid(), userDto.getId());
});
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java
index fcf6154a232..e0cd0a54266 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/MemberUpdater.java
@@ -78,7 +78,7 @@ public class MemberUpdater {
.setOrganizationUuid(organization.getUuid())
.setUserId(user.getId()));
dbClient.userGroupDao().insert(dbSession,
- new UserGroupDto().setGroupId(defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()).getId()).setUserId(user.getId()));
+ new UserGroupDto().setGroupUuid(defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()).getUuid()).setUserId(user.getId()));
}
public void removeMember(DbSession dbSession, OrganizationDto organization, UserDto user) {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java
index 720a2ba1be0..bd9fe0a571b 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganisationSupport.java
@@ -85,28 +85,28 @@ public class OrganisationSupport {
private void associateMembersOfDefaultOrganizationToGroup(DbSession dbSession, String defaultOrganizationUuid, GroupDto membersGroup) {
List<Integer> organizationMembers = dbClient.organizationMemberDao().selectUserIdsByOrganizationUuid(dbSession, defaultOrganizationUuid);
- organizationMembers.forEach(member -> dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(membersGroup.getId()).setUserId(member)));
+ organizationMembers.forEach(member -> dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupUuid(membersGroup.getUuid()).setUserId(member)));
}
private void copySonarUsersGroupPermissionsToMembersGroup(DbSession dbSession, String defaultOrganizationUuid, GroupDto sonarUsersGroup, GroupDto membersGroup) {
- dbClient.groupPermissionDao().selectAllPermissionsByGroupId(dbSession, defaultOrganizationUuid, sonarUsersGroup.getId(),
+ dbClient.groupPermissionDao().selectAllPermissionsByGroupUuid(dbSession, defaultOrganizationUuid, sonarUsersGroup.getUuid(),
context -> {
GroupPermissionDto groupPermissionDto = (GroupPermissionDto) context.getResultObject();
dbClient.groupPermissionDao().insert(dbSession,
new GroupPermissionDto()
.setUuid(uuidFactory.create())
.setOrganizationUuid(defaultOrganizationUuid)
- .setGroupId(membersGroup.getId())
+ .setGroupUuid(membersGroup.getUuid())
.setRole(groupPermissionDto.getRole())
.setComponentUuid(groupPermissionDto.getComponentUuid()));
});
}
private void copySonarUsersGroupPermissionTemplatesToMembersGroup(DbSession dbSession, GroupDto sonarUsersGroup, GroupDto membersGroup) {
- List<PermissionTemplateGroupDto> sonarUsersPermissionTemplates = dbClient.permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupId(dbSession,
- sonarUsersGroup.getId());
+ List<PermissionTemplateGroupDto> sonarUsersPermissionTemplates = dbClient.permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupUuid(dbSession,
+ sonarUsersGroup.getUuid());
sonarUsersPermissionTemplates.forEach(permissionTemplateGroup -> dbClient.permissionTemplateDao().insertGroupPermission(dbSession,
- permissionTemplateGroup.getTemplateUuid(), membersGroup.getId(), permissionTemplateGroup.getPermission()));
+ permissionTemplateGroup.getTemplateUuid(), membersGroup.getUuid(), permissionTemplateGroup.getPermission()));
}
private List<Integer> disableTemplateRulesAndCustomRules(DbSession dbSession) {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java
index beb8569be39..ce7f4f9ebe6 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java
@@ -183,7 +183,7 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater {
}
private void insertGroupPermission(DbSession dbSession, PermissionTemplateDto template, String permission, @Nullable GroupDto group) {
- dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group == null ? null : group.getId(), permission);
+ dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getUuid(), group == null ? null : group.getUuid(), permission);
}
private void insertQualityProfiles(DbSession dbSession, DbSession batchDbSession, OrganizationDto organization) {
@@ -220,6 +220,7 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater {
*/
private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) {
GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto()
+ .setUuid(uuidFactory.create())
.setOrganizationUuid(organization.getUuid())
.setName(OWNERS_GROUP_NAME)
.setDescription(OWNERS_GROUP_DESCRIPTION));
@@ -233,14 +234,14 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater {
new GroupPermissionDto()
.setUuid(uuidFactory.create())
.setOrganizationUuid(group.getOrganizationUuid())
- .setGroupId(group.getId())
+ .setGroupUuid(group.getUuid())
.setRole(permission.getKey()));
}
private void addCurrentUserToGroup(DbSession dbSession, GroupDto group, int createUserId) {
dbClient.userGroupDao().insert(
dbSession,
- new UserGroupDto().setGroupId(group.getId()).setUserId(createUserId));
+ new UserGroupDto().setGroupUuid(group.getUuid()).setUserId(createUserId));
}
private void insertOrganizationMember(DbSession dbSession, OrganizationDto organizationDto, int userId) {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupId.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuid.java
index 227b309ad42..e3695d6b39b 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupId.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuid.java
@@ -28,28 +28,28 @@ import static java.util.Objects.requireNonNull;
* Reference to a user group, as used internally by the backend. It does
* not support reference to virtual groups "anyone".
*
- * @see GroupIdOrAnyone
+ * @see GroupUuidOrAnyone
*/
@Immutable
-public class GroupId {
+public class GroupUuid {
- private final int id;
+ private final String uuid;
private final String organizationUuid;
- private GroupId(String organizationUuid, int id) {
- this.id = id;
+ private GroupUuid(String organizationUuid, String uuid) {
+ this.uuid = uuid;
this.organizationUuid = requireNonNull(organizationUuid);
}
- public int getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
public String getOrganizationUuid() {
return organizationUuid;
}
- public static GroupId from(GroupDto dto) {
- return new GroupId(dto.getOrganizationUuid(), dto.getId());
+ public static GroupUuid from(GroupDto dto) {
+ return new GroupUuid(dto.getOrganizationUuid(), dto.getUuid());
}
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupIdOrAnyone.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuidOrAnyone.java
index 1e975472a7b..bd6e5dd6ba9 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupIdOrAnyone.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/GroupUuidOrAnyone.java
@@ -28,40 +28,40 @@ import static java.util.Objects.requireNonNull;
/**
* Reference to a user group, as used internally by the backend. Contrary to
- * {@link GroupId}, it supports reference to virtual groups "anyone". In these
- * cases {@link #getId()} returns {@code null}
+ * {@link GroupUuid}, it supports reference to virtual groups "anyone". In these
+ * cases {@link #getUuid()} returns {@code null}
*
- * @see GroupId
+ * @see GroupUuid
*/
@Immutable
-public class GroupIdOrAnyone {
+public class GroupUuidOrAnyone {
- private final Integer id;
+ private final String uuid;
private final String organizationUuid;
- private GroupIdOrAnyone(String organizationUuid, @Nullable Integer id) {
- this.id = id;
+ private GroupUuidOrAnyone(String organizationUuid, @Nullable String uuid) {
+ this.uuid = uuid;
this.organizationUuid = requireNonNull(organizationUuid, "organizationUuid can't be null");
}
public boolean isAnyone() {
- return id == null;
+ return uuid == null;
}
@CheckForNull
- public Integer getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
public String getOrganizationUuid() {
return organizationUuid;
}
- public static GroupIdOrAnyone from(GroupDto dto) {
- return new GroupIdOrAnyone(dto.getOrganizationUuid(), dto.getId());
+ public static GroupUuidOrAnyone from(GroupDto dto) {
+ return new GroupUuidOrAnyone(dto.getOrganizationUuid(), dto.getUuid());
}
- public static GroupIdOrAnyone forAnyone(String organizationUuid) {
- return new GroupIdOrAnyone(organizationUuid, null);
+ public static GroupUuidOrAnyone forAnyone(String organizationUuid) {
+ return new GroupUuidOrAnyone(organizationUuid, null);
}
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java
index 41c23d9f3ac..d608545b54a 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java
@@ -453,7 +453,7 @@ public class UserUpdater {
}
private static boolean isUserAlreadyMemberOfDefaultGroup(GroupDto defaultGroup, List<GroupDto> userGroups) {
- return userGroups.stream().anyMatch(group -> defaultGroup.getId().equals(group.getId()));
+ return userGroups.stream().anyMatch(group -> defaultGroup.getUuid().equals(group.getUuid()));
}
private void addUserToDefaultOrganizationAndDefaultGroup(DbSession dbSession, UserDto userDto) {
@@ -473,7 +473,7 @@ public class UserUpdater {
if (isUserAlreadyMemberOfDefaultGroup(defaultGroup, userGroups)) {
return;
}
- dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(defaultGroup.getId()));
+ dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupUuid(defaultGroup.getUuid()));
}
private void setNotificationsReadDate(DbSession dbSession, UserDto user) {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java
index 86379dde770..4a1f68e92b2 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupCreatorImpl.java
@@ -20,6 +20,7 @@
package org.sonar.server.usergroups;
import java.util.Optional;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.user.GroupDto;
@@ -30,9 +31,11 @@ public class DefaultGroupCreatorImpl implements DefaultGroupCreator {
public static final String DEFAULT_GROUP_NAME = "Members";
private final DbClient dbClient;
+ private final UuidFactory uuidFactory;
- public DefaultGroupCreatorImpl(DbClient dbClient) {
+ public DefaultGroupCreatorImpl(DbClient dbClient, UuidFactory uuidFactory) {
this.dbClient = dbClient;
+ this.uuidFactory = uuidFactory;
}
public GroupDto create(DbSession dbSession, String organizationUuid) {
@@ -40,11 +43,12 @@ public class DefaultGroupCreatorImpl implements DefaultGroupCreator {
checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid);
GroupDto defaultGroup = new GroupDto()
+ .setUuid(uuidFactory.create())
.setName(DEFAULT_GROUP_NAME)
.setDescription("All members of the organization")
.setOrganizationUuid(organizationUuid);
dbClient.groupDao().insert(dbSession, defaultGroup);
- dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup);
+ dbClient.organizationDao().setDefaultGroupUuid(dbSession, organizationUuid, defaultGroup);
return defaultGroup;
}
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java
index 993075bb321..4ad43db1d07 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usergroups/DefaultGroupFinder.java
@@ -35,9 +35,9 @@ public class DefaultGroupFinder {
}
public GroupDto findDefaultGroup(DbSession dbSession, String organizationUuid) {
- int defaultGroupId = dbClient.organizationDao().getDefaultGroupId(dbSession, organizationUuid)
+ String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(format("Default group cannot be found on organization '%s'", organizationUuid)));
- return requireNonNull(dbClient.groupDao().selectById(dbSession, defaultGroupId), format("Group '%s' cannot be found", defaultGroupId));
+ return requireNonNull(dbClient.groupDao().selectByUuid(dbSession, defaultGroupUuid), format("Group '%s' cannot be found", defaultGroupUuid));
}
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java
index df984ddba95..f0f63a56bfe 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java
@@ -431,9 +431,9 @@ public class HttpHeadersAuthenticationTest {
private void verityUserGroups(String login, GroupDto... expectedGroups) {
UserDto userDto = db.users().selectUserByLogin(login).get();
if (expectedGroups.length == 0) {
- assertThat(db.users().selectGroupIdsOfUser(userDto)).isEmpty();
+ assertThat(db.users().selectGroupUuidsOfUser(userDto)).isEmpty();
} else {
- assertThat(db.users().selectGroupIdsOfUser(userDto)).containsOnly(stream(expectedGroups).map(GroupDto::getId).collect(MoreCollectors.toList()).toArray(new Integer[] {}));
+ assertThat(db.users().selectGroupUuidsOfUser(userDto)).containsOnly(stream(expectedGroups).map(GroupDto::getUuid).collect(MoreCollectors.toList()).toArray(new String[] {}));
}
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java
index 27b16482f47..6229476c2d9 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java
@@ -790,7 +790,7 @@ public class UserRegistrarImplTest {
}
private void checkGroupMembership(UserDto user, GroupDto... expectedGroups) {
- assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(stream(expectedGroups).map(GroupDto::getId).collect(Collectors.toList()).toArray(new Integer[]{}));
+ assertThat(db.users().selectGroupUuidsOfUser(user)).containsOnly(stream(expectedGroups).map(GroupDto::getUuid).collect(Collectors.toList()).toArray(new String[]{}));
}
private GroupDto insertDefaultGroup() {
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java
index 885d96c0016..8735ba7f177 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/MemberUpdaterTest.java
@@ -302,10 +302,10 @@ public class MemberUpdaterTest {
underTest.removeMember(db.getSession(), organization, user);
- assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId()))
- .containsOnly(anotherGroup.getId());
- assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(db.getSession(), anotherUser.getId()))
- .containsOnly(group.getId(), anotherGroup.getId());
+ assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), user.getId()))
+ .containsOnly(anotherGroup.getUuid());
+ assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), anotherUser.getId()))
+ .containsOnly(group.getUuid(), anotherGroup.getUuid());
}
@Test
@@ -320,7 +320,7 @@ public class MemberUpdaterTest {
underTest.removeMember(db.getSession(), organization, user);
- assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(db.getSession(), user.getId())).isEmpty();
+ assertThat(dbClient.groupMembershipDao().selectGroupUuidsByUserId(db.getSession(), user.getId())).isEmpty();
}
@Test
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java
index 6bf13f57a97..fc830f021a4 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganisationSupportTest.java
@@ -61,7 +61,7 @@ public class OrganisationSupportTest {
private OrganizationFlags organizationFlags = new OrganizationFlagsImpl(dbTester.getDbClient());
private RuleIndexer ruleIndexer = spy(new RuleIndexer(es.client(), dbTester.getDbClient()));
private OrganisationSupport underTest = new OrganisationSupport(dbTester.getDbClient(), defaultOrganizationProvider, organizationFlags,
- new DefaultGroupCreatorImpl(dbTester.getDbClient()), new DefaultGroupFinder(dbTester.getDbClient()), ruleIndexer, new SequenceUuidFactory());
+ new DefaultGroupCreatorImpl(dbTester.getDbClient(), new SequenceUuidFactory()), new DefaultGroupFinder(dbTester.getDbClient()), ruleIndexer, new SequenceUuidFactory());
@Test
public void enabling_support_saves_internal_property_and_flags_caller_as_root() {
@@ -93,14 +93,14 @@ public class OrganisationSupportTest {
call(user1.getLogin());
- Optional<Integer> defaultGroupId = dbTester.getDbClient().organizationDao().getDefaultGroupId(dbTester.getSession(), defaultOrganization.getUuid());
- assertThat(defaultGroupId).isPresent();
- GroupDto membersGroup = dbTester.getDbClient().groupDao().selectById(dbTester.getSession(), defaultGroupId.get());
+ Optional<String> defaultGroupUuid = dbTester.getDbClient().organizationDao().getDefaultGroupUuid(dbTester.getSession(), defaultOrganization.getUuid());
+ assertThat(defaultGroupUuid).isPresent();
+ GroupDto membersGroup = dbTester.getDbClient().groupDao().selectByUuid(dbTester.getSession(), defaultGroupUuid.get());
assertThat(membersGroup).isNotNull();
assertThat(membersGroup.getName()).isEqualTo("Members");
- assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user1.getId())).containsOnly(defaultGroupId.get());
- assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), user2.getId())).containsOnly(defaultGroupId.get());
- assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupIdsByUserId(dbTester.getSession(), userInAnotherOrganization.getId())).isEmpty();
+ assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user1.getId())).containsOnly(defaultGroupUuid.get());
+ assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), user2.getId())).containsOnly(defaultGroupUuid.get());
+ assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserId(dbTester.getSession(), userInAnotherOrganization.getId())).isEmpty();
}
@Test
@@ -117,10 +117,10 @@ public class OrganisationSupportTest {
call(user.getLogin());
- int defaultGroupId = dbTester.getDbClient().organizationDao().getDefaultGroupId(dbTester.getSession(), defaultOrganization.getUuid()).get();
- assertThat(defaultGroupId).isNotEqualTo(sonarUsersGroup.getId());
+ String defaultGroupUuid = dbTester.getDbClient().organizationDao().getDefaultGroupUuid(dbTester.getSession(), defaultOrganization.getUuid()).get();
+ assertThat(defaultGroupUuid).isNotEqualTo(sonarUsersGroup.getUuid());
List<GroupPermissionDto> result = new ArrayList<>();
- dbTester.getDbClient().groupPermissionDao().selectAllPermissionsByGroupId(dbTester.getSession(), defaultOrganization.getUuid(), defaultGroupId,
+ dbTester.getDbClient().groupPermissionDao().selectAllPermissionsByGroupUuid(dbTester.getSession(), defaultOrganization.getUuid(), defaultGroupUuid,
context -> result.add((GroupPermissionDto) context.getResultObject()));
assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
tuple(null, "user"), tuple(project.uuid(), "codeviewer"));
@@ -140,10 +140,10 @@ public class OrganisationSupportTest {
call(user.getLogin());
- int defaultGroupId = dbTester.getDbClient().organizationDao().getDefaultGroupId(dbTester.getSession(), defaultOrganization.getUuid()).get();
- assertThat(dbTester.getDbClient().permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupId(dbTester.getSession(), defaultGroupId))
- .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission)
- .containsOnly(tuple(defaultGroupId, "user"), tuple(defaultGroupId, "admin"));
+ String defaultGroupUuid = dbTester.getDbClient().organizationDao().getDefaultGroupUuid(dbTester.getSession(), defaultOrganization.getUuid()).get();
+ assertThat(dbTester.getDbClient().permissionTemplateDao().selectAllGroupPermissionTemplatesByGroupUuid(dbTester.getSession(), defaultGroupUuid))
+ .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission)
+ .containsOnly(tuple(defaultGroupUuid, "user"), tuple(defaultGroupUuid, "admin"));
}
@Test
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java
index bcf48f97ca8..e6523acd80b 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java
@@ -104,7 +104,7 @@ public class OrganizationUpdaterImplTest {
private OrganizationValidation organizationValidation = mock(OrganizationValidation.class);
private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private UserIndex userIndex = new UserIndex(es.client(), system2);
- private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient);
+ private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient, uuidFactory);
private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
@@ -183,7 +183,7 @@ public class OrganizationUpdaterImplTest {
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, FULL_POPULATED_NEW_ORGANIZATION.getKey()).get();
GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
- int defaultGroupId = dbClient.organizationDao().getDefaultGroupId(dbSession, organization.getUuid()).get();
+ String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organization.getUuid()).get();
PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
assertThat(defaultTemplate.getName()).isEqualTo("Default template");
assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization " + FULL_POPULATED_NEW_ORGANIZATION.getName());
@@ -191,14 +191,14 @@ public class OrganizationUpdaterImplTest {
assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
assertThat(defaultTemplates.getApplicationsUuid()).isNull();
assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateUuid(dbSession, defaultTemplate.getUuid()))
- .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission)
+ .extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission)
.containsOnly(
- tuple(ownersGroup.getId(), UserRole.ADMIN),
- tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION),
- tuple(defaultGroupId, UserRole.USER),
- tuple(defaultGroupId, UserRole.CODEVIEWER),
- tuple(defaultGroupId, UserRole.ISSUE_ADMIN),
- tuple(defaultGroupId, UserRole.SECURITYHOTSPOT_ADMIN));
+ tuple(ownersGroup.getUuid(), UserRole.ADMIN),
+ tuple(ownersGroup.getUuid(), GlobalPermissions.SCAN_EXECUTION),
+ tuple(defaultGroupUuid, UserRole.USER),
+ tuple(defaultGroupUuid, UserRole.CODEVIEWER),
+ tuple(defaultGroupUuid, UserRole.ISSUE_ADMIN),
+ tuple(defaultGroupUuid, UserRole.SECURITYHOTSPOT_ADMIN));
}
@Test
@@ -378,13 +378,13 @@ public class OrganizationUpdaterImplTest {
GroupDto groupDto = groupOpt.get();
assertThat(groupDto.getDescription()).isEqualTo("Owners of organization");
- assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId()))
+ assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getUuid()))
.containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()]));
List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers(
dbSession,
UserMembershipQuery.builder()
.organizationUuid(organization.getUuid())
- .groupId(groupDto.getId())
+ .groupUuid(groupDto.getUuid())
.membership(UserMembershipQuery.IN).build(),
0, Integer.MAX_VALUE);
assertThat(members)
@@ -399,12 +399,12 @@ public class OrganizationUpdaterImplTest {
GroupDto groupDto = groupOpt.get();
assertThat(groupDto.getDescription()).isEqualTo("All members of the organization");
- assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).isEmpty();
+ assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getUuid())).isEmpty();
List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers(
dbSession,
UserMembershipQuery.builder()
.organizationUuid(organization.getUuid())
- .groupId(groupDto.getId())
+ .groupUuid(groupDto.getUuid())
.membership(UserMembershipQuery.IN).build(),
0, Integer.MAX_VALUE);
assertThat(members)
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupIdOrAnyoneTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupUuidOrAnyoneTest.java
index 73612c5ec78..7024a9b3416 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupIdOrAnyoneTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/permission/GroupUuidOrAnyoneTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.permission;
-import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -28,7 +27,7 @@ import org.sonar.db.user.GroupDto;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
-public class GroupIdOrAnyoneTest {
+public class GroupUuidOrAnyoneTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -38,7 +37,7 @@ public class GroupIdOrAnyoneTest {
expectOrganizationUuidNPE();
- GroupIdOrAnyone.from(dto);
+ GroupUuidOrAnyone.from(dto);
}
@Test
@@ -47,44 +46,44 @@ public class GroupIdOrAnyoneTest {
GroupDto dto = new GroupDto();
dto.setOrganizationUuid(organizationUuid);
- GroupIdOrAnyone underTest = GroupIdOrAnyone.from(dto);
+ GroupUuidOrAnyone underTest = GroupUuidOrAnyone.from(dto);
assertThat(underTest.getOrganizationUuid()).isEqualTo(organizationUuid);
assertThat(underTest.isAnyone()).isTrue();
- assertThat(underTest.getId()).isNull();
+ assertThat(underTest.getUuid()).isNull();
}
@Test
public void for_returns_isAnyone_false_if_id_is_not_null() {
- int id = new Random().nextInt(199);
+ String uuid = randomAlphabetic(10);
String organizationUuid = randomAlphabetic(10);
GroupDto dto = new GroupDto();
dto.setOrganizationUuid(organizationUuid);
- dto.setId(id);
+ dto.setUuid(uuid);
- GroupIdOrAnyone underTest = GroupIdOrAnyone.from(dto);
+ GroupUuidOrAnyone underTest = GroupUuidOrAnyone.from(dto);
assertThat(underTest.getOrganizationUuid()).isEqualTo(organizationUuid);
assertThat(underTest.isAnyone()).isFalse();
- assertThat(underTest.getId()).isEqualTo(id);
+ assertThat(underTest.getUuid()).isEqualTo(uuid);
}
@Test
public void forAnyone_fails_with_NPE_if_arg_is_null() {
expectOrganizationUuidNPE();
- GroupIdOrAnyone.forAnyone(null);
+ GroupUuidOrAnyone.forAnyone(null);
}
@Test
public void forAnyone_returns_isAnyone_true() {
String organizationUuid = randomAlphabetic(12);
- GroupIdOrAnyone underTest = GroupIdOrAnyone.forAnyone(organizationUuid);
+ GroupUuidOrAnyone underTest = GroupUuidOrAnyone.forAnyone(organizationUuid);
assertThat(underTest.isAnyone()).isTrue();
assertThat(underTest.getOrganizationUuid()).isEqualTo(organizationUuid);
- assertThat(underTest.getId()).isNull();
+ assertThat(underTest.getUuid()).isNull();
}
private void expectOrganizationUuidNPE() {
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java
index 86bd343e21b..0eeb5feeddb 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/tester/MockUserSessionTest.java
@@ -33,7 +33,7 @@ public class MockUserSessionTest {
assertThat(mock.getLogin()).isEqualTo("foo");
assertThat(mock.getUuid()).isEqualTo("foouuid");
- assertThat(mock.getGroups()).extracting(GroupDto::getId).containsOnly(group.getId());
+ assertThat(mock.getGroups()).extracting(GroupDto::getUuid).containsOnly(group.getUuid());
assertThat(mock.isLoggedIn()).isTrue();
}
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
index e1ccb4343d4..469a34ba93e 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
@@ -85,7 +85,7 @@ public class ServerUserSessionTest {
db.users().insertMember(group1, user);
db.users().insertMember(group2, user);
- assertThat(newUserSession(user).getGroups()).extracting(GroupDto::getId).containsOnly(group1.getId(), group2.getId());
+ assertThat(newUserSession(user).getGroups()).extracting(GroupDto::getUuid).containsOnly(group1.getUuid(), group2.getUuid());
}
@Test
@@ -96,11 +96,11 @@ public class ServerUserSessionTest {
db.users().insertMember(group1, user);
ServerUserSession session = newUserSession(user);
- assertThat(session.getGroups()).extracting(GroupDto::getId).containsOnly(group1.getId());
+ assertThat(session.getGroups()).extracting(GroupDto::getUuid).containsOnly(group1.getUuid());
// membership updated but not cache
db.users().insertMember(group2, user);
- assertThat(session.getGroups()).extracting(GroupDto::getId).containsOnly(group1.getId());
+ assertThat(session.getGroups()).extracting(GroupDto::getUuid).containsOnly(group1.getUuid());
}
@Test
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java
index d76f44355cd..682a12a9844 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java
@@ -66,7 +66,7 @@ public class ThreadLocalUserSessionTest {
assertThat(threadLocalUserSession.getLogin()).isEqualTo("karadoc");
assertThat(threadLocalUserSession.getUuid()).isEqualTo("karadoc-uuid");
assertThat(threadLocalUserSession.isLoggedIn()).isTrue();
- assertThat(threadLocalUserSession.getGroups()).extracting(GroupDto::getId).containsOnly(group.getId());
+ assertThat(threadLocalUserSession.getGroups()).extracting(GroupDto::getUuid).containsOnly(group.getUuid());
}
@Test
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java
index 330d99933c5..ef10c608f89 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java
@@ -23,6 +23,7 @@ import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
@@ -38,7 +39,7 @@ public class DefaultGroupCreatorImplTest {
@Rule
public DbTester db = DbTester.create();
- private DefaultGroupCreator underTest = new DefaultGroupCreatorImpl(db.getDbClient());
+ private DefaultGroupCreator underTest = new DefaultGroupCreatorImpl(db.getDbClient(), new SequenceUuidFactory());
@Test
public void create_default_group() {
@@ -46,9 +47,9 @@ public class DefaultGroupCreatorImplTest {
underTest.create(db.getSession(), organizationDto.getUuid());
- Optional<Integer> defaultGroupId = db.getDbClient().organizationDao().getDefaultGroupId(db.getSession(), organizationDto.getUuid());
- assertThat(defaultGroupId).isPresent();
- assertThat(db.getDbClient().groupDao().selectById(db.getSession(), defaultGroupId.get()))
+ Optional<String> defaultGroupUuid = db.getDbClient().organizationDao().getDefaultGroupUuid(db.getSession(), organizationDto.getUuid());
+ assertThat(defaultGroupUuid).isPresent();
+ assertThat(db.getDbClient().groupDao().selectByUuid(db.getSession(), defaultGroupUuid.get()))
.extracting(GroupDto::getName, GroupDto::getDescription)
.containsOnly("Members", "All members of the organization");
}
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java
index cbdf4e94187..0953963ae3c 100644
--- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java
+++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupFinderTest.java
@@ -46,7 +46,7 @@ public class DefaultGroupFinderTest {
GroupDto result = underTest.findDefaultGroup(db.getSession(), organization.getUuid());
- assertThat(result.getId()).isEqualTo(defaultGroup.getId());
+ assertThat(result.getUuid()).isEqualTo(defaultGroup.getUuid());
assertThat(result.getName()).isEqualTo("default");
}
@@ -65,10 +65,10 @@ public class DefaultGroupFinderTest {
public void fail_with_NPE_when_default_group_does_not_exist() {
OrganizationDto organization = db.organizations().insert();
GroupDto defaultGroup = db.users().insertDefaultGroup(organization, "default");
- db.getDbClient().groupDao().deleteById(db.getSession(), defaultGroup.getId());
+ db.getDbClient().groupDao().deleteByUuid(db.getSession(), defaultGroup.getUuid());
expectedException.expect(NullPointerException.class);
- expectedException.expectMessage(format("Group '%s' cannot be found", defaultGroup.getId()));
+ expectedException.expectMessage(format("Group '%s' cannot be found", defaultGroup.getUuid()));
underTest.findDefaultGroup(db.getSession(), organization.getUuid());
}