From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001
From: Gerard Smyth <gerard.smyth@gmail.com>
Date: Thu, 08 May 2014 13:09:30 -0400
Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.

---
 src/main/java/com/gitblit/transport/ssh/MemoryKeyManager.java |   48 ++++++++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/gitblit/transport/ssh/MemoryKeyManager.java b/src/main/java/com/gitblit/transport/ssh/MemoryKeyManager.java
index 26bd021..357b34a 100644
--- a/src/main/java/com/gitblit/transport/ssh/MemoryKeyManager.java
+++ b/src/main/java/com/gitblit/transport/ssh/MemoryKeyManager.java
@@ -15,7 +15,6 @@
  */
 package com.gitblit.transport.ssh;
 
-import java.security.PublicKey;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -29,10 +28,10 @@
  */
 public class MemoryKeyManager extends IPublicKeyManager {
 
-	Map<String, List<PublicKey>> keys;
+	final Map<String, List<SshKey>> keys;
 
 	public MemoryKeyManager() {
-		keys = new HashMap<String, List<PublicKey>>();
+		keys = new HashMap<String, List<SshKey>>();
 	}
 
 	@Override
@@ -58,11 +57,12 @@
 
 	@Override
 	protected boolean isStale(String username) {
-		return false;
+		// always return true so we gets keys from our hashmap
+		return true;
 	}
 
 	@Override
-	protected List<PublicKey> getKeysImpl(String username) {
+	protected List<SshKey> getKeysImpl(String username) {
 		String id = username.toLowerCase();
 		if (keys.containsKey(id)) {
 			return keys.get(id);
@@ -71,28 +71,40 @@
 	}
 
 	@Override
-	public boolean addKey(String username, String data) {
-		return false;
+	public boolean addKey(String username, SshKey key) {
+		String id = username.toLowerCase();
+		if (!keys.containsKey(id)) {
+			keys.put(id, new ArrayList<SshKey>());
+		}
+		log.info("added {} key {}", username, key.getFingerprint());
+		return keys.get(id).add(key);
 	}
 
 	@Override
-	public boolean removeKey(String username, String data) {
-		return false;
+	public boolean removeKey(String username, SshKey key) {
+		String id = username.toLowerCase();
+		if (!keys.containsKey(id)) {
+			log.info("can't remove keys for {}", username);
+			return false;
+		}
+		List<SshKey> list = keys.get(id);
+		boolean success = list.remove(key);
+		if (success) {
+			log.info("removed {} key {}", username, key.getFingerprint());
+		}
+
+		if (list.isEmpty()) {
+			keys.remove(id);
+			log.info("no {} keys left, removed {}", username, username);
+		}
+		return success;
 	}
 
 	@Override
 	public boolean removeAllKeys(String username) {
 		String id = username.toLowerCase();
 		keys.remove(id.toLowerCase());
+		log.info("removed all keys for {}", username);
 		return true;
-	}
-
-	/* Test method for populating the memory key manager */
-	public void addKey(String username, PublicKey key) {
-		String id = username.toLowerCase();
-		if (!keys.containsKey(id)) {
-			keys.put(id, new ArrayList<PublicKey>());
-		}
-		keys.get(id).add(key);
 	}
 }

--
Gitblit v1.9.1