From fdf85cf245cddf121d35799637aaea8795db2ebd Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 19 Mar 2014 12:34:00 -0400 Subject: [PATCH] Fix exception handling for account with no public keys --- .../java/com/gitblit/transport/ssh/IPublicKeyManager.java | 5 +++++ .../com/gitblit/transport/ssh/gitblit/KeysDispatcher.java | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java b/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java index 5857a599..d2135142 100644 --- a/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java +++ b/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.manager.IManager; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; +import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.LoadingCache; /** @@ -64,6 +65,10 @@ public abstract class IPublicKeyManager implements IManager { keyCache.invalidate(username); } return keyCache.get(username); + } catch (InvalidCacheLoadException e) { + if (e.getMessage() == null || !e.getMessage().contains("returned null")) { + log.error(MessageFormat.format("failed to retrieve keys for {0}", username), e); + } } catch (ExecutionException e) { log.error(MessageFormat.format("failed to retrieve keys for {0}", username), e); } diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java index 4430c68d..a54196da 100644 --- a/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java @@ -99,8 +99,12 @@ public class KeysDispatcher extends DispatchCommand { @Override public void run() { IPublicKeyManager keyManager = getContext().getGitblit().getPublicKeyManager(); - List keys = keyManager.getKeys(getContext().getClient().getUsername()); - + String username = getContext().getClient().getUsername(); + List keys = keyManager.getKeys(username); + if (keys == null) { + stdout.println(String.format("%s has not added any public keys for ssh authentication", username)); + return; + } for (PublicKey key : keys) { // two-steps - perhaps this could be improved Buffer buf = new Buffer(); -- 2.39.5