From f5ca1655278d8b34a402120864a5a5c628b1c31d Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 10 Apr 2014 16:57:32 -0400 Subject: [PATCH] Rename SSH key store on user rename --- src/main/java/com/gitblit/manager/GitblitManager.java | 3 +++ .../com/gitblit/transport/ssh/IPublicKeyManager.java | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java index 5a7d15ae..e3b6cf7d 100644 --- a/src/main/java/com/gitblit/manager/GitblitManager.java +++ b/src/main/java/com/gitblit/manager/GitblitManager.java @@ -338,6 +338,9 @@ public class GitblitManager implements IGitblit { repositoryManager.updateRepositoryModel(model.name, model, false); } } + + // rename the user's ssh public keystore + getPublicKeyManager().renameUser(username, user.username); } if (!userManager.updateUserModel(username, user)) { throw new GitBlitException("Failed to update user!"); diff --git a/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java b/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java index 0dbee637..1e74b2f0 100644 --- a/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java +++ b/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java @@ -79,6 +79,17 @@ public abstract class IPublicKeyManager implements IManager { return null; } + public final void renameUser(String oldName, String newName) { + List keys = getKeys(oldName); + if (keys == null || keys.isEmpty()) { + return; + } + removeAllKeys(oldName); + for (SshKey key : keys) { + addKey(newName, key); + } + } + protected abstract boolean isStale(String username); protected abstract List getKeysImpl(String username); -- 2.39.5