From: James Moger Date: Wed, 19 Mar 2014 16:34:00 +0000 (-0400) Subject: Fix exception handling for account with no public keys X-Git-Tag: v1.5.0~68^2~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fdf85cf245cddf121d35799637aaea8795db2ebd;p=gitblit.git Fix exception handling for account with no public keys --- 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();