use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class GerritPublicKeyCheckerTest method add.
private void add(PGPPublicKeyRing kr, IdentifiedUser user) throws Exception {
Account.Id id = user.getAccountId();
List<ExternalId> newExtIds = new ArrayList<>(2);
newExtIds.add(ExternalId.create(toExtIdKey(kr.getPublicKey()), id));
@SuppressWarnings("unchecked") String userId = (String) Iterators.getOnlyElement(kr.getPublicKey().getUserIDs(), null);
if (userId != null) {
String email = PushCertificateIdent.parse(userId).getEmailAddress();
assertThat(email).contains("@");
newExtIds.add(ExternalId.createEmail(id, email));
}
store.add(kr);
PersonIdent ident = new PersonIdent("A U Thor", "author@example.com");
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
assertThat(store.save(cb)).isAnyOf(NEW, FAST_FORWARD, FORCED);
externalIdsUpdateFactory.create().insert(newExtIds);
accountCache.evict(user.getAccountId());
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class GerritPublicKeyChecker method getAllowedUserIds.
private Set<String> getAllowedUserIds(IdentifiedUser user) {
Set<String> result = new HashSet<>();
result.addAll(user.getEmailAddresses());
for (ExternalId extId : user.state().getExternalIds()) {
if (extId.isScheme(SCHEME_GPGKEY)) {
// Omit GPG keys.
continue;
}
result.add(extId.key().get());
}
return result;
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class LocalUsernamesToLowerCase method run.
@Override
public int run() throws Exception {
Injector dbInjector = createDbInjector(MULTI_USER);
manager.add(dbInjector, dbInjector.createChildInjector(SchemaVersionCheck.module()));
manager.start();
dbInjector.createChildInjector(new AbstractModule() {
@Override
protected void configure() {
// The LocalUsernamesToLowerCase program needs to access all external IDs only
// once to update them. After the update they are not accessed again. Hence the
// LocalUsernamesToLowerCase program doesn't benefit from caching external IDs and
// the external ID cache can be disabled.
install(DisabledExternalIdCache.module());
}
}).injectMembers(this);
Collection<ExternalId> todo = externalIds.all();
monitor.beginTask("Converting local usernames", todo.size());
for (ExternalId extId : todo) {
convertLocalUserToLowerCase(extId);
monitor.update(1);
}
externalIdsBatchUpdate.commit("Convert local usernames to lower case");
monitor.endTask();
manager.stop();
return 0;
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class LocalUsernamesToLowerCase method convertLocalUserToLowerCase.
private void convertLocalUserToLowerCase(ExternalId extId) {
if (extId.isScheme(SCHEME_GERRIT)) {
String localUser = extId.key().id();
String localUserLowerCase = localUser.toLowerCase(Locale.US);
if (!localUser.equals(localUserLowerCase)) {
ExternalId extIdLowerCase = ExternalId.create(SCHEME_GERRIT, localUserLowerCase, extId.accountId(), extId.email(), extId.password());
externalIdsBatchUpdate.replace(extId, extIdLowerCase);
}
}
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class AbstractRealm method getEmailAddresses.
@Override
public Set<String> getEmailAddresses(IdentifiedUser user) {
Collection<ExternalId> ids = user.state().getExternalIds();
Set<String> emails = Sets.newHashSetWithExpectedSize(ids.size());
for (ExternalId ext : ids) {
if (!Strings.isNullOrEmpty(ext.email())) {
emails.add(ext.email());
}
}
return emails;
}
Aggregations