aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-11-29 21:43:29 +0100
committerSonarTech <sonartech@sonarsource.com>2018-12-12 20:21:01 +0100
commit86cd2f36c84cdf32b64765583af59c4bd6569884 (patch)
tree37647b92cc9f0f5a539ee4f5a13221903f3f089f
parent2c418ad1b5533d40152261548f43f708fa1b0df7 (diff)
downloadsonarqube-86cd2f36c84cdf32b64765583af59c4bd6569884.tar.gz
sonarqube-86cd2f36c84cdf32b64765583af59c4bd6569884.zip
SONARCLOUD-213 remove useless method in PermissionService
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java13
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/UserSessionFactoryImpl.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/PermissionServiceImplTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/UserRole.java9
14 files changed, 34 insertions, 67 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
index 8f10e7edd75..c5c7b0d189c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
@@ -25,6 +25,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.GroupPermissionDto;
+import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.server.permission.PermissionChange.Operation.ADD;
import static org.sonar.server.permission.PermissionChange.Operation.REMOVE;
@@ -34,11 +35,9 @@ import static org.sonar.server.ws.WsUtils.checkRequest;
public class GroupPermissionChanger {
private final DbClient dbClient;
- private final PermissionService permissionService;
- public GroupPermissionChanger(DbClient dbClient, PermissionService permissionService) {
+ public GroupPermissionChanger(DbClient dbClient) {
this.dbClient = dbClient;
- this.permissionService = permissionService;
}
public boolean apply(DbSession dbSession, GroupPermissionChange change) {
@@ -70,7 +69,7 @@ public class GroupPermissionChanger {
private boolean isAttemptToAddPublicPermissionToPublicComponent(GroupPermissionChange change, ProjectId projectId) {
return !projectId.isPrivate()
&& change.getOperation() == ADD
- && permissionService.getPublicPermissions().contains(change.getPermission());
+ && PUBLIC_PERMISSIONS.contains(change.getPermission());
}
private static boolean isAttemptToRemovePermissionFromAnyoneOnPrivateComponent(GroupPermissionChange change, ProjectId projectId) {
@@ -100,7 +99,7 @@ public class GroupPermissionChanger {
private boolean isAttemptToRemovePublicPermissionFromPublicComponent(GroupPermissionChange change, ProjectId projectId) {
return !projectId.isPrivate()
&& change.getOperation() == REMOVE
- && permissionService.getPublicPermissions().contains(change.getPermission());
+ && PUBLIC_PERMISSIONS.contains(change.getPermission());
}
private boolean addPermission(DbSession dbSession, GroupPermissionChange change) {
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 6c84667e897..4ee354afe1a 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
@@ -27,5 +27,5 @@ public interface PermissionService {
List<OrganizationPermission> getAllOrganizationPermissions();
List<String> getAllProjectPermissions();
- List<String> getPublicPermissions();
+
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java
index ef614b8bd32..76c54faf52d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java
@@ -39,11 +39,6 @@ public class PermissionServiceImpl implements PermissionService {
private static final List<OrganizationPermission> ALL_GLOBAL_PERMISSIONS = ImmutableList.copyOf(OrganizationPermission.values());
- /**
- * Permissions which are implicitly available for any user, any group and to group "AnyOne" on public components.
- */
- private static final List<String> PUBLIC_PERMISSIONS = ImmutableList.of(UserRole.USER, UserRole.CODEVIEWER);
-
private final List<OrganizationPermission> globalPermissions;
private final List<String> projectPermissions;
@@ -73,12 +68,4 @@ public class PermissionServiceImpl implements PermissionService {
public List<String> getAllProjectPermissions() {
return projectPermissions;
}
-
- /**
- * Permissions which are implicitly available for any user, any group and to group "AnyOne" on public components.
- */
- @Override
- public List<String> getPublicPermissions() {
- return PUBLIC_PERMISSIONS;
- }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
index 3b7d08010ec..7824a71b2cc 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
@@ -51,6 +51,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static org.sonar.api.security.DefaultGroups.isAnyone;
+import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
@ServerSide
public class PermissionTemplateService {
@@ -170,7 +171,7 @@ public class PermissionTemplateService {
}
private boolean permissionValidForProject(ComponentDto project, String permission) {
- return project.isPrivate() || !permissionService.getPublicPermissions().contains(permission);
+ return project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission);
}
private static boolean groupNameValidForProject(ComponentDto project, String groupName) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java b/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
index 0143a3be8cf..45e7775f6f4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/UserPermissionChanger.java
@@ -25,6 +25,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.UserPermissionDto;
+import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.server.permission.PermissionChange.Operation.ADD;
import static org.sonar.server.permission.PermissionChange.Operation.REMOVE;
@@ -36,11 +37,9 @@ import static org.sonar.server.ws.WsUtils.checkRequest;
public class UserPermissionChanger {
private final DbClient dbClient;
- private final PermissionService permissionService;
- public UserPermissionChanger(DbClient dbClient, PermissionService permissionService) {
+ public UserPermissionChanger(DbClient dbClient) {
this.dbClient = dbClient;
- this.permissionService = permissionService;
}
public boolean apply(DbSession dbSession, UserPermissionChange change) {
@@ -71,7 +70,7 @@ public class UserPermissionChanger {
private boolean isAttemptToAddPublicPermissionToPublicComponent(UserPermissionChange change, ProjectId projectId) {
return !projectId.isPrivate()
&& change.getOperation() == ADD
- && permissionService.getPublicPermissions().contains(change.getPermission());
+ && PUBLIC_PERMISSIONS.contains(change.getPermission());
}
private void ensureConsistencyWithVisibility(UserPermissionChange change) {
@@ -84,7 +83,7 @@ public class UserPermissionChanger {
private boolean isAttemptToRemovePublicPermissionFromPublicComponent(UserPermissionChange change, ProjectId projectId) {
return !projectId.isPrivate()
&& change.getOperation() == REMOVE
- && permissionService.getPublicPermissions().contains(change.getPermission());
+ && PUBLIC_PERMISSIONS.contains(change.getPermission());
}
private boolean addPermission(DbSession dbSession, UserPermissionChange change) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
index 8103fe582d7..473c393e597 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
@@ -44,6 +44,7 @@ import org.sonarqube.ws.client.project.ProjectsWsParameters;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
+import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.WsUtils.checkRequest;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
@@ -136,7 +137,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
// delete project permissions for group AnyOne
dbClient.groupPermissionDao().deleteByRootComponentIdAndGroupId(dbSession, component.getId(), null);
// grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project
- permissionService.getPublicPermissions().forEach(permission -> {
+ PUBLIC_PERMISSIONS.forEach(permission -> {
dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission)
.forEach(groupId -> insertProjectPermissionOnGroup(dbSession, component, permission, groupId));
dbClient.userPermissionDao().selectUserIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission)
@@ -157,7 +158,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
}
private void updatePermissionsToPublic(DbSession dbSession, ComponentDto component) {
- permissionService.getPublicPermissions().forEach(permission -> {
+ PUBLIC_PERMISSIONS.forEach(permission -> {
// delete project group permission for UserRole.CODEVIEWER and UserRole.USER
dbClient.groupPermissionDao().deleteByRootComponentIdAndPermission(dbSession, component.getId(), permission);
// delete project user permission for UserRole.CODEVIEWER and UserRole.USER
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java b/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java
index 563042db0ed..f28b38dce51 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java
@@ -43,12 +43,12 @@ import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.OrganizationFlags;
-import org.sonar.server.permission.PermissionService;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+import static org.sonar.api.web.UserRole.PUBLIC_PERMISSIONS;
/**
* Implementation of {@link UserSession} used in web server
@@ -62,18 +62,16 @@ public class ServerUserSession extends AbstractUserSession {
private final Supplier<Collection<GroupDto>> groups = Suppliers.memoize(this::loadGroups);
private final Supplier<Boolean> isSystemAdministratorSupplier = Suppliers.memoize(this::loadIsSystemAdministrator);
private final Map<String, String> projectUuidByComponentUuid = new HashMap<>();
- private final PermissionService permissionService;
private Map<String, Set<OrganizationPermission>> permissionsByOrganizationUuid;
private Map<String, Set<String>> permissionsByProjectUuid;
private Set<String> organizationMembership = new HashSet<>();
ServerUserSession(DbClient dbClient, OrganizationFlags organizationFlags,
- DefaultOrganizationProvider defaultOrganizationProvider, @Nullable UserDto userDto, PermissionService permissionService) {
+ DefaultOrganizationProvider defaultOrganizationProvider, @Nullable UserDto userDto) {
this.dbClient = dbClient;
this.organizationFlags = organizationFlags;
this.defaultOrganizationProvider = defaultOrganizationProvider;
this.userDto = userDto;
- this.permissionService = permissionService;
}
private Collection<GroupDto> loadGroups() {
@@ -200,7 +198,7 @@ public class ServerUserSession extends AbstractUserSession {
return loadDbPermissions(dbSession, projectUuid);
}
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
- builder.addAll(permissionService.getPublicPermissions());
+ builder.addAll(PUBLIC_PERMISSIONS);
builder.addAll(loadDbPermissions(dbSession, projectUuid));
return builder.build();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserSessionFactoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserSessionFactoryImpl.java
index dac7bd4a5c3..e50a32dde9b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/UserSessionFactoryImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserSessionFactoryImpl.java
@@ -24,7 +24,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.user.UserDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.OrganizationFlags;
-import org.sonar.server.permission.PermissionService;
import static java.util.Objects.requireNonNull;
@@ -34,24 +33,22 @@ public class UserSessionFactoryImpl implements UserSessionFactory {
private final DbClient dbClient;
private final DefaultOrganizationProvider defaultOrganizationProvider;
private final OrganizationFlags organizationFlags;
- private final PermissionService permissionService;
public UserSessionFactoryImpl(DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider,
- OrganizationFlags organizationFlags, PermissionService permissionService) {
+ OrganizationFlags organizationFlags) {
this.dbClient = dbClient;
this.defaultOrganizationProvider = defaultOrganizationProvider;
this.organizationFlags = organizationFlags;
- this.permissionService = permissionService;
}
@Override
public ServerUserSession create(UserDto user) {
requireNonNull(user, "UserDto must not be null");
- return new ServerUserSession(dbClient, organizationFlags, defaultOrganizationProvider, user, permissionService);
+ return new ServerUserSession(dbClient, organizationFlags, defaultOrganizationProvider, user);
}
@Override
public ServerUserSession createAnonymous() {
- return new ServerUserSession(dbClient, organizationFlags, defaultOrganizationProvider, null, permissionService);
+ return new ServerUserSession(dbClient, organizationFlags, defaultOrganizationProvider, null);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
index 6323fbae13c..e760c83cc22 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
@@ -38,10 +38,7 @@ import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
-import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.usergroups.ws.GroupIdOrAnyone;
-import org.sonar.server.usergroups.ws.GroupWsSupport;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@@ -56,11 +53,9 @@ public class GroupPermissionChangerTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private GroupWsSupport groupWsSupport = new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider, new DefaultGroupFinder(db.getDbClient()));
private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
- private GroupPermissionChanger underTest = new GroupPermissionChanger(db.getDbClient(), permissionService);
+ private GroupPermissionChanger underTest = new GroupPermissionChanger(db.getDbClient());
private OrganizationDto org;
private GroupDto group;
private ComponentDto privateProject;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionServiceImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionServiceImplTest.java
index 5936b6ac186..bcbbdcd295f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionServiceImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/PermissionServiceImplTest.java
@@ -25,7 +25,6 @@ import org.sonar.db.permission.OrganizationPermission;
import static org.assertj.core.api.Assertions.assertThat;
-
public class PermissionServiceImplTest {
private ResourceTypesRule resourceTypesRule = new ResourceTypesRule().setRootQualifiers("APP", "VW");
@@ -39,12 +38,6 @@ public class PermissionServiceImplTest {
}
@Test
- public void publicPermissions_must_be_ordered() {
- assertThat(underTest.getPublicPermissions())
- .containsExactly("user", "codeviewer");
- }
-
- @Test
public void projectPermissions_must_be_ordered() {
assertThat(underTest.getAllProjectPermissions())
.containsExactly("admin", "codeviewer", "issueadmin", "securityhotspotadmin", "scan", "user");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
index cef415d87d4..a15051f70a1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/UserPermissionChangerTest.java
@@ -59,8 +59,7 @@ public class UserPermissionChangerTest {
private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-
- private UserPermissionChanger underTest = new UserPermissionChanger(db.getDbClient(), permissionService);
+ private UserPermissionChanger underTest = new UserPermissionChanger(db.getDbClient());
private OrganizationDto org1;
private OrganizationDto org2;
private UserDto user1;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java
index 40ff8b09ca9..2df0afdbeba 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java
@@ -23,7 +23,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
@@ -35,8 +34,6 @@ import org.sonar.server.es.EsTester;
import org.sonar.server.es.ProjectIndexersImpl;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.permission.GroupPermissionChanger;
-import org.sonar.server.permission.PermissionService;
-import org.sonar.server.permission.PermissionServiceImpl;
import org.sonar.server.permission.PermissionUpdater;
import org.sonar.server.permission.UserPermissionChanger;
import org.sonar.server.permission.index.FooIndexDefinition;
@@ -61,9 +58,6 @@ public abstract class BasePermissionWsTest<A extends PermissionsWsAction> {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- protected ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- protected PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
protected UserSessionRule userSession = UserSessionRule.standalone();
protected WsActionTester wsTester;
@@ -91,8 +85,8 @@ public abstract class BasePermissionWsTest<A extends PermissionsWsAction> {
protected PermissionUpdater newPermissionUpdater() {
return new PermissionUpdater(
new ProjectIndexersImpl(new PermissionIndexer(db.getDbClient(), es.client())),
- new UserPermissionChanger(db.getDbClient(), permissionService),
- new GroupPermissionChanger(db.getDbClient(), permissionService));
+ new UserPermissionChanger(db.getDbClient()),
+ new GroupPermissionChanger(db.getDbClient()));
}
protected TestRequest newRequest() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
index 83caa654df2..cb4ce3b82c4 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
@@ -38,8 +38,6 @@ import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.organization.TestOrganizationFlags;
-import org.sonar.server.permission.PermissionService;
-import org.sonar.server.permission.PermissionServiceImpl;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Arrays.asList;
@@ -58,9 +56,6 @@ public class ServerUserSessionTest {
public DbTester db = DbTester.create(System2.INSTANCE);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT);
- private PermissionService permissionService = new PermissionServiceImpl(resourceTypes);
-
private DbClient dbClient = db.getDbClient();
private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
@@ -703,7 +698,7 @@ public class ServerUserSessionTest {
}
private ServerUserSession newUserSession(@Nullable UserDto userDto) {
- return new ServerUserSession(dbClient, organizationFlags, defaultOrganizationProvider, userDto, permissionService);
+ return new ServerUserSession(dbClient, organizationFlags, defaultOrganizationProvider, userDto);
}
private ServerUserSession newAnonymousSession() {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/UserRole.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/UserRole.java
index 196218cdc51..fb582ea5b7c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/UserRole.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/UserRole.java
@@ -23,6 +23,10 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
/**
* @since 1.11
@@ -49,4 +53,9 @@ public @interface UserRole {
String[] value() default {};
+ /**
+ * Permissions which are implicitly available for any user, any group and to group "AnyOne" on public components.
+ */
+ Set<String> PUBLIC_PERMISSIONS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(UserRole.USER, UserRole.CODEVIEWER)));
+
}