]> source.dussan.org Git - gitblit.git/commitdiff
Fix exception handling for account with no public keys
authorJames Moger <james.moger@gitblit.com>
Wed, 19 Mar 2014 16:34:00 +0000 (12:34 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 Apr 2014 22:58:09 +0000 (18:58 -0400)
src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java
src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java

index 5857a59985f7037e3f154eeb320a3576fff9da5b..d21351429e31bb27482ee00de28ef38def7baf28 100644 (file)
@@ -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);
                }
index 4430c68dae2d1eb58e9c571d1c08b2022d887428..a54196da6fba8fd129ec43292262a8d6ccd31e91 100644 (file)
@@ -99,8 +99,12 @@ public class KeysDispatcher extends DispatchCommand {
                @Override
                public void run() {
                        IPublicKeyManager keyManager = getContext().getGitblit().getPublicKeyManager();
-                       List<PublicKey> keys = keyManager.getKeys(getContext().getClient().getUsername());
-
+                       String username = getContext().getClient().getUsername();
+                       List<PublicKey> 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();