From 4011b6048cb5f31bdabb5daad94a67ead7869be7 Mon Sep 17 00:00:00 2001
From: Southparkfan <Southparkfan@users.noreply.github.com>
Date: Thu, 26 Feb 2015 08:39:57 -0500
Subject: [PATCH] Fix spelling mistake
---
src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java | 40 ++++++++++++++++++++++++++++++----------
1 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java b/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java
index 5857a59..1e74b2f 100644
--- a/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java
+++ b/src/main/java/com/gitblit/transport/ssh/IPublicKeyManager.java
@@ -15,8 +15,8 @@
*/
package com.gitblit.transport.ssh;
-import java.security.PublicKey;
import java.text.MessageFormat;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -27,10 +27,11 @@
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;
/**
- * Parent class for public key managers.
+ * Parent class for ssh public key managers.
*
* @author James Moger
*
@@ -39,14 +40,18 @@
protected final Logger log = LoggerFactory.getLogger(getClass());
- protected final LoadingCache<String, List<PublicKey>> keyCache = CacheBuilder
+ protected final LoadingCache<String, List<SshKey>> keyCache = CacheBuilder
.newBuilder().
expireAfterAccess(15, TimeUnit.MINUTES).
maximumSize(100)
- .build(new CacheLoader<String, List<PublicKey>>() {
+ .build(new CacheLoader<String, List<SshKey>>() {
@Override
- public List<PublicKey> load(String username) {
- return getKeysImpl(username);
+ public List<SshKey> load(String username) {
+ List<SshKey> keys = getKeysImpl(username);
+ if (keys == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(keys);
}
});
@@ -58,25 +63,40 @@
@Override
public abstract IPublicKeyManager stop();
- public final List<PublicKey> getKeys(String username) {
+ public final List<SshKey> getKeys(String username) {
try {
if (isStale(username)) {
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);
}
return null;
}
+ public final void renameUser(String oldName, String newName) {
+ List<SshKey> 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<PublicKey> getKeysImpl(String username);
+ protected abstract List<SshKey> getKeysImpl(String username);
- public abstract boolean addKey(String username, String data);
+ public abstract boolean addKey(String username, SshKey key);
- public abstract boolean removeKey(String username, String data);
+ public abstract boolean removeKey(String username, SshKey key);
public abstract boolean removeAllKeys(String username);
}
--
Gitblit v1.9.1