Invalidate the SSH key cache when a user's keys change

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-12-29 15:18:29 -08:00
parent 0c564cb58f
commit e77e6fc878
2 changed files with 6 additions and 2 deletions

View File

@@ -76,6 +76,7 @@ public class AccountSecurityImpl extends BaseServiceImplementation implements
newKey.setInvalid(); newKey.setInvalid();
} }
db.accountSshKeys().insert(Collections.singleton(newKey)); db.accountSshKeys().insert(Collections.singleton(newKey));
SshUtil.invalidate(db.accounts().get(me));
return newKey; return newKey;
} }
}); });
@@ -96,6 +97,7 @@ public class AccountSecurityImpl extends BaseServiceImplementation implements
final Transaction txn = db.beginTransaction(); final Transaction txn = db.beginTransaction();
db.accountSshKeys().delete(k, txn); db.accountSshKeys().delete(k, txn);
txn.commit(); txn.commit();
SshUtil.invalidate(db.accounts().get(me));
} }
return VoidResult.INSTANCE; return VoidResult.INSTANCE;

View File

@@ -139,8 +139,10 @@ public class SshUtil {
/** Invalidate all cached keys for the given account. */ /** Invalidate all cached keys for the given account. */
public static void invalidate(final Account acct) { public static void invalidate(final Account acct) {
synchronized (keys) { if (acct != null) {
keys.remove(acct.getPreferredEmail()); synchronized (keys) {
keys.remove(acct.getPreferredEmail());
}
} }
} }