Search in sources :

Example 21 with ExternalId

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());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ArrayList(java.util.ArrayList) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString)

Example 22 with ExternalId

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;
}
Also used : ExternalId(com.google.gerrit.server.account.externalids.ExternalId) PublicKeyStore.keyIdToString(com.google.gerrit.gpg.PublicKeyStore.keyIdToString) HashSet(java.util.HashSet)

Example 23 with ExternalId

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;
}
Also used : Injector(com.google.inject.Injector) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) AbstractModule(com.google.inject.AbstractModule)

Example 24 with ExternalId

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);
        }
    }
}
Also used : ExternalId(com.google.gerrit.server.account.externalids.ExternalId)

Example 25 with ExternalId

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;
}
Also used : ExternalId(com.google.gerrit.server.account.externalids.ExternalId)

Aggregations

ExternalId (com.google.gerrit.server.account.externalids.ExternalId)34 Account (com.google.gerrit.reviewdb.client.Account)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 Test (org.junit.Test)8 OrmException (com.google.gwtorm.server.OrmException)7 ArrayList (java.util.ArrayList)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)6 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)6 NoteMap (org.eclipse.jgit.notes.NoteMap)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)5 ExternalIdsUpdate (com.google.gerrit.server.account.externalids.ExternalIdsUpdate)5 HashSet (java.util.HashSet)5 AccountExternalIdInfo (com.google.gerrit.extensions.common.AccountExternalIdInfo)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)4 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)4