diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-10-06 11:38:58 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-10-06 11:43:47 +0200 |
commit | 96f6a9d147111f89d6a9ee7ad61f484ae08dc5d8 (patch) | |
tree | c44aadfd73ce9a9850fc4204fddc358ab49a3684 | |
parent | 81c45e4bca28565774bb668bdd60da35f2df32e8 (diff) | |
download | sonarqube-96f6a9d147111f89d6a9ee7ad61f484ae08dc5d8.tar.gz sonarqube-96f6a9d147111f89d6a9ee7ad61f484ae08dc5d8.zip |
Fix quality flaws
6 files changed, 82 insertions, 14 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/Messages.java b/server/sonar-server/src/main/java/org/sonar/server/batch/Messages.java index 71c877da110..40e05183577 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/Messages.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/Messages.java @@ -24,5 +24,5 @@ public class Messages { // constants } - static String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator."; + static final String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator."; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java index 2dbe0d3611d..b9454a2545d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java @@ -88,7 +88,7 @@ public class ComponentFinder { return component.get(); } - private void checkIsProjectOrModule(ComponentDto component, ResourceTypes resourceTypes) { + private static void checkIsProjectOrModule(ComponentDto component, ResourceTypes resourceTypes) { Set<String> rootQualifiers = from(resourceTypes.getRoots()) .transform(RESOURCE_TYPE_TO_QUALIFIER) .toSet(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java index 5e18899fc33..ed223457c31 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java @@ -22,7 +22,6 @@ package org.sonar.server.permission; import java.util.List; import org.sonar.api.server.ServerSide; -import org.sonar.api.web.UserRole; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -30,7 +29,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ResourceDto; import org.sonar.db.permission.PermissionRepository; import org.sonar.server.component.ComponentFinder; -import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.issue.index.IssueAuthorizationIndexer; import org.sonar.server.user.UserSession; @@ -73,7 +71,7 @@ public class PermissionService { ComponentDto component = componentFinder.getByKey(session, componentKey); ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey); if (provisioned == null) { - checkProjectAdminPermission(componentKey); + checkProjectAdminUserByComponentKey(userSession, componentKey); } else { userSession.checkGlobalPermission(GlobalPermissions.PROVISIONING); } @@ -106,12 +104,6 @@ public class PermissionService { indexProjectPermissions(); } - private void checkProjectAdminPermission(String projectKey) { - if (!userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) && !userSession.hasProjectPermission(UserRole.ADMIN, projectKey)) { - throw new ForbiddenException("Insufficient privileges"); - } - } - private void indexProjectPermissions() { issueAuthorizationIndexer.index(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/DefaultPermissionTemplateFinder.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/DefaultPermissionTemplateFinder.java index f309355ff53..196b8bf537d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/DefaultPermissionTemplateFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/DefaultPermissionTemplateFinder.java @@ -30,9 +30,9 @@ import org.sonar.api.resources.ResourceTypes; import static com.google.common.collect.FluentIterable.from; import static com.google.common.collect.Ordering.natural; +import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY; import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty; -import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; public class DefaultPermissionTemplateFinder { private final Settings settings; @@ -84,8 +84,7 @@ public class DefaultPermissionTemplateFinder { @Override public String apply(@Nonnull String qualifier) { - String effectiveTemplateUuid = effectiveTemplateUuid(settings, qualifier); - return effectiveTemplateUuid; + return effectiveTemplateUuid(settings, qualifier); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWsParameters.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWsParameters.java index 8b0550352ea..d40d245f052 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWsParameters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWsParameters.java @@ -28,6 +28,10 @@ public class UserGroupsWsParameters { static final String PARAM_GROUP_ID = "id"; static final String PARAM_LOGIN = "login"; + private UserGroupsWsParameters() { + // static methods only + } + static void createGroupParameters(NewAction action) { createGroupIdParameter(action); createGroupNameParameter(action); diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java new file mode 100644 index 00000000000..08c63a39962 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java @@ -0,0 +1,73 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.server.permission.ws.template; + +import com.google.common.collect.HashBasedTable; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.resources.Qualifiers; + +import static java.util.Collections.singletonList; +import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto; + +public class SearchTemplatesDataTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + SearchTemplatesData.Builder underTest = SearchTemplatesData.newBuilder() + .defaultTemplates(singletonList(new DefaultPermissionTemplateFinder.TemplateUuidQualifier("template_uuid", Qualifiers.PROJECT))) + .templates(singletonList(newPermissionTemplateDto())) + .userCountByTemplateIdAndPermission(HashBasedTable.<Long, String, Integer>create()) + .groupCountByTemplateIdAndPermission(HashBasedTable.<Long, String, Integer>create()); + + @Test + public void fail_if_templates_is_null() { + expectedException.expect(IllegalStateException.class); + underTest.templates(null); + + underTest.build(); + } + + @Test + public void fail_if_default_templates_are_null() { + expectedException.expect(IllegalStateException.class); + underTest.defaultTemplates(null); + + underTest.build(); + } + + @Test + public void fail_if_user_count_is_null() { + expectedException.expect(IllegalStateException.class); + underTest.userCountByTemplateIdAndPermission(null); + + underTest.build(); + } + + @Test + public void fail_if_group_count_is_null() { + expectedException.expect(IllegalStateException.class); + underTest.groupCountByTemplateIdAndPermission(null); + + underTest.build(); + } +} |