aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-06-11 16:23:04 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-06-11 16:23:04 +0200
commitcef90a32b3dcf0d9242fcbdc394548227221d472 (patch)
treeb9c0a3eeaaca1acfebdb795d3f0ecd34ecb77d82
parent28d75d24014a6f32ad55c084da4107b4085fd039 (diff)
downloadsonarqube-cef90a32b3dcf0d9242fcbdc394548227221d472.tar.gz
sonarqube-cef90a32b3dcf0d9242fcbdc394548227221d472.zip
SONAR-6565 Prevent IllegalStateException from spewing to server log
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java5
2 files changed, 9 insertions, 5 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 15a34dfea51..6e849793bbc 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
@@ -24,6 +24,7 @@ import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
+import java.net.HttpURLConnection;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
@@ -44,6 +45,7 @@ import org.sonar.core.user.UserGroupDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.Message;
+import org.sonar.server.exceptions.ServerException;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.util.Validation;
@@ -313,7 +315,7 @@ public class UserUpdater {
private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
final String defaultGroup = settings.getString(CoreProperties.CORE_DEFAULT_GROUP);
if (defaultGroup == null) {
- throw new IllegalStateException(String.format("The default group property '%s' is null", CoreProperties.CORE_DEFAULT_GROUP));
+ throw new ServerException(HttpURLConnection.HTTP_INTERNAL_ERROR, String.format("The default group property '%s' is null", CoreProperties.CORE_DEFAULT_GROUP));
}
List<GroupDto> userGroups = dbClient.groupDao().findByUserLogin(dbSession, userDto.getLogin());
if (!Iterables.any(userGroups, new Predicate<GroupDto>() {
@@ -324,8 +326,9 @@ public class UserUpdater {
})) {
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));
+ throw new ServerException(HttpURLConnection.HTTP_INTERNAL_ERROR,
+ 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 2a0564f0651..29527c23b81 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
@@ -43,6 +43,7 @@ import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.Message;
+import org.sonar.server.exceptions.ServerException;
import org.sonar.server.user.db.GroupDao;
import org.sonar.server.user.db.UserDao;
import org.sonar.server.user.db.UserGroupDao;
@@ -492,7 +493,7 @@ public class UserUpdaterTest {
.setPasswordConfirmation("password")
.setScmAccounts(newArrayList("u1", "u_1")));
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("The default group property 'sonar.defaultGroup' is null");
+ assertThat(e).isInstanceOf(ServerException.class).hasMessage("The default group property 'sonar.defaultGroup' is null");
}
}
@@ -509,7 +510,7 @@ public class UserUpdaterTest {
.setPasswordConfirmation("password")
.setScmAccounts(newArrayList("u1", "u_1")));
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class)
+ assertThat(e).isInstanceOf(ServerException.class)
.hasMessage("The default group 'polop' for new users does not exist. Please update the general security settings to fix this issue.");
}
}