Move sshUserName from Account to AccountExternalId
We remove the secondary unique column sshUserName and store it in the AccountExternalId entity instead. This change is necessary to support databases which do not allow mulitiple key attributes for an entity. Change-Id: I20076a05f2ea083da6044a4f1ed2f0672e85739a Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import static com.google.gerrit.reviewdb.AccountExternalId.SCHEME_USERNAME;
|
||||
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.reviewdb.Account;
|
||||
import com.google.gerrit.reviewdb.AccountExternalId;
|
||||
import com.google.gerrit.reviewdb.AccountSshKey;
|
||||
import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.cache.Cache;
|
||||
@@ -122,14 +124,18 @@ public class SshKeyCacheImpl implements SshKeyCache {
|
||||
throws Exception {
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final Account user = db.accounts().bySshUserName(username);
|
||||
final AccountExternalId.Key key =
|
||||
new AccountExternalId.Key(SCHEME_USERNAME, username);
|
||||
final AccountExternalId user = db.accountExternalIds().get(key);
|
||||
if (user == null) {
|
||||
return NO_SUCH_USER;
|
||||
}
|
||||
|
||||
final List<SshKeyCacheEntry> kl = new ArrayList<SshKeyCacheEntry>(4);
|
||||
for (final AccountSshKey k : db.accountSshKeys().valid(user.getId())) {
|
||||
add(db, kl, k);
|
||||
for (AccountSshKey k : db.accountSshKeys().byAccount(user.getAccountId())) {
|
||||
if (k.isValid()) {
|
||||
add(db, kl, k);
|
||||
}
|
||||
}
|
||||
if (kl.isEmpty()) {
|
||||
return NO_KEYS;
|
||||
|
||||
@@ -182,7 +182,7 @@ class SshLog implements LifecycleListener {
|
||||
);
|
||||
|
||||
event.setProperty(P_SESSION, id(s.getAttribute(SshUtil.SESSION_ID)));
|
||||
event.setProperty(P_USER_NAME, u.getAccount().getSshUserName());
|
||||
event.setProperty(P_USER_NAME, u.getUserName());
|
||||
event.setProperty(P_ACCOUNT_ID, "a/" + u.getAccountId().toString());
|
||||
|
||||
return event;
|
||||
|
||||
Reference in New Issue
Block a user