use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class LocalUsernamesToLowerCase method replaceIfNotExists.
private void replaceIfNotExists(ExternalIdNotes extIdNotes, ExternalId extId, ExternalId extIdLowerCase) throws IOException {
try {
Optional<ExternalId> existingExternalId = extIdNotes.get(extIdLowerCase.key()).filter(eid -> eid.accountId().equals(extIdLowerCase.accountId())).filter(eid -> StringUtils.equalsIgnoreCase(eid.email(), extId.email())).filter(eid -> StringUtils.equalsIgnoreCase(eid.password(), extId.password()));
if (existingExternalId.isPresent()) {
System.err.println("WARNING: external-id " + extIdLowerCase + " already exists with the same account-id " + extId.accountId() + " :" + "removing the duplicate external-id " + extId.key());
extIdNotes.delete(extId);
} else {
extIdNotes.replace(extId, extIdLowerCase);
}
} catch (ConfigInvalidException e) {
throw new IOException("Unable to parse external id definition when looking for current external-id " + extIdLowerCase, e);
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdsOnInit method insert.
public synchronized void insert(String commitMessage, Collection<ExternalId> extIds) throws IOException, ConfigInvalidException {
File path = getPath();
if (path != null) {
try (Repository allUsersRepo = new FileRepository(path)) {
ExternalIdNotes extIdNotes = ExternalIdNotes.load(allUsers, allUsersRepo, externalIdFactory, authConfig.isUserNameCaseInsensitiveMigrationMode());
extIdNotes.insert(extIds);
try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, allUsersRepo)) {
PersonIdent serverIdent = new GerritPersonIdentProvider(flags.cfg).get();
metaDataUpdate.getCommitBuilder().setAuthor(serverIdent);
metaDataUpdate.getCommitBuilder().setCommitter(serverIdent);
metaDataUpdate.getCommitBuilder().setMessage(commitMessage);
extIdNotes.commit(metaDataUpdate);
}
}
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ChangeExternalIdCaseSensitivityIT method getExternalIdNotes.
private static ExternalIdNotes getExternalIdNotes(ServerContext ctx, Project.NameKey allUsers) throws Exception {
GitRepositoryManager repoManager = ctx.getInjector().getInstance(GitRepositoryManager.class);
ExternalIdNotes.FactoryNoReindex extIdNotesFactory = ctx.getInjector().getInstance(ExternalIdNotes.FactoryNoReindex.class);
return extIdNotesFactory.load(repoManager.openRepository(allUsers));
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method createCaseInsensitiveMigrationModeExternalIdBeforeTheMigration.
@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
@GerritConfig(name = "auth.userNameCaseInsensitiveMigrationMode", value = "true")
public void createCaseInsensitiveMigrationModeExternalIdBeforeTheMigration() throws Exception {
Account.Id accountId = Account.id(66);
boolean isUserNameCaseInsensitive = false;
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
createExternalId(md, extIdNotes, SCHEME_GERRIT, "JaneDoe", accountId, isUserNameCaseInsensitive);
createExternalId(md, extIdNotes, SCHEME_USERNAME, "JaneDoe", accountId, isUserNameCaseInsensitive);
assertThat(getAccountId(extIdNotes, SCHEME_GERRIT, "JaneDoe")).isEqualTo(accountId.get());
assertThat(getExternalId(extIdNotes, SCHEME_GERRIT, "janedoe").isPresent()).isFalse();
assertThat(getAccountId(extIdNotes, SCHEME_USERNAME, "JaneDoe")).isEqualTo(accountId.get());
assertThat(getExternalId(extIdNotes, SCHEME_USERNAME, "janedoe").isPresent()).isFalse();
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdNotesUpsertPreprocessorIT method blockUpsert_replace.
@Test
public void blockUpsert_replace() throws Exception {
Account.Id id = Account.id(sequences.nextAccountId());
ExternalId extId1 = extIdFactory.create("foo", "bar", id, "email1@foo", "hash");
ExternalId extId2 = extIdFactory.create("foo", "bar", id, "email2@foo", "hash");
accountsUpdateProvider.get().insert("test", id, u -> u.addExternalId(extId1));
assertThat(accounts.get(id).get().externalIds()).containsExactly(extId1);
testPreprocessor.reset();
testPreprocessor.throwException = true;
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
extIdNotes.replace(ImmutableSet.of(extId1), ImmutableSet.of(extId2));
StorageException e = assertThrows(StorageException.class, () -> extIdNotes.commit(md));
assertThat(e).hasMessageThat().contains("upsert not good");
}
assertThat(testPreprocessor.upserted).isEmpty();
assertThat(accounts.get(id).get().externalIds()).containsExactly(extId1);
}
Aggregations