Revert "AccountManager: Load external ID from primary storage"

With 2.14 external IDs are still in ReviewDb. The schema migration that
migrates external IDs from ReviewDb to NoteDb is only part of [1] which
is not included in 2.14.

2.14 already writes new external IDs to NoteDb, but reading must always
done from ReviewDb (or the account index).

[1] https://gerrit-review.googlesource.com/93470

This reverts commit 38b17c63dfa7257467fb52dba47388ebab07d0ea.

Change-Id: Ie75d635e0b62e142eea2608a43b5ba3937a6ccb2
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java
index 5887129..b0dcbe4 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java
@@ -60,7 +60,6 @@
   private final AtomicBoolean awaitsFirstAccountCheck;
   private final AuditService auditService;
   private final Provider<InternalAccountQuery> accountQueryProvider;
-  private final ExternalIds externalIds;
   private final ExternalIdsUpdate.Server externalIdsUpdateFactory;
 
   @Inject
@@ -74,7 +73,6 @@
       ProjectCache projectCache,
       AuditService auditService,
       Provider<InternalAccountQuery> accountQueryProvider,
-      ExternalIds externalIds,
       ExternalIdsUpdate.Server externalIdsUpdateFactory) {
     this.schema = schema;
     this.byIdCache = byIdCache;
@@ -86,7 +84,6 @@
     this.awaitsFirstAccountCheck = new AtomicBoolean(true);
     this.auditService = auditService;
     this.accountQueryProvider = accountQueryProvider;
-    this.externalIds = externalIds;
     this.externalIdsUpdateFactory = externalIdsUpdateFactory;
   }
 
@@ -114,7 +111,7 @@
     who = realm.authenticate(who);
     try {
       try (ReviewDb db = schema.open()) {
-        ExternalId id = externalIds.get(who.getExternalIdKey());
+        ExternalId id = findExternalId(who.getExternalIdKey());
         if (id == null) {
           // New account, automatically create and return.
           //
@@ -136,6 +133,18 @@
     }
   }
 
+  private ExternalId findExternalId(ExternalId.Key key) throws OrmException {
+    AccountState accountState = accountQueryProvider.get().oneByExternalId(key);
+    if (accountState != null) {
+      for (ExternalId extId : accountState.getExternalIds()) {
+        if (extId.key().equals(key)) {
+          return extId;
+        }
+      }
+    }
+    return null;
+  }
+
   private void update(ReviewDb db, AuthRequest who, ExternalId extId)
       throws OrmException, IOException, ConfigInvalidException {
     IdentifiedUser user = userFactory.create(extId.accountId());
@@ -348,7 +357,7 @@
   public AuthResult link(Account.Id to, AuthRequest who)
       throws AccountException, OrmException, IOException, ConfigInvalidException {
     try (ReviewDb db = schema.open()) {
-      ExternalId extId = externalIds.get(who.getExternalIdKey());
+      ExternalId extId = findExternalId(who.getExternalIdKey());
       if (extId != null) {
         if (!extId.accountId().equals(to)) {
           throw new AccountException("Identity in use by another account");
@@ -423,7 +432,7 @@
   public AuthResult unlink(Account.Id from, AuthRequest who)
       throws AccountException, OrmException, IOException, ConfigInvalidException {
     try (ReviewDb db = schema.open()) {
-      ExternalId extId = externalIds.get(who.getExternalIdKey());
+      ExternalId extId = findExternalId(who.getExternalIdKey());
       if (extId != null) {
         if (!extId.accountId().equals(from)) {
           throw new AccountException(