]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8227 Move org.sonar.server.issue.index.IssueAuthorizationIndexer to org.sonar...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Oct 2016 13:01:38 +0000 (15:01 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 20 Oct 2016 11:12:07 +0000 (13:12 +0200)
This indexer will also be used to feed the authorization type of projectmeasures index

32 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java
server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationIndexer.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionUpdater.java
server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationDao.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationDaoTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationDaoTest/no_authorization.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationIndexerTest/index.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationDaoTest/no_authorization.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationDaoTest/shared.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationIndexerTest/index.xml [new file with mode: 0644]

index 6dbda3f2f7375ea6fda3124b502547d60ea60a06..32dc0e95471e0c5944ab29a3703a3b3d30c145a5 100644 (file)
@@ -75,7 +75,6 @@ import org.sonar.server.debt.DebtModelPluginRepository;
 import org.sonar.server.debt.DebtRulesXMLImporter;
 import org.sonar.server.event.NewAlerts;
 import org.sonar.server.issue.IssueUpdater;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher;
@@ -100,6 +99,7 @@ import org.sonar.server.permission.GroupPermissionChanger;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.UserPermissionChanger;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.platform.DatabaseServerCompatibility;
 import org.sonar.server.platform.DefaultServerUpgradeStatus;
 import org.sonar.server.platform.ServerFileSystemImpl;
@@ -340,7 +340,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
 
       // issues
       IssueIndexer.class,
-      IssueAuthorizationIndexer.class,
+      AuthorizationIndexer.class,
       IssueUpdater.class, // used in Web Services and CE's DebtCalculator
       FunctionExecutor.class, // used by IssueWorkflow
       IssueWorkflow.class, // used in Web Services and CE's DebtCalculator
index 2ad193b9ccf03c4600d8d67bde4ba74a07c26d13..1aae37b7b7459d34cc1c63b48f05ddb67247a835 100644 (file)
@@ -29,8 +29,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.component.es.ProjectMeasuresIndexer;
 import org.sonar.server.test.index.TestIndexer;
 
@@ -39,14 +39,14 @@ import org.sonar.server.test.index.TestIndexer;
 public class ComponentCleanerService {
 
   private final DbClient dbClient;
-  private final IssueAuthorizationIndexer issueAuthorizationIndexer;
+  private final AuthorizationIndexer issueAuthorizationIndexer;
   private final IssueIndexer issueIndexer;
   private final TestIndexer testIndexer;
   private final ProjectMeasuresIndexer projectMeasuresIndexer;
   private final ResourceTypes resourceTypes;
   private final ComponentFinder componentFinder;
 
-  public ComponentCleanerService(DbClient dbClient, IssueAuthorizationIndexer issueAuthorizationIndexer, IssueIndexer issueIndexer,
+  public ComponentCleanerService(DbClient dbClient, AuthorizationIndexer issueAuthorizationIndexer, IssueIndexer issueIndexer,
                                  TestIndexer testIndexer, ProjectMeasuresIndexer projectMeasuresIndexer, ResourceTypes resourceTypes, ComponentFinder componentFinder) {
     this.dbClient = dbClient;
     this.issueAuthorizationIndexer = issueAuthorizationIndexer;
index f3229145c8182e3af22b6e3e169a646ef025801e..ab411e4a5ac7ab950bf999021c64024e96d82378 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.server.computation.task.projectanalysis.component.DepthTraversa
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
 import org.sonar.server.computation.task.step.ComputationStep;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 
 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.VIEW;
@@ -42,12 +42,12 @@ public class ApplyPermissionsStep implements ComputationStep {
 
   private final DbClient dbClient;
   private final DbIdsRepository dbIdsRepository;
-  private final IssueAuthorizationIndexer indexer;
+  private final AuthorizationIndexer indexer;
   private final PermissionRepository permissionRepository;
   private final TreeRootHolder treeRootHolder;
 
-  public ApplyPermissionsStep(DbClient dbClient, DbIdsRepository dbIdsRepository, IssueAuthorizationIndexer indexer, PermissionRepository permissionRepository,
-    TreeRootHolder treeRootHolder) {
+  public ApplyPermissionsStep(DbClient dbClient, DbIdsRepository dbIdsRepository, AuthorizationIndexer indexer, PermissionRepository permissionRepository,
+                              TreeRootHolder treeRootHolder) {
     this.dbClient = dbClient;
     this.dbIdsRepository = dbIdsRepository;
     this.indexer = indexer;
index 4285b9b612835747d8e9d5552674390b6ed7a289..a6e473bbea41f4973782ff29c3e64114cfb28960 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.server.es;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.component.es.ProjectMeasuresIndexer;
 import org.sonar.server.test.index.TestIndexer;
 import org.sonar.server.user.index.UserIndexer;
@@ -34,7 +34,7 @@ public class IndexerStartupTask {
   private static final Logger LOG = Loggers.get(IndexerStartupTask.class);
 
   private final TestIndexer testIndexer;
-  private final IssueAuthorizationIndexer issueAuthorizationIndexer;
+  private final AuthorizationIndexer issueAuthorizationIndexer;
   private final IssueIndexer issueIndexer;
   private final UserIndexer userIndexer;
   private final ViewIndexer viewIndexer;
@@ -43,12 +43,12 @@ public class IndexerStartupTask {
 
   /**
    * Limitation - {@link org.sonar.server.es.BaseIndexer} are not injected through an array or a collection
-   * because we need {@link org.sonar.server.issue.index.IssueAuthorizationIndexer} to be executed before
+   * because we need {@link AuthorizationIndexer} to be executed before
    * {@link org.sonar.server.issue.index.IssueIndexer}
    */
-  public IndexerStartupTask(TestIndexer testIndexer, IssueAuthorizationIndexer issueAuthorizationIndexer, IssueIndexer issueIndexer,
-    UserIndexer userIndexer, ViewIndexer viewIndexer, ProjectMeasuresIndexer projectMeasuresIndexer,
-    Settings settings) {
+  public IndexerStartupTask(TestIndexer testIndexer, AuthorizationIndexer issueAuthorizationIndexer, IssueIndexer issueIndexer,
+                            UserIndexer userIndexer, ViewIndexer viewIndexer, ProjectMeasuresIndexer projectMeasuresIndexer,
+                            Settings settings) {
     this.testIndexer = testIndexer;
     this.issueAuthorizationIndexer = issueAuthorizationIndexer;
     this.issueIndexer = issueIndexer;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java
deleted file mode 100644 (file)
index fb82b3d..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.issue.index;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-
-/**
- * No streaming because of union of joins -> no need to use ResultSetIterator
- */
-public class IssueAuthorizationDao {
-
-  public static final class Dto {
-    private final String projectUuid;
-    private final long updatedAt;
-    private final List<String> users = Lists.newArrayList();
-    private final List<String> groups = Lists.newArrayList();
-
-    public Dto(String projectUuid, long updatedAt) {
-      this.projectUuid = projectUuid;
-      this.updatedAt = updatedAt;
-    }
-
-    public String getProjectUuid() {
-      return projectUuid;
-    }
-
-    public long getUpdatedAt() {
-      return updatedAt;
-    }
-
-    public List<String> getUsers() {
-      return users;
-    }
-
-    public Dto addUser(String s) {
-      users.add(s);
-      return this;
-    }
-
-    public Dto addGroup(String s) {
-      groups.add(s);
-      return this;
-    }
-
-    public List<String> getGroups() {
-      return groups;
-    }
-  }
-
-  private static final String SQL_TEMPLATE =
-    "SELECT " +
-      "  project_authorization.project as project, " +
-      "  project_authorization.login as login, " +
-      "  project_authorization.permission_group as permission_group, " +
-      "  project_authorization.updated_at as updated_at " +
-      "FROM ( " +
-
-      // project is returned when no authorization
-      "      SELECT " +
-      "      projects.uuid AS project, " +
-      "      projects.authorization_updated_at AS updated_at, " +
-      "      NULL AS login, " +
-      "      NULL  AS permission_group " +
-      "      FROM projects " +
-      "      WHERE " +
-      "        projects.qualifier = 'TRK' " +
-      "        AND projects.copy_component_uuid is NULL " +
-      "        {dateCondition} " +
-      "      UNION " +
-
-      // users
-
-      "      SELECT " +
-      "      projects.uuid AS project, " +
-      "      projects.authorization_updated_at AS updated_at, " +
-      "      users.login  AS login, " +
-      "      NULL  AS permission_group " +
-      "      FROM projects " +
-      "      INNER JOIN user_roles ON user_roles.resource_id = projects.id AND user_roles.role = 'user' " +
-      "      INNER JOIN users ON users.id = user_roles.user_id " +
-      "      WHERE " +
-      "        projects.qualifier = 'TRK' " +
-      "        AND projects.copy_component_uuid is NULL " +
-      "        {dateCondition} " +
-      "      UNION " +
-
-      // groups without Anyone
-
-      "      SELECT " +
-      "      projects.uuid AS project, " +
-      "      projects.authorization_updated_at AS updated_at, " +
-      "      NULL  AS login, " +
-      "      groups.name  AS permission_group " +
-      "      FROM projects " +
-      "      INNER JOIN group_roles ON group_roles.resource_id = projects.id AND group_roles.role = 'user' " +
-      "      INNER JOIN groups ON groups.id = group_roles.group_id " +
-      "      WHERE " +
-      "        projects.qualifier = 'TRK' " +
-      "        AND projects.copy_component_uuid is NULL " +
-      "        {dateCondition} " +
-      "        AND group_id IS NOT NULL " +
-      "      UNION " +
-
-      // Anyone groups
-
-      "      SELECT " +
-      "      projects.uuid AS project, " +
-      "      projects.authorization_updated_at AS updated_at, " +
-      "      NULL         AS login, " +
-      "      'Anyone'     AS permission_group " +
-      "      FROM projects " +
-      "      INNER JOIN group_roles ON group_roles.resource_id = projects.id AND group_roles.role='user' " +
-      "      WHERE " +
-      "        projects.qualifier = 'TRK' " +
-      "        AND projects.copy_component_uuid is NULL " +
-      "        {dateCondition} " +
-      "        AND group_roles.group_id IS NULL " +
-      "    ) project_authorization";
-
-  Collection<Dto> selectAfterDate(DbClient dbClient, DbSession session, long afterDate) {
-    try {
-      Map<String, Dto> dtosByProjectUuid = Maps.newHashMap();
-      PreparedStatement stmt = null;
-      ResultSet rs = null;
-      try {
-        stmt = createStatement(dbClient, session, afterDate);
-        rs = stmt.executeQuery();
-        while (rs.next()) {
-          processRow(rs, dtosByProjectUuid);
-        }
-        return dtosByProjectUuid.values();
-      } finally {
-        DbUtils.closeQuietly(rs);
-        DbUtils.closeQuietly(stmt);
-      }
-    } catch (SQLException e) {
-      throw new IllegalStateException("Fail to select issue authorizations after date: " + afterDate, e);
-    }
-  }
-
-  private static PreparedStatement createStatement(DbClient dbClient, DbSession session, long afterDate) throws SQLException {
-    String sql;
-    if (afterDate > 0L) {
-      sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", " AND projects.authorization_updated_at>? ");
-    } else {
-      sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", "");
-    }
-    PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
-    if (afterDate > 0L) {
-      for (int i = 1; i <= 4; i++) {
-        stmt.setLong(i, afterDate);
-      }
-    }
-    return stmt;
-  }
-
-  private static void processRow(ResultSet rs, Map<String, Dto> dtosByProjectUuid) throws SQLException {
-    String projectUuid = rs.getString(1);
-    String userLogin = rs.getString(2);
-    String group = rs.getString(3);
-
-    Dto dto = dtosByProjectUuid.get(projectUuid);
-    if (dto == null) {
-      long updatedAt = rs.getLong(4);
-      dto = new Dto(projectUuid, updatedAt);
-      dtosByProjectUuid.put(projectUuid, dto);
-    }
-    if (StringUtils.isNotBlank(userLogin)) {
-      dto.addUser(userLogin);
-    }
-    if (StringUtils.isNotBlank(group)) {
-      dto.addGroup(group);
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationIndexer.java
deleted file mode 100644 (file)
index 71568f2..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.issue.index;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableMap;
-import org.elasticsearch.action.ActionRequest;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbClient;
-import org.sonar.server.es.BaseIndexer;
-import org.sonar.server.es.BulkIndexer;
-import org.sonar.server.es.EsClient;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-
-/**
- * Manages the synchronization of index issues/authorization with authorization settings defined in database :
- * <ul>
- *   <li>index the projects with recent permission changes</li>
- *   <li>delete project orphans from index</li>
- * </ul>
- */
-public class IssueAuthorizationIndexer extends BaseIndexer {
-
-  private final DbClient dbClient;
-
-  public IssueAuthorizationIndexer(DbClient dbClient, EsClient esClient) {
-    super(esClient, 0L, IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT);
-    this.dbClient = dbClient;
-  }
-
-  @Override
-  protected long doIndex(long lastUpdatedAt) {
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      // warning - do not enable large mode, else disabling of replicas
-      // will impact the type "issue" which is much bigger than issueAuthorization
-      BulkIndexer bulk = new BulkIndexer(esClient, IssueIndexDefinition.INDEX);
-
-      IssueAuthorizationDao dao = new IssueAuthorizationDao();
-      Collection<IssueAuthorizationDao.Dto> authorizations = dao.selectAfterDate(dbClient, dbSession, lastUpdatedAt);
-      return doIndex(bulk, authorizations);
-    }
-  }
-
-  @VisibleForTesting
-  public void index(Collection<IssueAuthorizationDao.Dto> authorizations) {
-    final BulkIndexer bulk = new BulkIndexer(esClient, IssueIndexDefinition.INDEX);
-    doIndex(bulk, authorizations);
-  }
-
-  private long doIndex(BulkIndexer bulk, Collection<IssueAuthorizationDao.Dto> authorizations) {
-    long maxDate = 0L;
-    bulk.start();
-    for (IssueAuthorizationDao.Dto authorization : authorizations) {
-      bulk.add(newUpdateRequest(authorization));
-      maxDate = Math.max(maxDate, authorization.getUpdatedAt());
-    }
-    bulk.stop();
-    return maxDate;
-  }
-
-  public void deleteProject(String uuid, boolean refresh) {
-    esClient
-      .prepareDelete(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, uuid)
-      .setRefresh(refresh)
-      .setRouting(uuid)
-      .get();
-  }
-
-  private static ActionRequest newUpdateRequest(IssueAuthorizationDao.Dto dto) {
-    Map<String, Object> doc = ImmutableMap.of(
-      IssueIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID, dto.getProjectUuid(),
-      IssueIndexDefinition.FIELD_AUTHORIZATION_GROUPS, dto.getGroups(),
-      IssueIndexDefinition.FIELD_AUTHORIZATION_USERS, dto.getUsers(),
-      IssueIndexDefinition.FIELD_AUTHORIZATION_UPDATED_AT, new Date(dto.getUpdatedAt()));
-    return new UpdateRequest(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, dto.getProjectUuid())
-      .routing(dto.getProjectUuid())
-      .doc(doc)
-      .upsert(doc);
-  }
-}
index 3ad1b779073aa64ed8d4744f5f4216d30aad2eba..df1d9d3037cc298cc9fdc51a09c3238d2bf5579e 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.db.component.ResourceDto;
 import org.sonar.db.permission.PermissionRepository;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.user.UserSession;
 
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
@@ -43,12 +43,12 @@ public class PermissionService {
 
   private final DbClient dbClient;
   private final PermissionRepository permissionRepository;
-  private final IssueAuthorizationIndexer issueAuthorizationIndexer;
+  private final AuthorizationIndexer issueAuthorizationIndexer;
   private final UserSession userSession;
   private final ComponentFinder componentFinder;
 
-  public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, IssueAuthorizationIndexer issueAuthorizationIndexer, UserSession userSession,
-    ComponentFinder componentFinder) {
+  public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, AuthorizationIndexer issueAuthorizationIndexer, UserSession userSession,
+                           ComponentFinder componentFinder) {
     this.dbClient = dbClient;
     this.permissionRepository = permissionRepository;
     this.issueAuthorizationIndexer = issueAuthorizationIndexer;
index 78d9cdbf7331bacc762f5d14d5edb34094c07f80..07403ad42e08e3a5f173313e16e70c77357b8a34 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Optional;
 import java.util.Set;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 
 /**
  * Add or remove global/project permissions to a group. This class
@@ -35,11 +35,11 @@ import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 public class PermissionUpdater {
 
   private final DbClient dbClient;
-  private final IssueAuthorizationIndexer issueAuthorizationIndexer;
+  private final AuthorizationIndexer issueAuthorizationIndexer;
   private final UserPermissionChanger userPermissionChanger;
   private final GroupPermissionChanger groupPermissionChanger;
 
-  public PermissionUpdater(DbClient dbClient, IssueAuthorizationIndexer issueAuthorizationIndexer,
+  public PermissionUpdater(DbClient dbClient, AuthorizationIndexer issueAuthorizationIndexer,
     UserPermissionChanger userPermissionChanger, GroupPermissionChanger groupPermissionChanger) {
     this.dbClient = dbClient;
     this.issueAuthorizationIndexer = issueAuthorizationIndexer;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationDao.java b/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationDao.java
new file mode 100644 (file)
index 0000000..066a9f2
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.index;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.dbutils.DbUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+
+/**
+ * No streaming because of union of joins -> no need to use ResultSetIterator
+ */
+public class AuthorizationDao {
+
+  public static final class Dto {
+    private final String projectUuid;
+    private final long updatedAt;
+    private final List<String> users = Lists.newArrayList();
+    private final List<String> groups = Lists.newArrayList();
+
+    public Dto(String projectUuid, long updatedAt) {
+      this.projectUuid = projectUuid;
+      this.updatedAt = updatedAt;
+    }
+
+    public String getProjectUuid() {
+      return projectUuid;
+    }
+
+    public long getUpdatedAt() {
+      return updatedAt;
+    }
+
+    public List<String> getUsers() {
+      return users;
+    }
+
+    public Dto addUser(String s) {
+      users.add(s);
+      return this;
+    }
+
+    public Dto addGroup(String s) {
+      groups.add(s);
+      return this;
+    }
+
+    public List<String> getGroups() {
+      return groups;
+    }
+  }
+
+  private static final String SQL_TEMPLATE =
+    "SELECT " +
+      "  project_authorization.project as project, " +
+      "  project_authorization.login as login, " +
+      "  project_authorization.permission_group as permission_group, " +
+      "  project_authorization.updated_at as updated_at " +
+      "FROM ( " +
+
+      // project is returned when no authorization
+      "      SELECT " +
+      "      projects.uuid AS project, " +
+      "      projects.authorization_updated_at AS updated_at, " +
+      "      NULL AS login, " +
+      "      NULL  AS permission_group " +
+      "      FROM projects " +
+      "      WHERE " +
+      "        projects.qualifier = 'TRK' " +
+      "        AND projects.copy_component_uuid is NULL " +
+      "        {dateCondition} " +
+      "      UNION " +
+
+      // users
+
+      "      SELECT " +
+      "      projects.uuid AS project, " +
+      "      projects.authorization_updated_at AS updated_at, " +
+      "      users.login  AS login, " +
+      "      NULL  AS permission_group " +
+      "      FROM projects " +
+      "      INNER JOIN user_roles ON user_roles.resource_id = projects.id AND user_roles.role = 'user' " +
+      "      INNER JOIN users ON users.id = user_roles.user_id " +
+      "      WHERE " +
+      "        projects.qualifier = 'TRK' " +
+      "        AND projects.copy_component_uuid is NULL " +
+      "        {dateCondition} " +
+      "      UNION " +
+
+      // groups without Anyone
+
+      "      SELECT " +
+      "      projects.uuid AS project, " +
+      "      projects.authorization_updated_at AS updated_at, " +
+      "      NULL  AS login, " +
+      "      groups.name  AS permission_group " +
+      "      FROM projects " +
+      "      INNER JOIN group_roles ON group_roles.resource_id = projects.id AND group_roles.role = 'user' " +
+      "      INNER JOIN groups ON groups.id = group_roles.group_id " +
+      "      WHERE " +
+      "        projects.qualifier = 'TRK' " +
+      "        AND projects.copy_component_uuid is NULL " +
+      "        {dateCondition} " +
+      "        AND group_id IS NOT NULL " +
+      "      UNION " +
+
+      // Anyone groups
+
+      "      SELECT " +
+      "      projects.uuid AS project, " +
+      "      projects.authorization_updated_at AS updated_at, " +
+      "      NULL         AS login, " +
+      "      'Anyone'     AS permission_group " +
+      "      FROM projects " +
+      "      INNER JOIN group_roles ON group_roles.resource_id = projects.id AND group_roles.role='user' " +
+      "      WHERE " +
+      "        projects.qualifier = 'TRK' " +
+      "        AND projects.copy_component_uuid is NULL " +
+      "        {dateCondition} " +
+      "        AND group_roles.group_id IS NULL " +
+      "    ) project_authorization";
+
+  Collection<Dto> selectAfterDate(DbClient dbClient, DbSession session, long afterDate) {
+    try {
+      Map<String, Dto> dtosByProjectUuid = Maps.newHashMap();
+      PreparedStatement stmt = null;
+      ResultSet rs = null;
+      try {
+        stmt = createStatement(dbClient, session, afterDate);
+        rs = stmt.executeQuery();
+        while (rs.next()) {
+          processRow(rs, dtosByProjectUuid);
+        }
+        return dtosByProjectUuid.values();
+      } finally {
+        DbUtils.closeQuietly(rs);
+        DbUtils.closeQuietly(stmt);
+      }
+    } catch (SQLException e) {
+      throw new IllegalStateException("Fail to select authorizations after date: " + afterDate, e);
+    }
+  }
+
+  private static PreparedStatement createStatement(DbClient dbClient, DbSession session, long afterDate) throws SQLException {
+    String sql;
+    if (afterDate > 0L) {
+      sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", " AND projects.authorization_updated_at>? ");
+    } else {
+      sql = StringUtils.replace(SQL_TEMPLATE, "{dateCondition}", "");
+    }
+    PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
+    if (afterDate > 0L) {
+      for (int i = 1; i <= 4; i++) {
+        stmt.setLong(i, afterDate);
+      }
+    }
+    return stmt;
+  }
+
+  private static void processRow(ResultSet rs, Map<String, Dto> dtosByProjectUuid) throws SQLException {
+    String projectUuid = rs.getString(1);
+    String userLogin = rs.getString(2);
+    String group = rs.getString(3);
+
+    Dto dto = dtosByProjectUuid.get(projectUuid);
+    if (dto == null) {
+      long updatedAt = rs.getLong(4);
+      dto = new Dto(projectUuid, updatedAt);
+      dtosByProjectUuid.put(projectUuid, dto);
+    }
+    if (StringUtils.isNotBlank(userLogin)) {
+      dto.addUser(userLogin);
+    }
+    if (StringUtils.isNotBlank(group)) {
+      dto.addGroup(group);
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java
new file mode 100644 (file)
index 0000000..83a0870
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.index;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.server.es.BaseIndexer;
+import org.sonar.server.es.BulkIndexer;
+import org.sonar.server.es.EsClient;
+import org.sonar.server.issue.index.IssueIndexDefinition;
+
+/**
+ * Manages the synchronization of index issues/authorization with authorization settings defined in database :
+ * <ul>
+ *   <li>index the projects with recent permission changes</li>
+ *   <li>delete project orphans from index</li>
+ * </ul>
+ */
+public class AuthorizationIndexer extends BaseIndexer {
+
+  private final DbClient dbClient;
+
+  public AuthorizationIndexer(DbClient dbClient, EsClient esClient) {
+    super(esClient, 0L, IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT);
+    this.dbClient = dbClient;
+  }
+
+  @Override
+  protected long doIndex(long lastUpdatedAt) {
+    try (DbSession dbSession = dbClient.openSession(false)) {
+      // warning - do not enable large mode, else disabling of replicas
+      // will impact the type "issue" which is much bigger than issueAuthorization
+      BulkIndexer bulk = new BulkIndexer(esClient, IssueIndexDefinition.INDEX);
+
+      AuthorizationDao dao = new AuthorizationDao();
+      Collection<AuthorizationDao.Dto> authorizations = dao.selectAfterDate(dbClient, dbSession, lastUpdatedAt);
+      return doIndex(bulk, authorizations);
+    }
+  }
+
+  @VisibleForTesting
+  public void index(Collection<AuthorizationDao.Dto> authorizations) {
+    final BulkIndexer bulk = new BulkIndexer(esClient, IssueIndexDefinition.INDEX);
+    doIndex(bulk, authorizations);
+  }
+
+  private long doIndex(BulkIndexer bulk, Collection<AuthorizationDao.Dto> authorizations) {
+    long maxDate = 0L;
+    bulk.start();
+    for (AuthorizationDao.Dto authorization : authorizations) {
+      bulk.add(newIssueUpdateRequest(authorization));
+      maxDate = Math.max(maxDate, authorization.getUpdatedAt());
+    }
+    bulk.stop();
+    return maxDate;
+  }
+
+  public void deleteProject(String uuid, boolean refresh) {
+    esClient
+      .prepareDelete(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, uuid)
+      .setRefresh(refresh)
+      .setRouting(uuid)
+      .get();
+  }
+
+  private static ActionRequest newIssueUpdateRequest(AuthorizationDao.Dto dto) {
+    Map<String, Object> doc = ImmutableMap.of(
+      IssueIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID, dto.getProjectUuid(),
+      IssueIndexDefinition.FIELD_AUTHORIZATION_GROUPS, dto.getGroups(),
+      IssueIndexDefinition.FIELD_AUTHORIZATION_USERS, dto.getUsers(),
+      IssueIndexDefinition.FIELD_AUTHORIZATION_UPDATED_AT, new Date(dto.getUpdatedAt()));
+    return new UpdateRequest(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, dto.getProjectUuid())
+      .routing(dto.getProjectUuid())
+      .doc(doc)
+      .upsert(doc);
+  }
+}
index 134897cf4110e133af4222ae59ada3073adca9f4..1e25081156a84a86dfd8e8d4cf3678c95559b8a1 100644 (file)
@@ -102,7 +102,6 @@ import org.sonar.server.issue.SetSeverityAction;
 import org.sonar.server.issue.SetTypeAction;
 import org.sonar.server.issue.TransitionAction;
 import org.sonar.server.issue.filter.IssueFilterWsModule;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher;
@@ -140,6 +139,7 @@ import org.sonar.server.permission.GroupPermissionChanger;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.UserPermissionChanger;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.permission.ws.PermissionsWsModule;
 import org.sonar.server.platform.BackendCleanup;
 import org.sonar.server.platform.PersistentSettings;
@@ -457,7 +457,7 @@ public class PlatformLevel4 extends PlatformLevel {
       // issues
       IssueIndexDefinition.class,
       IssueIndexer.class,
-      IssueAuthorizationIndexer.class,
+      AuthorizationIndexer.class,
       ServerIssueStorage.class,
       IssueUpdater.class,
       FunctionExecutor.class,
index 69194e8f21684599aa9a2c69276eef2f22f3c0cb..62190745f3a29aa94356f4296f7adb2241e05f9e 100644 (file)
@@ -39,12 +39,12 @@ import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.index.IssueAuthorizationDao;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationDao;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.platform.ServerFileSystem;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
@@ -78,7 +78,7 @@ public class IssuesActionTest {
 
   private IssueIndex issueIndex;
   private IssueIndexer issueIndexer;
-  private IssueAuthorizationIndexer issueAuthorizationIndexer;
+  private AuthorizationIndexer issueAuthorizationIndexer;
   private ServerFileSystem fs = mock(ServerFileSystem.class);
 
   WsTester tester;
@@ -89,7 +89,7 @@ public class IssuesActionTest {
   public void before() {
     issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSessionRule);
     issueIndexer = new IssueIndexer(null, es.client());
-    issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, es.client());
+    issueAuthorizationIndexer = new AuthorizationIndexer(null, es.client());
     issuesAction = new IssuesAction(db.getDbClient(), issueIndex, userSessionRule, new ComponentFinder(db.getDbClient()));
 
     tester = new WsTester(new BatchWs(new BatchIndex(fs), issuesAction));
@@ -329,7 +329,7 @@ public class IssuesActionTest {
   }
 
   private void addIssueAuthorization(String projectUuid, @Nullable String group, @Nullable String user) {
-    issueAuthorizationIndexer.index(newArrayList(new IssueAuthorizationDao.Dto(projectUuid, 1).addGroup(group).addUser(user)));
+    issueAuthorizationIndexer.index(newArrayList(new AuthorizationDao.Dto(projectUuid, 1).addGroup(group).addUser(user)));
   }
 
   private void addBrowsePermissionOnComponent(String componentKey) {
index b534beadc487c973dd65b5d13413f18cc262e84c..11238b7e0ea831926942f72384c53a3063bda608 100644 (file)
@@ -42,9 +42,9 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.issue.IssueTesting;
 import org.sonar.server.issue.index.IssueAuthorizationDoc;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.component.es.ProjectMeasuresIndexDefinition;
 import org.sonar.server.component.es.ProjectMeasuresIndexer;
 import org.sonar.server.test.index.TestDoc;
@@ -78,7 +78,7 @@ public class ComponentCleanerServiceTest {
   DbClient dbClient = db.getDbClient();
   DbSession dbSession = db.getSession();
 
-  IssueAuthorizationIndexer issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, es.client());
+  AuthorizationIndexer issueAuthorizationIndexer = new AuthorizationIndexer(dbClient, es.client());
   IssueIndexer issueIndexer = new IssueIndexer(dbClient, es.client());
   TestIndexer testIndexer = new TestIndexer(dbClient, es.client());
   ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
index 91f7679d3e0abcb3425cdb1a2e31a224094c73b5..0ae9354a80ca7410a767ecbd0c845f558911e901 100644 (file)
@@ -45,8 +45,8 @@ import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolde
 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
 import org.sonar.server.computation.task.step.ComputationStep;
 import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.component.ComponentTesting.newView;
@@ -76,14 +76,14 @@ public class ApplyPermissionsStepTest extends BaseStepTest {
   private DbSession dbSession;
   private DbClient dbClient = dbTester.getDbClient();
   private Settings settings = new MapSettings();
-  private IssueAuthorizationIndexer issueAuthorizationIndexer;
+  private AuthorizationIndexer issueAuthorizationIndexer;
   private ApplyPermissionsStep step;
 
   @Before
   public void setUp() {
     dbSession = dbClient.openSession(false);
 
-    issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, esTester.client());
+    issueAuthorizationIndexer = new AuthorizationIndexer(dbClient, esTester.client());
 
     step = new ApplyPermissionsStep(dbClient, dbIdsRepository, issueAuthorizationIndexer, new PermissionRepository(dbClient, settings), treeRootHolder);
   }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java
deleted file mode 100644 (file)
index cf78f4f..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.issue.index;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import java.util.Collection;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class IssueAuthorizationDaoTest {
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  private IssueAuthorizationDao dao = new IssueAuthorizationDao();
-
-  @Test
-  public void select_all() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
-    assertThat(dtos).hasSize(2);
-
-    IssueAuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
-    assertThat(abc.getGroups()).containsOnly("Anyone", "devs");
-    assertThat(abc.getUsers()).containsOnly("user1");
-    assertThat(abc.getUpdatedAt()).isNotNull();
-
-    IssueAuthorizationDao.Dto def = Iterables.find(dtos, new ProjectPredicate("DEF"));
-    assertThat(def.getGroups()).containsOnly("Anyone");
-    assertThat(def.getUsers()).containsOnly("user1", "user2");
-    assertThat(def.getUpdatedAt()).isNotNull();
-  }
-
-  @Test
-  public void select_after_date() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 1500000000L);
-
-    // only project DEF was updated in this period
-    assertThat(dtos).hasSize(1);
-    IssueAuthorizationDao.Dto def = Iterables.find(dtos, new ProjectPredicate("DEF"));
-    assertThat(def).isNotNull();
-    assertThat(def.getGroups()).containsOnly("Anyone");
-    assertThat(def.getUsers()).containsOnly("user1", "user2");
-  }
-
-  @Test
-  public void no_authorization() {
-    dbTester.prepareDbUnit(getClass(), "no_authorization.xml");
-
-    Collection<IssueAuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
-
-    assertThat(dtos).hasSize(1);
-    IssueAuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
-    assertThat(abc.getGroups()).isEmpty();
-    assertThat(abc.getUsers()).isEmpty();
-    assertThat(abc.getUpdatedAt()).isNotNull();
-  }
-
-  private static class ProjectPredicate implements Predicate<IssueAuthorizationDao.Dto> {
-
-    private final String projectUuid;
-
-    ProjectPredicate(String projectUuid) {
-      this.projectUuid = projectUuid;
-    }
-
-    @Override
-    public boolean apply(IssueAuthorizationDao.Dto input) {
-      return input.getProjectUuid().equals(projectUuid);
-    }
-
-    @Override
-    public boolean equals(Object object) {
-      return true;
-    }
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java
deleted file mode 100644 (file)
index a17eda2..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.issue.index;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import org.elasticsearch.search.SearchHit;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbTester;
-import org.sonar.server.es.EsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class IssueAuthorizationIndexerTest {
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
-
-  @Test
-  public void index_nothing() {
-    IssueAuthorizationIndexer indexer = createIndexer();
-    indexer.index();
-
-    assertThat(esTester.countDocuments("issues", "authorization")).isZero();
-  }
-
-  @Test
-  public void index() {
-    dbTester.prepareDbUnit(getClass(), "index.xml");
-
-    IssueAuthorizationIndexer indexer = createIndexer();
-    indexer.doIndex(0L);
-
-    List<SearchHit> docs = esTester.getDocuments("issues", "authorization");
-    assertThat(docs).hasSize(1);
-    SearchHit doc = docs.get(0);
-    assertThat(doc.getSource().get("project")).isEqualTo("ABC");
-    assertThat((Collection) doc.getSource().get("groups")).containsOnly("devs", "Anyone");
-    assertThat((Collection) doc.getSource().get("users")).containsOnly("user1");
-
-    // delete project
-    indexer.deleteProject("ABC", true);
-
-    assertThat(esTester.countDocuments("issues", "issueAuthorization")).isZero();
-  }
-
-  @Test
-  public void do_not_fail_when_deleting_unindexed_project() {
-    IssueAuthorizationIndexer indexer = createIndexer();
-    indexer.deleteProject("UNKNOWN", true);
-    assertThat(esTester.countDocuments("issues", "authorization")).isZero();
-  }
-
-  @Test
-  public void delete_permissions() {
-    IssueAuthorizationIndexer indexer = createIndexer();
-    IssueAuthorizationDao.Dto authorization = new IssueAuthorizationDao.Dto("ABC", System.currentTimeMillis());
-    authorization.addUser("guy");
-    authorization.addGroup("dev");
-    indexer.index(Arrays.asList(authorization));
-
-    // has permissions
-    assertThat(esTester.countDocuments("issues", "authorization")).isEqualTo(1);
-
-    // remove permissions -> dto has no users nor groups
-    authorization = new IssueAuthorizationDao.Dto("ABC", System.currentTimeMillis());
-    indexer.index(Arrays.asList(authorization));
-
-    List<SearchHit> docs = esTester.getDocuments("issues", "authorization");
-    assertThat(docs).hasSize(1);
-    assertThat((Collection)docs.get(0).sourceAsMap().get(IssueIndexDefinition.FIELD_AUTHORIZATION_USERS)).hasSize(0);
-    assertThat((Collection)docs.get(0).sourceAsMap().get(IssueIndexDefinition.FIELD_AUTHORIZATION_GROUPS)).hasSize(0);
-  }
-
-  private IssueAuthorizationIndexer createIndexer() {
-    return new IssueAuthorizationIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
-  }
-}
index 1e1bc821cd7f9f11d7d36697be6b31cd97f762f4..65117b830decde0059d78b2319687e0e25eb3c96 100644 (file)
@@ -41,6 +41,8 @@ import org.sonar.server.es.SearchResult;
 import org.sonar.server.issue.IssueQuery;
 import org.sonar.server.issue.IssueQuery.Builder;
 import org.sonar.server.issue.IssueTesting;
+import org.sonar.server.permission.index.AuthorizationDao;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.view.index.ViewIndexDefinition;
 import org.sonar.server.view.index.ViewIndexer;
@@ -64,13 +66,13 @@ public class IssueIndexDebtTest {
   IssueIndex index;
 
   IssueIndexer issueIndexer;
-  IssueAuthorizationIndexer issueAuthorizationIndexer;
+  AuthorizationIndexer issueAuthorizationIndexer;
   ViewIndexer viewIndexer;
 
   @Before
   public void setUp() {
     issueIndexer = new IssueIndexer(null, tester.client());
-    issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
+    issueAuthorizationIndexer = new AuthorizationIndexer(null, tester.client());
     viewIndexer = new ViewIndexer(null, tester.client());
     System2 system = mock(System2.class);
     when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
@@ -285,7 +287,7 @@ public class IssueIndexDebtTest {
   }
 
   private void addIssueAuthorization(String projectUuid, @Nullable String group, @Nullable String user) {
-    issueAuthorizationIndexer.index(newArrayList(new IssueAuthorizationDao.Dto(projectUuid, 1).addGroup(group).addUser(user)));
+    issueAuthorizationIndexer.index(newArrayList(new AuthorizationDao.Dto(projectUuid, 1).addGroup(group).addUser(user)));
   }
 
   private Builder newQueryBuilder() {
index db9145d7a85de3dd4530f634c9818af4053b073d..e60c23c85d8fe215b4ce898c7a88c64343472de5 100644 (file)
@@ -50,6 +50,8 @@ import org.sonar.server.es.SearchResult;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.issue.IssueQuery;
 import org.sonar.server.issue.IssueTesting;
+import org.sonar.server.permission.index.AuthorizationDao;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.view.index.ViewDoc;
 import org.sonar.server.view.index.ViewIndexDefinition;
@@ -77,13 +79,13 @@ public class IssueIndexTest {
   IssueIndex underTest;
 
   IssueIndexer issueIndexer;
-  IssueAuthorizationIndexer issueAuthorizationIndexer;
+  AuthorizationIndexer issueAuthorizationIndexer;
   ViewIndexer viewIndexer;
 
   @Before
   public void setUp() {
     issueIndexer = new IssueIndexer(null, tester.client());
-    issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
+    issueAuthorizationIndexer = new AuthorizationIndexer(null, tester.client());
     viewIndexer = new ViewIndexer(null, tester.client());
     System2 system = mock(System2.class);
     when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("GMT-1:00"));
@@ -1288,7 +1290,7 @@ public class IssueIndexTest {
   }
 
   private void addIssueAuthorization(String projectUuid, @Nullable String group, @Nullable String user) {
-    issueAuthorizationIndexer.index(newArrayList(new IssueAuthorizationDao.Dto(projectUuid, 1).addGroup(group).addUser(user)));
+    issueAuthorizationIndexer.index(newArrayList(new AuthorizationDao.Dto(projectUuid, 1).addGroup(group).addUser(user)));
   }
 
   private void indexView(String viewUuid, List<String> projects) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationDaoTest.java
new file mode 100644 (file)
index 0000000..a6c594f
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.index;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import java.util.Collection;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AuthorizationDaoTest {
+
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+  private AuthorizationDao dao = new AuthorizationDao();
+
+  @Test
+  public void select_all() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    Collection<AuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
+    assertThat(dtos).hasSize(2);
+
+    AuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
+    assertThat(abc.getGroups()).containsOnly("Anyone", "devs");
+    assertThat(abc.getUsers()).containsOnly("user1");
+    assertThat(abc.getUpdatedAt()).isNotNull();
+
+    AuthorizationDao.Dto def = Iterables.find(dtos, new ProjectPredicate("DEF"));
+    assertThat(def.getGroups()).containsOnly("Anyone");
+    assertThat(def.getUsers()).containsOnly("user1", "user2");
+    assertThat(def.getUpdatedAt()).isNotNull();
+  }
+
+  @Test
+  public void select_after_date() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    Collection<AuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 1500000000L);
+
+    // only project DEF was updated in this period
+    assertThat(dtos).hasSize(1);
+    AuthorizationDao.Dto def = Iterables.find(dtos, new ProjectPredicate("DEF"));
+    assertThat(def).isNotNull();
+    assertThat(def.getGroups()).containsOnly("Anyone");
+    assertThat(def.getUsers()).containsOnly("user1", "user2");
+  }
+
+  @Test
+  public void no_authorization() {
+    dbTester.prepareDbUnit(getClass(), "no_authorization.xml");
+
+    Collection<AuthorizationDao.Dto> dtos = dao.selectAfterDate(dbTester.getDbClient(), dbTester.getSession(), 0L);
+
+    assertThat(dtos).hasSize(1);
+    AuthorizationDao.Dto abc = Iterables.find(dtos, new ProjectPredicate("ABC"));
+    assertThat(abc.getGroups()).isEmpty();
+    assertThat(abc.getUsers()).isEmpty();
+    assertThat(abc.getUpdatedAt()).isNotNull();
+  }
+
+  private static class ProjectPredicate implements Predicate<AuthorizationDao.Dto> {
+
+    private final String projectUuid;
+
+    ProjectPredicate(String projectUuid) {
+      this.projectUuid = projectUuid;
+    }
+
+    @Override
+    public boolean apply(AuthorizationDao.Dto input) {
+      return input.getProjectUuid().equals(projectUuid);
+    }
+
+    @Override
+    public boolean equals(Object object) {
+      return true;
+    }
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java
new file mode 100644 (file)
index 0000000..bf25f0f
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.index;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import org.elasticsearch.search.SearchHit;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.config.MapSettings;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.issue.index.IssueIndexDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class AuthorizationIndexerTest {
+
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+  @Rule
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
+
+  @Test
+  public void index_nothing() {
+    AuthorizationIndexer indexer = createIndexer();
+    indexer.index();
+
+    assertThat(esTester.countDocuments("issues", "authorization")).isZero();
+  }
+
+  @Test
+  public void index() {
+    dbTester.prepareDbUnit(getClass(), "index.xml");
+
+    AuthorizationIndexer indexer = createIndexer();
+    indexer.doIndex(0L);
+
+    List<SearchHit> docs = esTester.getDocuments("issues", "authorization");
+    assertThat(docs).hasSize(1);
+    SearchHit doc = docs.get(0);
+    assertThat(doc.getSource().get("project")).isEqualTo("ABC");
+    assertThat((Collection) doc.getSource().get("groups")).containsOnly("devs", "Anyone");
+    assertThat((Collection) doc.getSource().get("users")).containsOnly("user1");
+
+    // delete project
+    indexer.deleteProject("ABC", true);
+
+    assertThat(esTester.countDocuments("issues", "issueAuthorization")).isZero();
+  }
+
+  @Test
+  public void do_not_fail_when_deleting_unindexed_project() {
+    AuthorizationIndexer indexer = createIndexer();
+    indexer.deleteProject("UNKNOWN", true);
+    assertThat(esTester.countDocuments("issues", "authorization")).isZero();
+  }
+
+  @Test
+  public void delete_permissions() {
+    AuthorizationIndexer indexer = createIndexer();
+    AuthorizationDao.Dto authorization = new AuthorizationDao.Dto("ABC", System.currentTimeMillis());
+    authorization.addUser("guy");
+    authorization.addGroup("dev");
+    indexer.index(Arrays.asList(authorization));
+
+    // has permissions
+    assertThat(esTester.countDocuments("issues", "authorization")).isEqualTo(1);
+
+    // remove permissions -> dto has no users nor groups
+    authorization = new AuthorizationDao.Dto("ABC", System.currentTimeMillis());
+    indexer.index(Arrays.asList(authorization));
+
+    List<SearchHit> docs = esTester.getDocuments("issues", "authorization");
+    assertThat(docs).hasSize(1);
+    assertThat((Collection)docs.get(0).sourceAsMap().get(IssueIndexDefinition.FIELD_AUTHORIZATION_USERS)).hasSize(0);
+    assertThat((Collection)docs.get(0).sourceAsMap().get(IssueIndexDefinition.FIELD_AUTHORIZATION_GROUPS)).hasSize(0);
+  }
+
+  private AuthorizationIndexer createIndexer() {
+    return new AuthorizationIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
+  }
+}
index 9e66249f11fad22b5bbeb2e9b7a54907e92c0214..2a95ad0a6e82e02301d47ec412a86738905aeded 100644 (file)
@@ -31,11 +31,11 @@ import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateTesting;
 import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.permission.GroupPermissionChanger;
 import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.UserPermissionChanger;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.usergroups.ws.GroupWsSupport;
 import org.sonar.server.ws.WsTester;
@@ -77,7 +77,7 @@ public abstract class BasePermissionWsTest<A extends PermissionsWsAction> {
 
   protected PermissionUpdater newPermissionUpdater() {
     return new PermissionUpdater(db.getDbClient(),
-      mock(IssueAuthorizationIndexer.class),
+      mock(AuthorizationIndexer.class),
       new UserPermissionChanger(db.getDbClient(), defaultOrganizationProvider),
       new GroupPermissionChanger(db.getDbClient(), defaultOrganizationProvider));
   }
index b202ab3354c5a9777065f54694cf6dcd199b6631..d9beaf0654d5c8ab95536c4a1b4855a663ea59ae 100644 (file)
@@ -37,8 +37,8 @@ import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.permission.ws.BasePermissionWsTest;
 import org.sonar.server.ws.WsTester;
 
@@ -64,7 +64,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
   private ComponentDto project;
   private PermissionTemplateDto template1;
   private PermissionTemplateDto template2;
-  private IssueAuthorizationIndexer issueAuthorizationIndexer = mock(IssueAuthorizationIndexer.class);
+  private AuthorizationIndexer issueAuthorizationIndexer = mock(AuthorizationIndexer.class);
 
   @Override
   protected ApplyTemplateAction buildWsAction() {
index d7a5fd585bcc3c7915cef37c12418b43fe9dfdec..1a459c0825d96a96a4e90b50481e77b36c664a8f 100644 (file)
@@ -36,8 +36,8 @@ import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.i18n.I18nRule;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.permission.ws.BasePermissionWsTest;
 import org.sonar.server.ws.WsTester;
 
@@ -61,7 +61,7 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   private GroupDto group2;
   private PermissionTemplateDto template1;
   private PermissionTemplateDto template2;
-  private IssueAuthorizationIndexer issueAuthorizationIndexer = mock(IssueAuthorizationIndexer.class);
+  private AuthorizationIndexer issueAuthorizationIndexer = mock(AuthorizationIndexer.class);
 
   @Override
   protected BulkApplyTemplateAction buildWsAction() {
index cee5160cc17b4fe4c42447538ec269b30856936a..9439a58a2add889e17d84fac3ae74a93fa13afe0 100644 (file)
@@ -48,9 +48,9 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
 import org.sonar.server.issue.index.IssueAuthorizationDoc;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.component.es.ProjectMeasuresIndexer;
 import org.sonar.server.test.index.TestDoc;
 import org.sonar.server.test.index.TestIndexDefinition;
@@ -99,7 +99,7 @@ public class BulkDeleteActionTest {
     ws = new WsTester(new ProjectsWs(
       new BulkDeleteAction(
         new ComponentCleanerService(dbClient,
-          new IssueAuthorizationIndexer(dbClient, es.client()),
+          new AuthorizationIndexer(dbClient, es.client()),
           new IssueIndexer(dbClient, es.client()),
           new TestIndexer(dbClient, es.client()),
           new ProjectMeasuresIndexer(dbClient, es.client()),
index eb8968c627727e0d092b8faefeab61c8691f711f..8ba806700ddf8c2a3004a317953d22da8aac9ef1 100644 (file)
@@ -46,9 +46,9 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.IssueTesting;
 import org.sonar.server.issue.index.IssueAuthorizationDoc;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.component.es.ProjectMeasuresIndexer;
 import org.sonar.server.test.index.TestDoc;
 import org.sonar.server.test.index.TestIndexDefinition;
@@ -100,7 +100,7 @@ public class DeleteActionTest {
       new DeleteAction(
         new ComponentCleanerService(
           dbClient,
-          new IssueAuthorizationIndexer(dbClient, es.client()),
+          new AuthorizationIndexer(dbClient, es.client()),
           new IssueIndexer(dbClient, es.client()),
           new TestIndexer(dbClient, es.client()),
           new ProjectMeasuresIndexer(dbClient, es.client()),
index af049ee634305fe3b8c9c88ba2879ed811b93cc5..267af21dec1ee1165dc2aa1a989326869ed0b5fc 100644 (file)
@@ -41,11 +41,11 @@ import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 import org.sonar.server.issue.IssueQuery;
 import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
+import org.sonar.server.permission.index.AuthorizationIndexer;
 import org.sonar.server.tester.UserSessionRule;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -144,7 +144,7 @@ public class ViewIndexerTest {
   public void clear_views_lookup_cache_on_index_view_uuid() {
     IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule);
     IssueIndexer issueIndexer = new IssueIndexer(dbClient, esTester.client());
-    IssueAuthorizationIndexer issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, esTester.client());
+    AuthorizationIndexer issueAuthorizationIndexer = new AuthorizationIndexer(dbClient, esTester.client());
 
     String viewUuid = "ABCD";
 
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationDaoTest/no_authorization.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationDaoTest/no_authorization.xml
deleted file mode 100644 (file)
index 39ae987..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<dataset>
-
-  <projects uuid="ABC"
-            uuid_path="NOT_USED"
-            project_uuid="ABC"
-            module_uuid="[null]"
-            module_uuid_path="."
-            root_uuid="ABC"
-            scope="PRJ"
-            qualifier="TRK"
-            kee="org.struts:struts"
-            name="Struts"
-            description="the description"
-            long_name="Apache Struts"
-            enabled="[true]"
-            language="java"
-            path="[null]"
-            authorization_updated_at="123456789"
-            id="1"/>
-
-  <!-- no authorizations project ABC. -->
-
-  <users id="10"
-         login="user1"
-         name="User 1"
-         email="user1@company.net"
-         active="[true]"
-         is_root="[false]"/>
-  <groups id="100"
-          name="devs"
-          organization_uuid="org1"/>
-
-  <user_roles id="1"
-              user_id="10"
-              resource_id="2"
-              role="user"
-              organization_uuid="org1"/>
-  <group_roles id="1"
-               group_id="100"
-               resource_id="2"
-               role="admin"
-               organization_uuid="org1"/>
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationDaoTest/shared.xml
deleted file mode 100644 (file)
index 955402a..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<dataset>
-
-  <projects uuid="ABC"
-            uuid_path="NOT_USED"
-            project_uuid="ABC"
-            module_uuid="[null]"
-            module_uuid_path="."
-            root_uuid="ABC"
-            scope="PRJ"
-            qualifier="TRK"
-            kee="org.struts:struts"
-            name="Struts"
-            description="the description"
-            long_name="Apache Struts"
-            enabled="[true]"
-            language="java"
-            path="[null]"
-            authorization_updated_at="1000000000"
-            id="1"/>
-
-  <projects uuid="DEF"
-            uuid_path="NOT_USED"
-            project_uuid="DEF"
-            module_uuid="[null]"
-            module_uuid_path="."
-            root_uuid="ABC"
-            scope="PRJ"
-            qualifier="TRK"
-            kee="org.sonar.sample"
-            name="Sample"
-            description="the description"
-            long_name="Sample"
-            enabled="[true]"
-            language="java"
-            path="[null]"
-            authorization_updated_at="2000000000"
-            id="2"/>
-
-  <!-- user1 can access both projects -->
-  <users id="10"
-         login="user1"
-         name="User 1"
-         email="user1@company.net"
-         active="[true]"
-         is_root="[false]"/>
-  <user_roles id="1"
-              user_id="10"
-              resource_id="1"
-              role="user"
-              organization_uuid="org1"/>
-  <user_roles id="2"
-              user_id="10"
-              resource_id="1"
-              role="admin"
-              organization_uuid="org1"/>
-  <user_roles id="3"
-              user_id="10"
-              resource_id="2"
-              role="user"
-              organization_uuid="org1"/>
-
-  <!-- group devs has user access on ABC only -->
-  <groups id="100"
-          name="devs"
-          organization_uuid="org1"/>
-  <group_roles id="1"
-               group_id="100"
-               resource_id="1"
-               role="user"
-               organization_uuid="org1"/>
-  <group_roles id="2"
-               group_id="100"
-               resource_id="1"
-               role="admin"
-               organization_uuid="org1"/>
-
-  <!-- Anyone group has user access on both projects -->
-  <group_roles id="4"
-               group_id="[null]"
-               resource_id="1"
-               role="user"
-               organization_uuid="org1"/>
-  <group_roles id="5"
-               group_id="[null]"
-               resource_id="1"
-               role="admin"
-               organization_uuid="org1"/>
-  <group_roles id="6"
-               group_id="[null]"
-               resource_id="2"
-               role="user"
-               organization_uuid="org1"/>
-
-  <!-- user2 has user access on DEF only -->
-  <users id="11"
-         login="user2"
-         name="User 2"
-         email="user2@company.net"
-         active="[true]"
-         is_root="[false]"/>
-  <user_roles id="4"
-              user_id="11"
-              resource_id="1"
-              role="admin"
-              organization_uuid="org1"/>
-  <user_roles id="5"
-              user_id="11"
-              resource_id="2"
-              role="user"
-              organization_uuid="org1"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationIndexerTest/index.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueAuthorizationIndexerTest/index.xml
deleted file mode 100644 (file)
index 7a5529f..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<dataset>
-
-  <projects uuid="ABC"
-            uuid_path="NOT_USED"
-            project_uuid="ABC"
-            module_uuid="[null]"
-            module_uuid_path="."
-            root_uuid="ABC"
-            scope="PRJ"
-            qualifier="TRK"
-            kee="org.struts:struts"
-            name="Struts"
-            description="the description"
-            long_name="Apache Struts"
-            enabled="[true]"
-            language="java"
-            path="[null]"
-            authorization_updated_at="123456789"
-            id="1"/>
-
-  <users id="10"
-         login="user1"
-         name="User 1"
-         email="user1@company.net"
-         active="[true]"
-         is_root="[false]"/>
-  <user_roles id="1"
-              user_id="10"
-              resource_id="1"
-              role="user"
-              organization_uuid="org1"/>
-  <user_roles id="2"
-              user_id="10"
-              resource_id="1"
-              role="admin"
-              organization_uuid="org1"/>
-  <user_roles id="3"
-              user_id="10"
-              resource_id="2"
-              role="admin"
-              organization_uuid="org1"/>
-
-  <groups id="100"
-          name="devs"
-          organization_uuid="org1"/>
-  <group_roles id="1"
-               group_id="100"
-               resource_id="1"
-               role="user"
-               organization_uuid="org1"/>
-  <group_roles id="2"
-               group_id="100"
-               resource_id="2"
-               role="admin"
-               organization_uuid="org1"/>
-
-  <!-- Anyone group  -->
-  <group_roles id="3"
-               group_id="[null]"
-               resource_id="1"
-               role="user"
-               organization_uuid="org1"/>
-  <group_roles id="4"
-               group_id="[null]"
-               resource_id="2"
-               role="admin"
-               organization_uuid="org1"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationDaoTest/no_authorization.xml b/server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationDaoTest/no_authorization.xml
new file mode 100644 (file)
index 0000000..39ae987
--- /dev/null
@@ -0,0 +1,43 @@
+<dataset>
+
+  <projects uuid="ABC"
+            uuid_path="NOT_USED"
+            project_uuid="ABC"
+            module_uuid="[null]"
+            module_uuid_path="."
+            root_uuid="ABC"
+            scope="PRJ"
+            qualifier="TRK"
+            kee="org.struts:struts"
+            name="Struts"
+            description="the description"
+            long_name="Apache Struts"
+            enabled="[true]"
+            language="java"
+            path="[null]"
+            authorization_updated_at="123456789"
+            id="1"/>
+
+  <!-- no authorizations project ABC. -->
+
+  <users id="10"
+         login="user1"
+         name="User 1"
+         email="user1@company.net"
+         active="[true]"
+         is_root="[false]"/>
+  <groups id="100"
+          name="devs"
+          organization_uuid="org1"/>
+
+  <user_roles id="1"
+              user_id="10"
+              resource_id="2"
+              role="user"
+              organization_uuid="org1"/>
+  <group_roles id="1"
+               group_id="100"
+               resource_id="2"
+               role="admin"
+               organization_uuid="org1"/>
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..955402a
--- /dev/null
@@ -0,0 +1,112 @@
+<dataset>
+
+  <projects uuid="ABC"
+            uuid_path="NOT_USED"
+            project_uuid="ABC"
+            module_uuid="[null]"
+            module_uuid_path="."
+            root_uuid="ABC"
+            scope="PRJ"
+            qualifier="TRK"
+            kee="org.struts:struts"
+            name="Struts"
+            description="the description"
+            long_name="Apache Struts"
+            enabled="[true]"
+            language="java"
+            path="[null]"
+            authorization_updated_at="1000000000"
+            id="1"/>
+
+  <projects uuid="DEF"
+            uuid_path="NOT_USED"
+            project_uuid="DEF"
+            module_uuid="[null]"
+            module_uuid_path="."
+            root_uuid="ABC"
+            scope="PRJ"
+            qualifier="TRK"
+            kee="org.sonar.sample"
+            name="Sample"
+            description="the description"
+            long_name="Sample"
+            enabled="[true]"
+            language="java"
+            path="[null]"
+            authorization_updated_at="2000000000"
+            id="2"/>
+
+  <!-- user1 can access both projects -->
+  <users id="10"
+         login="user1"
+         name="User 1"
+         email="user1@company.net"
+         active="[true]"
+         is_root="[false]"/>
+  <user_roles id="1"
+              user_id="10"
+              resource_id="1"
+              role="user"
+              organization_uuid="org1"/>
+  <user_roles id="2"
+              user_id="10"
+              resource_id="1"
+              role="admin"
+              organization_uuid="org1"/>
+  <user_roles id="3"
+              user_id="10"
+              resource_id="2"
+              role="user"
+              organization_uuid="org1"/>
+
+  <!-- group devs has user access on ABC only -->
+  <groups id="100"
+          name="devs"
+          organization_uuid="org1"/>
+  <group_roles id="1"
+               group_id="100"
+               resource_id="1"
+               role="user"
+               organization_uuid="org1"/>
+  <group_roles id="2"
+               group_id="100"
+               resource_id="1"
+               role="admin"
+               organization_uuid="org1"/>
+
+  <!-- Anyone group has user access on both projects -->
+  <group_roles id="4"
+               group_id="[null]"
+               resource_id="1"
+               role="user"
+               organization_uuid="org1"/>
+  <group_roles id="5"
+               group_id="[null]"
+               resource_id="1"
+               role="admin"
+               organization_uuid="org1"/>
+  <group_roles id="6"
+               group_id="[null]"
+               resource_id="2"
+               role="user"
+               organization_uuid="org1"/>
+
+  <!-- user2 has user access on DEF only -->
+  <users id="11"
+         login="user2"
+         name="User 2"
+         email="user2@company.net"
+         active="[true]"
+         is_root="[false]"/>
+  <user_roles id="4"
+              user_id="11"
+              resource_id="1"
+              role="admin"
+              organization_uuid="org1"/>
+  <user_roles id="5"
+              user_id="11"
+              resource_id="2"
+              role="user"
+              organization_uuid="org1"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationIndexerTest/index.xml b/server/sonar-server/src/test/resources/org/sonar/server/permission/index/AuthorizationIndexerTest/index.xml
new file mode 100644 (file)
index 0000000..7a5529f
--- /dev/null
@@ -0,0 +1,69 @@
+<dataset>
+
+  <projects uuid="ABC"
+            uuid_path="NOT_USED"
+            project_uuid="ABC"
+            module_uuid="[null]"
+            module_uuid_path="."
+            root_uuid="ABC"
+            scope="PRJ"
+            qualifier="TRK"
+            kee="org.struts:struts"
+            name="Struts"
+            description="the description"
+            long_name="Apache Struts"
+            enabled="[true]"
+            language="java"
+            path="[null]"
+            authorization_updated_at="123456789"
+            id="1"/>
+
+  <users id="10"
+         login="user1"
+         name="User 1"
+         email="user1@company.net"
+         active="[true]"
+         is_root="[false]"/>
+  <user_roles id="1"
+              user_id="10"
+              resource_id="1"
+              role="user"
+              organization_uuid="org1"/>
+  <user_roles id="2"
+              user_id="10"
+              resource_id="1"
+              role="admin"
+              organization_uuid="org1"/>
+  <user_roles id="3"
+              user_id="10"
+              resource_id="2"
+              role="admin"
+              organization_uuid="org1"/>
+
+  <groups id="100"
+          name="devs"
+          organization_uuid="org1"/>
+  <group_roles id="1"
+               group_id="100"
+               resource_id="1"
+               role="user"
+               organization_uuid="org1"/>
+  <group_roles id="2"
+               group_id="100"
+               resource_id="2"
+               role="admin"
+               organization_uuid="org1"/>
+
+  <!-- Anyone group  -->
+  <group_roles id="3"
+               group_id="[null]"
+               resource_id="1"
+               role="user"
+               organization_uuid="org1"/>
+  <group_roles id="4"
+               group_id="[null]"
+               resource_id="2"
+               role="admin"
+               organization_uuid="org1"/>
+
+</dataset>