aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-07-03 14:49:39 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-07-03 15:08:06 +0200
commit5ccbb39d22b649cf47b0082b1b198783596b417e (patch)
treeb58770fb8e1882c4108d0bfe4462d068edc56a00 /sonar-core
parentbd9e609162e5c0420a7ac7c2d7c06580020db59d (diff)
downloadsonarqube-5ccbb39d22b649cf47b0082b1b198783596b417e.tar.gz
sonarqube-5ccbb39d22b649cf47b0082b1b198783596b417e.zip
Refator permissions to share same constants between Ruby and Java
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/user/Permission.java64
-rw-r--r--sonar-core/src/main/java/org/sonar/core/user/Permissions.java36
-rw-r--r--sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java18
3 files changed, 73 insertions, 45 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/user/Permission.java b/sonar-core/src/main/java/org/sonar/core/user/Permission.java
new file mode 100644
index 00000000000..be5fb50a755
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/user/Permission.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.core.user;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ *
+ * Holds the constants representing the various global permissions that can be assigned to users & groups
+ *
+ * @since 3.7
+ */
+public class Permission {
+
+ public static final Permission SYSTEM_ADMIN = new Permission("admin");
+ public static final Permission QUALITY_PROFILE_ADMIN = new Permission("profileadmin");
+ public static final Permission DASHBOARD_SHARING = new Permission("shareDashboard");
+ public static final Permission SCAN_EXECUTION = new Permission("scan");
+ public static final Permission DRY_RUN_EXECUTION = new Permission("dryRunScan");
+
+ private final String key;
+ // Use linked hash map to preserve order
+ private static Map<String, Permission> allGlobal = new LinkedHashMap<String, Permission>();
+
+ static {
+ allGlobal.put(SYSTEM_ADMIN.key, SYSTEM_ADMIN);
+ allGlobal.put(QUALITY_PROFILE_ADMIN.key, QUALITY_PROFILE_ADMIN);
+ allGlobal.put(DASHBOARD_SHARING.key, DASHBOARD_SHARING);
+ allGlobal.put(SCAN_EXECUTION.key, SCAN_EXECUTION);
+ allGlobal.put(DRY_RUN_EXECUTION.key, DRY_RUN_EXECUTION);
+ }
+
+ private Permission(String key) {
+ this.key = key;
+ }
+
+ public String key() {
+ return key;
+ }
+
+ public static Map<String, Permission> allGlobal() {
+ return allGlobal;
+ }
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/user/Permissions.java b/sonar-core/src/main/java/org/sonar/core/user/Permissions.java
deleted file mode 100644
index db6ad9d6e09..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/user/Permissions.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.core.user;
-
-/**
- *
- * Holds the constants representing the various permissions that can be assigned to users & groups
- *
- * @since 3.7
- */
-public interface Permissions {
-
- String SYSTEM_ADMIN = "admin";
- String QUALITY_PROFILE_ADMIN = "profileadmin";
- String DASHBOARD_SHARING = "shareDashboard";
- String SCAN_EXECUTION = "scan";
- String DRY_RUN_EXECUTION = "dryRunScan";
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java
index 33eae64cf56..582616cc5a6 100644
--- a/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java
@@ -34,8 +34,8 @@ public class RoleDaoTest extends AbstractDaoTestCase {
RoleDao dao = new RoleDao(getMyBatis());
- assertThat(dao.selectUserPermissions("admin_user")).containsOnly(Permissions.SYSTEM_ADMIN, Permissions.QUALITY_PROFILE_ADMIN);
- assertThat(dao.selectUserPermissions("profile_admin_user")).containsOnly(Permissions.QUALITY_PROFILE_ADMIN);
+ assertThat(dao.selectUserPermissions("admin_user")).containsOnly(Permission.SYSTEM_ADMIN.key(), Permission.QUALITY_PROFILE_ADMIN.key());
+ assertThat(dao.selectUserPermissions("profile_admin_user")).containsOnly(Permission.QUALITY_PROFILE_ADMIN.key());
}
@Test
@@ -44,18 +44,18 @@ public class RoleDaoTest extends AbstractDaoTestCase {
RoleDao dao = new RoleDao(getMyBatis());
- assertThat(dao.selectGroupPermissions("sonar-administrators")).containsOnly(Permissions.SYSTEM_ADMIN, Permissions.QUALITY_PROFILE_ADMIN,
- Permissions.DASHBOARD_SHARING, Permissions.DRY_RUN_EXECUTION, Permissions.SCAN_EXECUTION);
- assertThat(dao.selectGroupPermissions("sonar-users")).containsOnly(Permissions.DASHBOARD_SHARING, Permissions.DRY_RUN_EXECUTION,
- Permissions.SCAN_EXECUTION);
- assertThat(dao.selectGroupPermissions(DefaultGroups.ANYONE)).containsOnly(Permissions.DRY_RUN_EXECUTION, Permissions.SCAN_EXECUTION);
+ assertThat(dao.selectGroupPermissions("sonar-administrators")).containsOnly(Permission.SYSTEM_ADMIN.key(), Permission.QUALITY_PROFILE_ADMIN.key(),
+ Permission.DASHBOARD_SHARING.key(), Permission.DRY_RUN_EXECUTION.key(), Permission.SCAN_EXECUTION.key());
+ assertThat(dao.selectGroupPermissions("sonar-users")).containsOnly(Permission.DASHBOARD_SHARING.key(), Permission.DRY_RUN_EXECUTION.key(),
+ Permission.SCAN_EXECUTION.key());
+ assertThat(dao.selectGroupPermissions(DefaultGroups.ANYONE)).containsOnly(Permission.DRY_RUN_EXECUTION.key(), Permission.SCAN_EXECUTION.key());
}
@Test
public void should_delete_user_global_permission() throws Exception {
setupData("userPermissions");
- UserRoleDto userRoleToDelete = new UserRoleDto().setUserId(200L).setRole(Permissions.QUALITY_PROFILE_ADMIN);
+ UserRoleDto userRoleToDelete = new UserRoleDto().setUserId(200L).setRole(Permission.QUALITY_PROFILE_ADMIN.key());
RoleDao dao = new RoleDao(getMyBatis());
dao.deleteUserRole(userRoleToDelete);
@@ -67,7 +67,7 @@ public class RoleDaoTest extends AbstractDaoTestCase {
public void should_delete_group_global_permission() throws Exception {
setupData("groupPermissions");
- GroupRoleDto groupRoleToDelete = new GroupRoleDto().setGroupId(100L).setRole(Permissions.QUALITY_PROFILE_ADMIN);
+ GroupRoleDto groupRoleToDelete = new GroupRoleDto().setGroupId(100L).setRole(Permission.QUALITY_PROFILE_ADMIN.key());
RoleDao dao = new RoleDao(getMyBatis());
dao.deleteGroupRole(groupRoleToDelete);