import org.sonar.server.setting.DatabaseSettingLoader;
import org.sonar.server.setting.DatabaseSettingsEnabler;
import org.sonar.server.setting.ThreadLocalSettings;
-import org.sonar.server.user.index.UserIndex;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.util.OkHttpClientProvider;
import org.sonar.server.util.Paths2Impl;
import org.sonar.server.view.index.ViewIndex;
MetricFinder.class,
UnanalyzedLanguageMetrics.class,
- UserIndexer.class,
- UserIndex.class,
-
// components,
FavoriteUpdater.class,
ProjectIndexersImpl.class,
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.Uuids;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.SearchOptions;
-
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserIndexIT {
-
- private static final String USER1_LOGIN = "user1";
- private static final String USER2_LOGIN = "user2";
- private static final String USER3_LOGIN = "user3";
-
- @Rule
- public EsTester es = EsTester.create();
-
- private UserIndex underTest = new UserIndex(es.client(), System2.INSTANCE);
- private UserQuery.Builder userQuery = UserQuery.builder();
-
- @Test
- public void getAtMostThreeActiveUsersForScmAccount_returns_the_users_with_specified_scm_account() {
- UserDoc user1 = newUser("user1", asList("user_1", "u1"));
- UserDoc user2 = newUser("user_with_same_email_as_user1", asList("user_2")).setEmail(user1.email());
- UserDoc user3 = newUser("inactive_user_with_same_scm_as_user1", user1.scmAccounts()).setActive(false);
- es.putDocuments(TYPE_USER, user1);
- es.putDocuments(TYPE_USER, user2);
- es.putDocuments(TYPE_USER, user3);
-
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user1.scmAccounts().get(0))).extractingResultOf("login").containsOnly(user1.login());
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user1.login())).extractingResultOf("login").containsOnly(user1.login());
-
- // both users share the same email
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user1.email())).extracting(UserDoc::login).containsOnly(user1.login(), user2.login());
-
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("")).isEmpty();
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("unknown")).isEmpty();
- }
-
- @Test
- public void getAtMostThreeActiveUsersForScmAccount_ignores_inactive_user() {
- String scmAccount = "scmA";
- UserDoc user = newUser(USER1_LOGIN, singletonList(scmAccount)).setActive(false);
- es.putDocuments(TYPE_USER, user);
-
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(user.login())).isEmpty();
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(scmAccount)).isEmpty();
- }
-
- @Test
- public void getAtMostThreeActiveUsersForScmAccount_returns_maximum_three_users() {
- String email = "user@mail.com";
- UserDoc user1 = newUser("user1", Collections.emptyList()).setEmail(email);
- UserDoc user2 = newUser("user2", Collections.emptyList()).setEmail(email);
- UserDoc user3 = newUser("user3", Collections.emptyList()).setEmail(email);
- UserDoc user4 = newUser("user4", Collections.emptyList()).setEmail(email);
- es.putDocuments(TYPE_USER, user1);
- es.putDocuments(TYPE_USER, user2);
- es.putDocuments(TYPE_USER, user3);
- es.putDocuments(TYPE_USER, user4);
-
- // restrict results to 3 users
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount(email)).hasSize(3);
- }
-
- @Test
- public void getAtMostThreeActiveUsersForScmAccount_is_case_sensitive_for_login() {
- UserDoc user = newUser("the_login", singletonList("John.Smith"));
- es.putDocuments(TYPE_USER, user);
-
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_login")).hasSize(1);
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_Login")).isEmpty();
- }
-
- @Test
- public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_email() {
- UserDoc user = newUser("the_login", "the_EMAIL@corp.com", singletonList("John.Smith"));
- es.putDocuments(TYPE_USER, user);
-
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_EMAIL@corp.com")).hasSize(1);
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_email@corp.com")).hasSize(1);
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("email")).isEmpty();
- }
-
- @Test
- public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_scm_account() {
- UserDoc user = newUser("the_login", singletonList("John.Smith"));
- es.putDocuments(TYPE_USER, user);
-
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("John.Smith")).hasSize(1);
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMIth")).hasSize(1);
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMITH")).hasSize(1);
- assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN")).isEmpty();
- }
-
- @Test
- public void searchUsers() {
- es.putDocuments(TYPE_USER, newUser(USER1_LOGIN, asList("user_1", "u1")).setEmail("email1"));
- es.putDocuments(TYPE_USER, newUser(USER2_LOGIN, Collections.emptyList()).setEmail("email2"));
- es.putDocuments(TYPE_USER, newUser(USER3_LOGIN, Collections.emptyList()).setEmail("email3").setActive(false));
-
- assertThat(underTest.search(userQuery.build(), new SearchOptions()).getDocs()).hasSize(2);
- assertThat(underTest.search(userQuery.setTextQuery("user").build(), new SearchOptions()).getDocs()).hasSize(2);
- assertThat(underTest.search(userQuery.setTextQuery("ser").build(), new SearchOptions()).getDocs()).hasSize(2);
- assertThat(underTest.search(userQuery.setTextQuery(USER1_LOGIN).build(), new SearchOptions()).getDocs()).hasSize(1);
- assertThat(underTest.search(userQuery.setTextQuery(USER2_LOGIN).build(), new SearchOptions()).getDocs()).hasSize(1);
- assertThat(underTest.search(userQuery.setTextQuery("mail").build(), new SearchOptions()).getDocs()).hasSize(2);
- assertThat(underTest.search(userQuery.setTextQuery("EMAIL1").build(), new SearchOptions()).getDocs()).hasSize(1);
-
- // deactivated users
- assertThat(underTest.search(userQuery.setActive(false).setTextQuery(null).build(), new SearchOptions()).getDocs()).hasSize(1);
- assertThat(underTest.search(userQuery.setActive(false).setTextQuery("email3").build(), new SearchOptions()).getDocs()).hasSize(1);
- }
-
- private static UserDoc newUser(String login, List<String> scmAccounts) {
- return new UserDoc()
- .setUuid(Uuids.createFast())
- .setLogin(login)
- .setName(login.toUpperCase(Locale.ENGLISH))
- .setEmail(login + "@mail.com")
- .setActive(true)
- .setScmAccounts(scmAccounts);
- }
-
- private static UserDoc newUser(String login, String email, List<String> scmAccounts) {
- return new UserDoc()
- .setUuid(Uuids.createFast())
- .setLogin(login)
- .setName(login.toUpperCase(Locale.ENGLISH))
- .setEmail(email)
- .setActive(true)
- .setScmAccounts(scmAccounts);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import java.util.HashSet;
-import java.util.List;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.es.EsTester;
-
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserIndexerIT {
-
- private final System2 system2 = System2.INSTANCE;
-
- @Rule
- public DbTester db = DbTester.create(system2);
-
- @Rule
- public EsTester es = EsTester.create();
-
- private final UserIndexer underTest = new UserIndexer(db.getDbClient(), es.client());
-
- @Test
- public void index_nothing_on_startup() {
- underTest.indexOnStartup(new HashSet<>());
-
- assertThat(es.countDocuments(TYPE_USER)).isZero();
- }
-
- @Test
- public void indexOnStartup_adds_all_users_to_index() {
- UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("user_1", "u1")));
-
- underTest.indexOnStartup(new HashSet<>());
-
- List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
- assertThat(docs).hasSize(1);
- UserDoc doc = docs.get(0);
- assertThat(doc.uuid()).isEqualTo(user.getUuid());
- assertThat(doc.login()).isEqualTo(user.getLogin());
- assertThat(doc.name()).isEqualTo(user.getName());
- assertThat(doc.email()).isEqualTo(user.getEmail());
- assertThat(doc.active()).isEqualTo(user.isActive());
- assertThat(doc.scmAccounts()).isEqualTo(user.getSortedScmAccounts());
- }
-
- @Test
- public void indexAll_adds_all_users_to_index() {
- UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("user_1", "u1")));
-
- underTest.indexAll();
-
- List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
- assertThat(docs).hasSize(1);
- UserDoc doc = docs.get(0);
- assertThat(doc.uuid()).isEqualTo(user.getUuid());
- assertThat(doc.login()).isEqualTo(user.getLogin());
- assertThat(doc.name()).isEqualTo(user.getName());
- assertThat(doc.email()).isEqualTo(user.getEmail());
- assertThat(doc.active()).isEqualTo(user.isActive());
- assertThat(doc.scmAccounts()).isEqualTo(user.getSortedScmAccounts());
- }
-
- @Test
- public void indexOnStartup_adds_all_users() {
- UserDto user = db.users().insertUser();
-
- underTest.indexOnStartup(new HashSet<>());
-
- List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
- assertThat(docs).hasSize(1);
- UserDoc doc = docs.get(0);
- assertThat(doc.uuid()).isEqualTo(user.getUuid());
- assertThat(doc.login()).isEqualTo(user.getLogin());
- }
-
- @Test
- public void commitAndIndex_single_user() {
- UserDto user = db.users().insertUser();
- UserDto anotherUser = db.users().insertUser();
-
- underTest.commitAndIndex(db.getSession(), user);
-
- List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
- assertThat(docs)
- .extracting(UserDoc::uuid)
- .containsExactlyInAnyOrder(user.getUuid())
- .doesNotContain(anotherUser.getUuid());
- }
-
- @Test
- public void commitAndIndex_multiple_users() {
- UserDto user1 = db.users().insertUser();
- UserDto user2 = db.users().insertUser();
-
- underTest.commitAndIndex(db.getSession(), asList(user1, user2));
-
- List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
- assertThat(docs)
- .extracting(UserDoc::login)
- .containsExactlyInAnyOrder(
- user1.getLogin(),
- user2.getLogin());
- assertThat(db.countRowsOfTable(db.getSession(), "users")).isEqualTo(2);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.server.es.BaseDoc;
-
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserDoc extends BaseDoc {
-
- public UserDoc(Map<String, Object> fields) {
- super(TYPE_USER, fields);
- }
-
- public UserDoc() {
- this(new HashMap<>());
- }
-
- @Override
- public String getId() {
- return uuid();
- }
-
- public String uuid() {
- return getField(UserIndexDefinition.FIELD_UUID);
- }
-
- public String login() {
- return getField(UserIndexDefinition.FIELD_LOGIN);
- }
-
- public String name() {
- return getField(UserIndexDefinition.FIELD_NAME);
- }
-
- @Nullable
- public String email() {
- return getNullableField(UserIndexDefinition.FIELD_EMAIL);
- }
-
- public boolean active() {
- return getField(UserIndexDefinition.FIELD_ACTIVE);
- }
-
- public List<String> scmAccounts() {
- return getField(UserIndexDefinition.FIELD_SCM_ACCOUNTS);
- }
-
- public UserDoc setUuid(@Nullable String s) {
- setField(UserIndexDefinition.FIELD_UUID, s);
- return this;
- }
-
- public UserDoc setLogin(@Nullable String s) {
- setField(UserIndexDefinition.FIELD_LOGIN, s);
- return this;
- }
-
- public UserDoc setName(@Nullable String s) {
- setField(UserIndexDefinition.FIELD_NAME, s);
- return this;
- }
-
- public UserDoc setEmail(@Nullable String s) {
- setField(UserIndexDefinition.FIELD_EMAIL, s);
- return this;
- }
-
- public UserDoc setActive(boolean b) {
- setField(UserIndexDefinition.FIELD_ACTIVE, b);
- return this;
- }
-
- public UserDoc setScmAccounts(@Nullable List<String> s) {
- setField(UserIndexDefinition.FIELD_SCM_ACCOUNTS, s);
- return this;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.search.SearchRequest;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.Operator;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.SearchHit;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.elasticsearch.search.sort.SortOrder;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.System2;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.SearchOptions;
-import org.sonar.server.es.SearchResult;
-
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
-import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.USER_SEARCH_GRAMS_ANALYZER;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_EMAIL;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_LOGIN;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_NAME;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_SCM_ACCOUNTS;
-
-@ServerSide
-@ComputeEngineSide
-public class UserIndex {
-
- private final EsClient esClient;
- private final System2 system2;
-
- public UserIndex(EsClient esClient, System2 system2) {
- this.esClient = esClient;
- this.system2 = system2;
- }
-
- /**
- * Returns the active users (at most 3) who are associated to the given SCM account. This method can be used
- * to detect user conflicts.
- */
- public List<UserDoc> getAtMostThreeActiveUsersForScmAccount(String scmAccount) {
- List<UserDoc> result = new ArrayList<>();
- if (!StringUtils.isEmpty(scmAccount)) {
- SearchResponse response = esClient.search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
- .source(new SearchSourceBuilder()
- .query(boolQuery().must(matchAllQuery()).filter(
- boolQuery()
- .must(termQuery(FIELD_ACTIVE, true))
- .should(termQuery(FIELD_LOGIN, scmAccount))
- .should(matchQuery(SORTABLE_ANALYZER.subField(FIELD_EMAIL), scmAccount))
- .should(matchQuery(SORTABLE_ANALYZER.subField(FIELD_SCM_ACCOUNTS), scmAccount))
- .minimumShouldMatch(1)))
- .size(3)));
- for (SearchHit hit : response.getHits().getHits()) {
- result.add(new UserDoc(hit.getSourceAsMap()));
- }
- }
- return result;
- }
-
- public SearchResult<UserDoc> search(UserQuery userQuery, SearchOptions options) {
- SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
- .size(options.getLimit())
- .from(options.getOffset())
- .sort(FIELD_NAME, SortOrder.ASC);
-
- BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, userQuery.isActive()));
- QueryBuilder esQuery = matchAllQuery();
- Optional<String> textQuery = userQuery.getTextQuery();
- if (textQuery.isPresent()) {
- esQuery = QueryBuilders.multiMatchQuery(textQuery.get(),
- FIELD_LOGIN,
- USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_LOGIN),
- FIELD_NAME,
- USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME),
- FIELD_EMAIL,
- USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_EMAIL))
- .operator(Operator.AND);
- }
-
- SearchRequest request = EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
- .source(searchSourceBuilder.query(boolQuery().must(esQuery).filter(filter)));
- return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone().toZoneId());
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import org.sonar.api.config.Configuration;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.server.es.Index;
-import org.sonar.server.es.IndexDefinition;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.IndexType.IndexMainType;
-import org.sonar.server.es.newindex.NewRegularIndex;
-import org.sonar.server.es.newindex.TypeMapping;
-
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.USER_SEARCH_GRAMS_ANALYZER;
-import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder;
-
-/**
- * Definition of ES index "users", including settings and fields.
- */
-public class UserIndexDefinition implements IndexDefinition {
-
- public static final Index DESCRIPTOR = Index.simple("users");
- public static final IndexMainType TYPE_USER = IndexType.main(DESCRIPTOR, "user");
- public static final String FIELD_UUID = "uuid";
- public static final String FIELD_LOGIN = "login";
- public static final String FIELD_NAME = "name";
- public static final String FIELD_EMAIL = "email";
- public static final String FIELD_ACTIVE = "active";
- public static final String FIELD_SCM_ACCOUNTS = "scmAccounts";
-
- private final Configuration config;
-
- public UserIndexDefinition(Configuration config) {
- this.config = config;
- }
-
- public static UserIndexDefinition createForTest() {
- return new UserIndexDefinition(new MapSettings().asConfig());
- }
-
- @Override
- public void define(IndexDefinitionContext context) {
- NewRegularIndex index = context.create(
- DESCRIPTOR,
- newBuilder(config)
- .setDefaultNbOfShards(1)
- .build())
- // all information is retrieved from the index, not only IDs
- .setEnableSource(true);
-
- TypeMapping mapping = index.createTypeMapping(TYPE_USER);
- mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
- mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
- mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
- mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build();
- mapping.createBooleanField(FIELD_ACTIVE);
- mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import org.elasticsearch.action.index.IndexRequest;
-import org.sonar.core.util.stream.MoreCollectors;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.es.EsQueueDto;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.es.BulkIndexer;
-import org.sonar.server.es.BulkIndexer.Size;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.IndexingListener;
-import org.sonar.server.es.IndexingResult;
-import org.sonar.server.es.OneToOneResilientIndexingListener;
-import org.sonar.server.es.ResilientIndexer;
-
-import static java.util.Collections.singletonList;
-import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
-import static org.sonar.core.util.stream.MoreCollectors.toList;
-import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
-
-public class UserIndexer implements ResilientIndexer {
- private final DbClient dbClient;
- private final EsClient esClient;
-
- public UserIndexer(DbClient dbClient, EsClient esClient) {
- this.dbClient = dbClient;
- this.esClient = esClient;
- }
-
- @Override
- public Set<IndexType> getIndexTypes() {
- return ImmutableSet.of(TYPE_USER);
- }
-
- @Override
- public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
- indexAll(Size.LARGE);
- }
-
- public void indexAll() {
- indexAll(Size.REGULAR);
- }
-
- private void indexAll(Size bulkSize) {
- try (DbSession dbSession = dbClient.openSession(false)) {
- BulkIndexer bulkIndexer = newBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR);
- bulkIndexer.start();
-
- dbClient.userDao().scrollAll(dbSession,
- // only index requests, no deletion requests.
- // Deactivated users are not deleted but updated.
- u -> bulkIndexer.add(newIndexRequest(u)));
- bulkIndexer.stop();
- }
- }
-
- public void commitAndIndex(DbSession dbSession, UserDto user) {
- commitAndIndex(dbSession, singletonList(user));
- }
-
- public void commitAndIndex(DbSession dbSession, Collection<UserDto> users) {
- List<String> uuids = users.stream().map(UserDto::getUuid).collect(toList());
- List<EsQueueDto> items = uuids.stream()
- .map(uuid -> EsQueueDto.create(TYPE_USER.format(), uuid))
- .collect(MoreCollectors.toArrayList());
-
- dbClient.esQueueDao().insert(dbSession, items);
- dbSession.commit();
- postCommit(dbSession, users.stream().map(UserDto::getLogin).collect(toList()), items);
- }
-
- /**
- * Entry point for Byteman tests. See directory tests/resilience.
- * The parameter "logins" is used only by the Byteman script.
- */
- private void postCommit(DbSession dbSession, Collection<String> logins, Collection<EsQueueDto> items) {
- index(dbSession, items);
- }
-
- /**
- * @return the number of items that have been successfully indexed
- */
- @Override
- public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
- if (items.isEmpty()) {
- return new IndexingResult();
- }
- Set<String> uuids = items
- .stream()
- .map(EsQueueDto::getDocId)
- .collect(toHashSet(items.size()));
-
- BulkIndexer bulkIndexer = newBulkIndexer(Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items));
- bulkIndexer.start();
-
- dbClient.userDao().scrollByUuids(dbSession, uuids,
- // only index requests, no deletion requests.
- // Deactivated users are not deleted but updated.
- u -> {
- uuids.remove(u.getUuid());
- bulkIndexer.add(newIndexRequest(u));
- });
-
- // the remaining uuids reference rows that don't exist in db. They must
- // be deleted from index.
- uuids.forEach(uuid -> bulkIndexer.addDeletion(TYPE_USER, uuid));
- return bulkIndexer.stop();
- }
-
- private BulkIndexer newBulkIndexer(Size bulkSize, IndexingListener listener) {
- return new BulkIndexer(esClient, TYPE_USER, bulkSize, listener);
- }
-
- private static IndexRequest newIndexRequest(UserDto user) {
- UserDoc doc = new UserDoc(Maps.newHashMapWithExpectedSize(8));
- // all the keys must be present, even if value is null
- doc.setUuid(user.getUuid());
- doc.setLogin(user.getLogin());
- doc.setName(user.getName());
- doc.setEmail(user.getEmail());
- doc.setActive(user.isActive());
- doc.setScmAccounts(user.getSortedScmAccounts());
-
- return doc.toIndexRequest();
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import java.util.Optional;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-
-import static org.apache.commons.lang.StringUtils.isBlank;
-
-@Immutable
-public class UserQuery {
- private final String textQuery;
- private final boolean active;
-
- private UserQuery(Builder builder) {
- this.textQuery = builder.textQuery;
- this.active = builder.active;
- }
-
- public Optional<String> getTextQuery() {
- return Optional.ofNullable(textQuery);
- }
-
- public boolean isActive() {
- return active;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private String textQuery;
- private boolean active = true;
-
- private Builder() {
- // enforce factory method
- }
-
- public UserQuery build() {
- return new UserQuery(this);
- }
-
- public Builder setTextQuery(@Nullable String textQuery) {
- this.textQuery = isBlank(textQuery) ? null : textQuery;
- return this;
- }
-
- public Builder setActive(boolean active) {
- this.active = active;
- return this;
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.user.index;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info 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.user.index;
-
-import org.junit.Test;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.server.es.Index;
-import org.sonar.server.es.IndexDefinition;
-import org.sonar.server.es.IndexType;
-import org.sonar.server.es.newindex.NewIndex;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class UserIndexDefinitionTest {
-
- private IndexDefinition.IndexDefinitionContext underTest = new IndexDefinition.IndexDefinitionContext();
-
- @Test
- public void define() {
- UserIndexDefinition def = new UserIndexDefinition(new MapSettings().asConfig());
- def.define(underTest);
-
- assertThat(underTest.getIndices()).hasSize(1);
- NewIndex index = underTest.getIndices().get("users");
- assertThat(index.getMainType())
- .isEqualTo(IndexType.main(Index.simple("users"), "user"));
- assertThat(index.getRelationsStream()).isEmpty();
-
- // no cluster by default
- assertThat(index.getSetting("index.number_of_shards")).isEqualTo("1");
- assertThat(index.getSetting("index.number_of_replicas")).isEqualTo("0");
- }
-}
import org.sonar.server.issue.index.IssueIndexDefinition;
import org.sonar.server.measure.index.ProjectMeasuresIndexDefinition;
import org.sonar.server.rule.index.RuleIndexDefinition;
-import org.sonar.server.user.index.UserIndexDefinition;
import org.sonar.server.view.index.ViewIndexDefinition;
import static com.google.common.base.Preconditions.checkArgument;
IssueIndexDefinition.createForTest(),
ProjectMeasuresIndexDefinition.createForTest(),
RuleIndexDefinition.createForTest(),
- UserIndexDefinition.createForTest(),
ViewIndexDefinition.createForTest());
CORE_INDICES_CREATED.set(true);
import java.util.Objects;
import java.util.function.Consumer;
import java.util.regex.Pattern;
-import java.util.stream.Stream;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.apache.commons.lang.math.RandomUtils;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserGroupDto;
import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.util.Validation;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format;
-import static java.util.Arrays.stream;
import static java.util.Collections.emptyList;
-import static java.util.stream.Stream.concat;
import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
import static org.sonar.core.util.Slug.slugify;
import static org.sonar.core.util.stream.MoreCollectors.toList;
private final NewUserNotifier newUserNotifier;
private final DbClient dbClient;
- private final UserIndexer userIndexer;
private final DefaultGroupFinder defaultGroupFinder;
private final AuditPersister auditPersister;
private final CredentialsLocalAuthentication localAuthentication;
@Inject
- public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer, DefaultGroupFinder defaultGroupFinder, Configuration config,
+ public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, DefaultGroupFinder defaultGroupFinder, Configuration config,
AuditPersister auditPersister, CredentialsLocalAuthentication localAuthentication) {
this.newUserNotifier = newUserNotifier;
this.dbClient = dbClient;
- this.userIndexer = userIndexer;
this.defaultGroupFinder = defaultGroupFinder;
this.auditPersister = auditPersister;
this.localAuthentication = localAuthentication;
private UserDto commitUser(DbSession dbSession, UserDto userDto, Consumer<UserDto> beforeCommit, UserDto... otherUsersToIndex) {
beforeCommit.accept(userDto);
- userIndexer.commitAndIndex(dbSession, concat(Stream.of(userDto), stream(otherUsersToIndex)).collect(toList()));
+ dbSession.commit();
notifyNewUser(userDto.getLogin(), userDto.getName(), userDto.getEmail());
return userDto;
}
import org.sonar.server.management.ManagedInstanceService;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import static java.util.Arrays.stream;
private final System2 system2 = mock(System2.class);
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
- private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
-
private final DefaultGroupFinder defaultGroupFinder = new DefaultGroupFinder(db.getDbClient());
private final UserRegistrarImpl userIdentityAuthenticator = new UserRegistrarImpl(db.getDbClient(),
- new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, defaultGroupFinder, settings.asConfig(), mock(AuditPersister.class), localAuthentication),
+ new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), defaultGroupFinder, settings.asConfig(), mock(AuditPersister.class), localAuthentication),
defaultGroupFinder, mock(ManagedInstanceService.class));
private final HttpServletResponse response = mock(HttpServletResponse.class);
private final JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
import org.sonar.server.management.ManagedInstanceService;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import static java.util.Arrays.stream;
@Rule
public LogTester logTester = new LogTester();
- private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
private final DefaultGroupFinder groupFinder = new DefaultGroupFinder(db.getDbClient());
private final AuditPersister auditPersister = mock(AuditPersister.class);
private final ManagedInstanceService managedInstanceService = mock(ManagedInstanceService.class);
- private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, groupFinder, settings.asConfig(), auditPersister, localAuthentication);
+ private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), groupFinder, settings.asConfig(), auditPersister, localAuthentication);
private final UserRegistrarImpl underTest = new UserRegistrarImpl(db.getDbClient(), userUpdater, groupFinder, managedInstanceService);
private GroupDto defaultGroup;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.List;
-import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import static java.util.Arrays.asList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.data.MapEntry.entry;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
private final ArgumentCaptor<NewUserHandler.Context> newUserHandler = ArgumentCaptor.forClass(NewUserHandler.Context.class);
private final DbSession session = db.getSession();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
- private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
+ private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient,
new DefaultGroupFinder(dbClient), settings.asConfig(), null, localAuthentication);
@Test
.isEqualTo(dto.getUpdatedAt());
assertThat(dbClient.userDao().selectByLogin(session, "user").getUuid()).isEqualTo(dto.getUuid());
- List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
- assertThat(indexUsers).hasSize(1);
- assertThat(indexUsers.get(0).getSourceAsMap())
- .contains(
- entry("login", "user"),
- entry("name", "User"),
- entry("email", "user@mail.com"));
}
@Test
assertThat(dbClient.userDao().selectByLogin(session, "user").getSortedScmAccounts()).containsOnly("u1");
}
- @Test
- public void create_user_and_index_other_user() {
- createDefaultGroup();
- UserDto otherUser = db.users().insertUser();
-
- UserDto created = underTest.createAndCommit(session, NewUser.builder()
- .setLogin("user")
- .setName("User")
- .setEmail("user@mail.com")
- .setPassword("PASSWORD")
- .build(), u -> {
- }, otherUser);
-
- assertThat(es.getIds(UserIndexDefinition.TYPE_USER)).containsExactlyInAnyOrder(created.getUuid(), otherUser.getUuid());
- }
-
@Test
@UseDataProvider("loginWithAuthorizedSuffix")
public void createAndCommit_should_createUserWithoutException_when_loginHasAuthorizedSuffix(String login) {
@DataProvider
public static Object[][] loginWithAuthorizedSuffix() {
- return new Object[][]{
+ return new Object[][] {
{"1Login"},
{"AnotherLogin"},
{"alogin"},
@DataProvider
public static Object[][] loginWithUnauthorizedSuffix() {
- return new Object[][]{
+ return new Object[][] {
{".Toto"},
{"@Toto"},
{"-Tutu"},
import org.sonar.db.user.UserDto;
import org.sonar.server.authentication.CredentialsLocalAuthentication;
import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import static java.lang.String.format;
private final System2 system2 = new AlwaysIncreasingSystem2();
- @Rule
- public EsTester es = EsTester.create();
@Rule
public DbTester db = DbTester.create(system2);
private final DbClient dbClient = db.getDbClient();
private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
private final DbSession session = db.getSession();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
private final AuditPersister auditPersister = mock(AuditPersister.class);
- private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
+ private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient,
new DefaultGroupFinder(dbClient),
settings.asConfig(), auditPersister, localAuthentication);
package org.sonar.server.user;
import com.google.common.collect.Multimap;
-import java.util.List;
import java.util.function.Consumer;
-import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
-import static org.assertj.core.data.MapEntry.entry;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
private final System2 system2 = new AlwaysIncreasingSystem2();
- @Rule
- public EsTester es = EsTester.create();
@Rule
public DbTester db = DbTester.create(system2);
private final DbClient dbClient = db.getDbClient();
private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
private final DbSession session = db.getSession();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
private final AuditPersister auditPersister = mock(AuditPersister.class);
- private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
+ private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient,
new DefaultGroupFinder(dbClient), settings.asConfig(), auditPersister, localAuthentication);
@Test
UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com")
.setScmAccounts(asList("ma", "marius33")));
createDefaultGroup();
- userIndexer.indexAll();
underTest.updateAndCommit(session, user, new UpdateUser()
.setName("Marius2")
assertThat(updatedUser.getCreatedAt()).isEqualTo(user.getCreatedAt());
assertThat(updatedUser.getUpdatedAt()).isGreaterThan(user.getCreatedAt());
- List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
- assertThat(indexUsers).hasSize(1);
- assertThat(indexUsers.get(0).getSourceAsMap())
- .contains(
- entry("login", DEFAULT_LOGIN),
- entry("name", "Marius2"),
- entry("email", "marius2@mail.com"));
verify(auditPersister, never()).updateUserPassword(any(), any());
}
assertThat(userReloaded.getCryptedPassword()).isEqualTo(user.getCryptedPassword());
}
- @Test
- public void update_index_when_updating_user_login() {
- UserDto oldUser = db.users().insertUser();
- createDefaultGroup();
- userIndexer.indexAll();
-
- underTest.updateAndCommit(session, oldUser, new UpdateUser()
- .setLogin("new_login"), u -> {
- });
-
- List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
- assertThat(indexUsers).hasSize(1);
- assertThat(indexUsers.get(0).getSourceAsMap())
- .contains(entry("login", "new_login"));
- }
-
@Test
public void update_default_assignee_when_updating_login() {
createDefaultGroup();
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()));
db.properties().insertProperties(oldUser.getLogin(), anotherProject.getKey(), anotherProject.name(), anotherProject.qualifier(),
new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid()));
- userIndexer.indexAll();
underTest.updateAndCommit(session, oldUser, new UpdateUser()
.setLogin("new_login"), u -> {
assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(user.getUpdatedAt());
}
- @Test
- public void update_user_and_index_other_user() {
- createDefaultGroup();
- UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com")
- .setScmAccounts(asList("ma", "marius33")));
- UserDto otherUser = db.users().insertUser();
-
- underTest.updateAndCommit(session, user, new UpdateUser()
- .setName("Marius2")
- .setEmail("marius2@mail.com")
- .setPassword("password2")
- .setScmAccounts(asList("ma2")), u -> {
- }, otherUser);
-
- assertThat(es.getIds(UserIndexDefinition.TYPE_USER)).containsExactlyInAnyOrder(user.getUuid(), otherUser.getUuid());
- }
-
@Test
public void fail_to_set_null_password_when_local_user() {
UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com"));
import org.sonar.db.es.EsQueueDto;
import org.sonar.server.es.IndexType.IndexMainType;
import org.sonar.server.rule.index.RuleIndexer;
-import org.sonar.server.user.index.UserIndexer;
import static java.util.stream.IntStream.rangeClosed;
import static org.assertj.core.api.Assertions.assertThat;
}
private RecoveryIndexer newRecoveryIndexer() {
- UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
- return newRecoveryIndexer(userIndexer, ruleIndexer);
+ return newRecoveryIndexer(ruleIndexer);
}
private RecoveryIndexer newRecoveryIndexer(ResilientIndexer... indexers) {
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
-import org.elasticsearch.search.SearchHits;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserQuery;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.EsUtils;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.ExternalIdentity;
-import org.sonar.server.user.index.UserDoc;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_UUID;
public class AnonymizeActionIT {
private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public DbTester db = DbTester.create(system2);
@Rule
- public EsTester es = EsTester.create();
- @Rule
public UserSessionRule userSession = UserSessionRule.standalone();
private final DbClient dbClient = db.getDbClient();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final UserAnonymizer userAnonymizer = new UserAnonymizer(db.getDbClient());
- private final WsActionTester ws = new WsActionTester(new AnonymizeAction(dbClient, userIndexer, userSession, userAnonymizer));
+ private final WsActionTester ws = new WsActionTester(new AnonymizeAction(dbClient, userSession, userAnonymizer));
@Test
public void anonymize_user() {
TestResponse response = anonymize(user.getLogin());
verifyThatUserIsAnonymized(user.getUuid());
- verifyThatUserIsAnonymizedOnEs(user.getUuid());
assertThat(response.getInput()).isEmpty();
}
return request.execute();
}
- private void verifyThatUserIsAnonymizedOnEs(String uuid) {
- SearchHits hits = es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
- .source(new SearchSourceBuilder()
- .query(boolQuery()
- .must(termQuery(FIELD_UUID, uuid))
- .must(termQuery(FIELD_ACTIVE, "false")))))
- .getHits();
- List<UserDoc> userDocs = EsUtils.convertToDocs(hits, UserDoc::new);
- assertThat(userDocs).hasSize(1);
- assertThat(userDocs.get(0).login()).startsWith("sq-removed-");
- assertThat(userDocs.get(0).name()).startsWith("sq-removed-");
- }
-
private void verifyThatUserIsAnonymized(String uuid) {
List<UserDto> users = dbClient.userDao().selectUsers(db.getSession(), UserQuery.builder().isActive(false).build());
assertThat(users).hasSize(1);
import org.sonar.db.user.UserDto;
import org.sonar.server.authentication.CredentialsLocalAuthentication;
import org.sonar.server.authentication.JwtHttpHandler;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.ws.ServletFilterHandler;
@Rule
public DbTester db = DbTester.create();
@Rule
- public EsTester es = EsTester.createCustom(UserIndexDefinition.createForTest());
- @Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn();
private final ArgumentCaptor<UserDto> userDtoCaptor = ArgumentCaptor.forClass(UserDto.class);
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(),
- new UserIndexer(db.getDbClient(), es.client()), new DefaultGroupFinder(db.getDbClient()),
+ new DefaultGroupFinder(db.getDbClient()),
new MapSettings().asConfig(), new NoOpAuditPersister(), localAuthentication);
private final JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
import java.util.List;
import java.util.Optional;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.user.ws.CreateAction.CreateRequest;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.ws.TestRequest;
import static java.util.Optional.ofNullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_EMAIL;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_LOGIN;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_NAME;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_SCM_ACCOUNTS;
public class CreateActionIT {
@Rule
public DbTester db = DbTester.create(system2);
@Rule
- public EsTester es = EsTester.create();
- @Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
- private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
private GroupDto defaultGroup;
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
private final WsActionTester tester = new WsActionTester(new CreateAction(db.getDbClient(), new UserUpdater(mock(NewUserNotifier.class),
- db.getDbClient(), userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), new NoOpAuditPersister(), localAuthentication), userSessionRule, managedInstanceChecker));
+ db.getDbClient(), new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), new NoOpAuditPersister(), localAuthentication), userSessionRule, managedInstanceChecker));
@Before
public void setUp() {
.extracting(User::getLogin, User::getName, User::getEmail, User::getScmAccountsList, User::getLocal)
.containsOnly("john", "John", "john@email.com", singletonList("jn"), true);
- // exists in index
- assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
- .source(new SearchSourceBuilder()
- .query(boolQuery()
- .must(termQuery(FIELD_LOGIN, "john"))
- .must(termQuery(FIELD_NAME, "John"))
- .must(termQuery(FIELD_EMAIL, "john@email.com"))
- .must(termQuery(FIELD_SCM_ACCOUNTS, "jn")))))
- .getHits().getHits()).hasSize(1);
-
// exists in db
Optional<UserDto> dbUser = db.users().selectUserByLogin("john");
assertThat(dbUser).isPresent();
logInAsSystemAdministrator();
db.users().insertUser(newUserDto("john", "John", "john@email.com").setActive(false));
- userIndexer.indexAll();
call(CreateRequest.builder()
.setLogin("john")
import java.util.Optional;
import javax.annotation.Nullable;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.db.user.SessionTokenDto;
import org.sonar.db.user.UserDismissedMessageDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.management.ManagedInstanceChecker;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.ExternalIdentity;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.sonar.db.property.PropertyTesting.newUserPropertyDto;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_ACTIVE;
-import static org.sonar.server.user.index.UserIndexDefinition.FIELD_UUID;
import static org.sonar.test.JsonAssert.assertJson;
public class DeactivateActionIT {
@Rule
public DbTester db = DbTester.create(system2);
@Rule
- public EsTester es = EsTester.create();
- @Rule
public UserSessionRule userSession = UserSessionRule.standalone();
private final DbClient dbClient = db.getDbClient();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final DbSession dbSession = db.getSession();
private final UserAnonymizer userAnonymizer = new UserAnonymizer(db.getDbClient(), () -> "anonymized");
- private final UserDeactivator userDeactivator = new UserDeactivator(dbClient, userIndexer, userSession, userAnonymizer);
+ private final UserDeactivator userDeactivator = new UserDeactivator(dbClient, userSession, userAnonymizer);
private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
private final WsActionTester ws = new WsActionTester(new DeactivateAction(dbClient, userSession, new UserJsonWriter(userSession), userDeactivator, managedInstanceChecker));
deactivate(user.getLogin());
verifyThatUserIsDeactivated(user.getLogin());
- assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
- .source(new SearchSourceBuilder()
- .query(boolQuery()
- .must(termQuery(FIELD_UUID, user.getUuid()))
- .must(termQuery(FIELD_ACTIVE, "false")))))
- .getHits().getHits()).hasSize(1);
}
@Test
verifyThatUserIsDeactivated("anonymized");
verifyThatUserIsAnomymized("anonymized");
- assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER)
- .source(new SearchSourceBuilder()
- .query(boolQuery()
- .must(termQuery(FIELD_UUID, user.getUuid()))
- .must(termQuery(FIELD_ACTIVE, "false")))))
- .getHits().getHits()).hasSize(1);
}
@Test
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
import org.sonar.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create(system2);
@Rule
- public EsTester es = EsTester.create();
- @Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient(), settings.asConfig());
private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
private final WsActionTester ws = new WsActionTester(new UpdateAction(
- new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
+ new UserUpdater(mock(NewUserNotifier.class), dbClient, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
userSession, new UserJsonWriter(userSession), dbClient, managedInstanceChecker));
@Before
.setExternalLogin("jo")
.setExternalIdentityProvider("sonarqube");
dbClient.userDao().insert(dbSession, userDto);
- userIndexer.commitAndIndex(dbSession, userDto);
+ dbSession.commit();
}
}
import org.sonar.server.authentication.CredentialsLocalAuthentication;
import org.sonar.server.authentication.IdentityProviderRepositoryRule;
import org.sonar.server.authentication.TestIdentityProvider;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create();
@Rule
- public EsTester es = EsTester.create();
- @Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
private final MapSettings settings = new MapSettings().setProperty("sonar.internal.pbkdf2.iterations", "1");
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
- private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(dbClient, settings.asConfig());
private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
private final WsActionTester underTest = new WsActionTester(new UpdateIdentityProviderAction(dbClient, identityProviderRepository,
- new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
+ new UserUpdater(mock(NewUserNotifier.class), dbClient, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), null, localAuthentication),
userSession, managedInstanceChecker));
@Test
.setExternalLogin(externalLogin)
.setExternalIdentityProvider(externalIdentityProvider);
dbClient.userDao().insert(dbSession, userDto);
- userIndexer.commitAndIndex(dbSession, userDto);
+ dbSession.commit();
}
}
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
-import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create(system2);
@Rule
- public EsTester es = EsTester.create();
- @Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn().setSystemAdministrator();
private final ManagedInstanceChecker managedInstanceChecker = mock(ManagedInstanceChecker.class);
private final WsActionTester ws = new WsActionTester(new UpdateLoginAction(db.getDbClient(), userSession,
- new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()), null, null, null, null), managedInstanceChecker));
+ new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), null, null, null, null), managedInstanceChecker));
@Test
public void update_login_from_sonarqube_account_when_user_is_local() {
import org.sonar.db.DbSession;
import org.sonar.db.user.UserDto;
import org.sonar.server.user.UserSession;
-import org.sonar.server.user.index.UserIndexer;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
private static final String PARAM_LOGIN = "login";
private final DbClient dbClient;
- private final UserIndexer userIndexer;
private final UserSession userSession;
private final UserAnonymizer userAnonymizer;
- public AnonymizeAction(DbClient dbClient, UserIndexer userIndexer, UserSession userSession, UserAnonymizer userAnonymizer) {
+ public AnonymizeAction(DbClient dbClient, UserSession userSession, UserAnonymizer userAnonymizer) {
this.userAnonymizer = userAnonymizer;
this.dbClient = dbClient;
- this.userIndexer = userIndexer;
this.userSession = userSession;
}
userAnonymizer.anonymize(dbSession, user);
dbClient.userDao().update(dbSession, user);
- userIndexer.commitAndIndex(dbSession, user);
+ dbSession.commit();
}
response.noContent();
import org.sonar.db.property.PropertyQuery;
import org.sonar.db.user.UserDto;
import org.sonar.server.user.UserSession;
-import org.sonar.server.user.index.UserIndexer;
import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER;
public class UserDeactivator {
private final DbClient dbClient;
- private final UserIndexer userIndexer;
private final UserSession userSession;
private final UserAnonymizer userAnonymizer;
- public UserDeactivator(DbClient dbClient, UserIndexer userIndexer, UserSession userSession, UserAnonymizer userAnonymizer) {
+ public UserDeactivator(DbClient dbClient, UserSession userSession, UserAnonymizer userAnonymizer) {
this.dbClient = dbClient;
- this.userIndexer = userIndexer;
this.userSession = userSession;
this.userAnonymizer = userAnonymizer;
}
private void deactivateUser(DbSession dbSession, UserDto user) {
dbClient.userDao().deactivateUser(dbSession, user);
- userIndexer.commitAndIndex(dbSession, user);
+ dbSession.commit();
}
}
import org.sonar.server.user.SecurityRealmFactory;
import org.sonar.server.user.UserSessionFactoryImpl;
import org.sonar.server.user.UserUpdater;
-import org.sonar.server.user.index.UserIndex;
-import org.sonar.server.user.index.UserIndexDefinition;
-import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.user.ws.UsersWsModule;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.usergroups.ws.UserGroupsModule;
UserSessionFactoryImpl.class,
SecurityRealmFactory.class,
NewUserNotifier.class,
- UserIndexDefinition.class,
- UserIndexer.class,
- UserIndex.class,
UserUpdater.class,
new UsersWsModule(),
new UserTokenModule(),