}
}
- public static void checkAdministrationPermission(UserSession userSession, Optional<ProjectId> projectId) {
+ /**
+ * Checks that user is administrator of the specified project, or of the specified organization if project is not
+ * defined.
+ * @throws org.sonar.server.exceptions.ForbiddenException if user is not administrator
+ */
+ public static void checkProjectAdmin(UserSession userSession, String organizationUuid, Optional<ProjectId> projectId) {
+ userSession.checkLoggedIn();
+ if (!projectId.isPresent() || !userSession.hasComponentUuidPermission(UserRole.ADMIN, projectId.get().getUuid())) {
+ userSession.checkOrganizationPermission(organizationUuid, GlobalPermissions.SYSTEM_ADMIN);
+ }
+ }
+
+ /**
+ * Checks that user is administrator of the specified project, or of system if project is not
+ * defined.
+ * @throws org.sonar.server.exceptions.ForbiddenException if user is not administrator
+ * @deprecated does not support organizations. Replaced by {@link #checkProjectAdmin(UserSession, String, Optional)}
+ */
+ @Deprecated
+ public static void checkProjectAdmin(UserSession userSession, Optional<ProjectId> projectId) {
userSession.checkLoggedIn();
if (!projectId.isPresent() || !userSession.hasComponentUuidPermission(UserRole.ADMIN, projectId.get().getUuid())) {
userSession.checkPermission(GlobalPermissions.SYSTEM_ADMIN);
import org.sonar.server.usergroups.ws.GroupIdOrAnyone;
import static java.util.Arrays.asList;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministratorOfProjectOrOrganization;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupIdParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupNameParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
GroupIdOrAnyone group = support.findGroup(dbSession, request);
Optional<ProjectId> projectId = support.findProject(dbSession, request);
- checkAdministratorOfProjectOrOrganization(userSession, group.getOrganizationUuid(), projectId);
+ checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId);
PermissionChange change = new GroupPermissionChange(
PermissionChange.Operation.ADD,
import org.sonar.server.user.UserSession;
import static java.util.Arrays.asList;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministratorOfProjectOrOrganization;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createOrganizationParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
Optional<ProjectId> projectId = support.findProject(dbSession, request);
OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION_KEY));
- checkAdministratorOfProjectOrOrganization(userSession, org.getUuid(), projectId);
+ checkProjectAdmin(userSession, org.getUuid(), projectId);
PermissionChange change = new UserPermissionChange(
PermissionChange.Operation.ADD,
import static org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE;
import static org.sonar.db.permission.PermissionQuery.RESULTS_MAX_SIZE;
import static org.sonar.db.permission.PermissionQuery.SEARCH_QUERY_MIN_LENGTH;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministrationPermission;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ProjectId> projectId = support.findProject(dbSession, request);
- checkAdministrationPermission(userSession, projectId);
+ checkProjectAdmin(userSession, projectId);
PermissionQuery query = buildPermissionQuery(request, projectId);
// TODO validatePermission(groupsRequest.getPermission(), wsProjectRef);
import org.sonar.server.usergroups.ws.GroupIdOrAnyone;
import static java.util.Arrays.asList;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministrationPermission;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupIdParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupNameParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
GroupIdOrAnyone group = support.findGroup(dbSession, request);
Optional<ProjectId> projectId = support.findProject(dbSession, request);
- checkAdministrationPermission(userSession, projectId);
+ checkProjectAdmin(userSession, projectId);
PermissionChange change = new GroupPermissionChange(
PermissionChange.Operation.REMOVE,
import org.sonar.server.user.UserSession;
import static java.util.Arrays.asList;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministrationPermission;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createOrganizationParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
Optional<ProjectId> projectId = support.findProject(dbSession, request);
OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION_KEY));
- checkAdministrationPermission(userSession, projectId);
+ checkProjectAdmin(userSession, projectId);
PermissionChange change = new UserPermissionChange(
PermissionChange.Operation.REMOVE,
import org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse.Project;
import org.sonarqube.ws.client.permission.SearchProjectPermissionsWsRequest;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministrationPermission;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validateQualifier;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
import static org.sonar.server.permission.ws.ProjectWsRef.newOptionalWsProjectRef;
private final PermissionWsSupport wsSupport;
public SearchProjectPermissionsAction(DbClient dbClient, UserSession userSession, I18n i18n, ResourceTypes resourceTypes,
- SearchProjectPermissionsDataLoader dataLoader, PermissionWsSupport wsSupport) {
+ SearchProjectPermissionsDataLoader dataLoader, PermissionWsSupport wsSupport) {
this.dbClient = dbClient;
this.userSession = userSession;
this.i18n = i18n;
} else {
projectId = Optional.empty();
}
- checkAdministrationPermission(userSession, projectId);
+ checkProjectAdmin(userSession, projectId);
}
private SearchProjectPermissionsWsResponse buildResponse(SearchProjectPermissionsData data) {
import static org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE;
import static org.sonar.db.permission.PermissionQuery.RESULTS_MAX_SIZE;
import static org.sonar.db.permission.PermissionQuery.SEARCH_QUERY_MIN_LENGTH;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkAdministrationPermission;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validateGlobalPermission;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<ProjectId> projectId = support.findProject(dbSession, request);
- checkAdministrationPermission(userSession, projectId);
+ checkProjectAdmin(userSession, projectId);
PermissionQuery query = buildPermissionQuery(request, projectId);
List<UserDto> users = findUsers(dbSession, query);