From 8982e6e0738c6991b9a4b864423bd4f75383c7f4 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 10 Apr 2014 18:58:08 -0400
Subject: [PATCH] Add add-key and rm-key commands that apply only to the current user

---
 src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java |   35 +++--------------------------------
 1 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java
index 767f3cb..0eabdce 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java
@@ -14,10 +14,7 @@
 
 package com.gitblit.transport.ssh.commands;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -27,12 +24,10 @@
 
 import com.gitblit.transport.ssh.CommandMetaData;
 import com.gitblit.transport.ssh.IKeyManager;
-import com.gitblit.transport.ssh.SshKeyAuthenticator;
-import com.google.common.base.Charsets;
 
 /** Set a user's account settings. **/
 @CommandMetaData(name = "set-account", description = "Change an account's settings")
-public class SetAccountCommand extends SshCommand {
+public class SetAccountCommand extends BaseKeyCommand {
 
 	private static final String ALL = "ALL";
 
@@ -61,12 +56,12 @@
 	}
 
 	private void setAccount() throws IOException, UnloggedFailure {
-		addSshKeys = readSshKey(addSshKeys);
+		addSshKeys = readKeys(addSshKeys);
 		if (!addSshKeys.isEmpty()) {
 			addSshKeys(addSshKeys);
 		}
 
-		deleteSshKeys = readSshKey(deleteSshKeys);
+		deleteSshKeys = readKeys(deleteSshKeys);
 		if (!deleteSshKeys.isEmpty()) {
 			deleteSshKeys(deleteSshKeys);
 		}
@@ -90,29 +85,5 @@
 				keyManager.removeKey(user, sshKey);
 			}
 		}
-	}
-
-	private List<String> readSshKey(List<String> sshKeys)
-			throws UnsupportedEncodingException, IOException {
-		if (!sshKeys.isEmpty()) {
-			String sshKey;
-			int idx = sshKeys.indexOf("-");
-			if (idx >= 0) {
-				sshKey = "";
-				BufferedReader br = new BufferedReader(new InputStreamReader(
-						in, Charsets.UTF_8));
-				String line;
-				while ((line = br.readLine()) != null) {
-					sshKey += line + "\n";
-				}
-				sshKeys.set(idx, sshKey);
-			}
-		}
-		return sshKeys;
-	}
-
-	private SshKeyAuthenticator authenticator;
-	public void setAuthenticator(SshKeyAuthenticator authenticator) {
-		this.authenticator = authenticator;
 	}
 }

--
Gitblit v1.9.1