aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-06-09 13:38:34 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-06-09 13:38:39 +0200
commit6e85ae2bcf98c12c634e792742a72b8e02a04d33 (patch)
tree9f28c352128a43df8da250abb46d2c9956233a98 /server
parent8b0a4ad39bcfd68d74ca476a6cced91ebe9a3876 (diff)
downloadsonarqube-6e85ae2bcf98c12c634e792742a72b8e02a04d33.tar.gz
sonarqube-6e85ae2bcf98c12c634e792742a72b8e02a04d33.zip
SONAR-6565 Display a clear message when default group does not exist
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java18
2 files changed, 23 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
index 557d398fd6f..15a34dfea51 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
@@ -322,7 +322,11 @@ public class UserUpdater {
return input != null && input.getKey().equals(defaultGroup);
}
})) {
- GroupDto groupDto = dbClient.groupDao().selectByKey(dbSession, defaultGroup);
+ GroupDto groupDto = dbClient.groupDao().selectNullableByKey(dbSession, defaultGroup);
+ if (groupDto == null) {
+ throw new IllegalStateException(String.format("The default group '%s' for new users does not exist. Please update the general security settings to fix this issue.",
+ defaultGroup));
+ }
dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(groupDto.getId()));
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
index a9169d47908..2a0564f0651 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
@@ -497,6 +497,24 @@ public class UserUpdaterTest {
}
@Test
+ public void fail_to_associate_default_group_when_default_group_does_not_exist() {
+ settings.setProperty(CoreProperties.CORE_DEFAULT_GROUP, "polop");
+
+ try {
+ userUpdater.create(NewUser.create()
+ .setLogin("user")
+ .setName("User")
+ .setEmail("user@mail.com")
+ .setPassword("password")
+ .setPasswordConfirmation("password")
+ .setScmAccounts(newArrayList("u1", "u_1")));
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class)
+ .hasMessage("The default group 'polop' for new users does not exist. Please update the general security settings to fix this issue.");
+ }
+ }
+
+ @Test
public void reactivate_user_when_creating_user_with_existing_login() {
db.prepareDbUnit(getClass(), "reactivate_user.xml");
when(system2.now()).thenReturn(1418215735486L);