From 503a853acad49ac6da7f520c26b3b27942dbfec5 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] Merge AbstractSshCommand and BaseCommand into a single class --- src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java | 38 ++++---------------------------------- 1 files changed, 4 insertions(+), 34 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..1f0d902 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 { +@CommandMetaData(name = "set-account", description = "Change an account's settings", admin = true) +public class SetAccountCommand extends BaseKeyCommand { private static final String ALL = "ALL"; @@ -61,16 +56,15 @@ } 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); } - authenticator.getKeyCache().invalidate(user); } private void addSshKeys(List<String> sshKeys) throws UnloggedFailure, @@ -90,29 +84,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