Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AA883200B9F for ; Mon, 26 Sep 2016 15:13:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A9431160AC8; Mon, 26 Sep 2016 13:13:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 76F65160AE6 for ; Mon, 26 Sep 2016 15:13:42 +0200 (CEST) Received: (qmail 44534 invoked by uid 500); 26 Sep 2016 13:13:41 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 44416 invoked by uid 99); 26 Sep 2016 13:13:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2016 13:13:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4EE4FE0ADC; Mon, 26 Sep 2016 13:13:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Mon, 26 Sep 2016 13:13:43 -0000 Message-Id: <2a6d8d1c710d421c9aed2c72b9be8a54@git.apache.org> In-Reply-To: <2c4a3164c17d4bff9ca3fc3c3362a1e1@git.apache.org> References: <2c4a3164c17d4bff9ca3fc3c3362a1e1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/9] accumulo git commit: Revert "ACCUMULO-4461: modified commands to not prompt for a password" archived-at: Mon, 26 Sep 2016 13:13:43 -0000 Revert "ACCUMULO-4461: modified commands to not prompt for a password" This reverts commit d23676dc3698d2ca6084b17cd4326b43dbcec41c. Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/221dc3fe Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/221dc3fe Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/221dc3fe Branch: refs/heads/master Commit: 221dc3fe3e13f57a6f21541390fbaa88622aaec5 Parents: deb5edd Author: Josh Elser Authored: Mon Sep 26 09:10:34 2016 -0400 Committer: Josh Elser Committed: Mon Sep 26 09:10:34 2016 -0400 ---------------------------------------------------------------------- .../apache/accumulo/core/cli/ClientOpts.java | 37 ++++---------------- .../accumulo/core/cli/TestClientOpts.java | 12 +++---- .../org/apache/accumulo/server/util/Admin.java | 14 +++++++- 3 files changed, 24 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/221dc3fe/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java index 98421d5..54e8b53 100644 --- a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java +++ b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java @@ -58,8 +58,6 @@ import com.beust.jcommander.IStringConverter; import com.beust.jcommander.Parameter; import com.google.common.base.Predicate; -import jline.console.ConsoleReader; - public class ClientOpts extends Help { public static class TimeConverter implements IStringConverter { @@ -94,20 +92,6 @@ public class ClientOpts extends Help { public String toString() { return new String(value, UTF_8); } - - /** - * Prompts user for a password - * - * @return user entered Password object, null if no console exists - */ - public static Password promptUser() throws IOException { - if (System.console() == null) { - throw new IOException("Attempted to prompt user on the console when System.console = null"); - } - ConsoleReader reader = new ConsoleReader(); - String enteredPass = reader.readLine("Enter password: ", '*'); - return new Password(enteredPass); - } } public static class PasswordConverter implements IStringConverter { @@ -158,20 +142,13 @@ public class ClientOpts extends Help { } } - // other token types should have resolved by this point, so return PasswordToken - Password pass = null; - if (securePassword != null) { - pass = securePassword; - } else if (password != null) { - pass = password; - } else { - try { - pass = Password.promptUser(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return new PasswordToken(pass.value); + if (securePassword != null) + return new PasswordToken(securePassword.value); + + if (password != null) + return new PasswordToken(password.value); + + return null; } @Parameter(names = {"-z", "--keepers"}, description = "Comma separated list of zookeeper hosts (host:port,host:port)") http://git-wip-us.apache.org/repos/asf/accumulo/blob/221dc3fe/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java b/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java index 3da5b30..65df5c9 100644 --- a/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java +++ b/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java @@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit; import javax.security.auth.DestroyFailedException; +import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriterConfig; import org.apache.accumulo.core.client.ClientConfiguration; import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty; @@ -65,19 +66,14 @@ public class TestClientOpts { BatchWriterOpts bwOpts = new BatchWriterOpts(); BatchScannerOpts bsOpts = new BatchScannerOpts(); try { - args.getPrincipal(); + assertNull(args.getPrincipal()); fail("Expected to receive exception fetching non-existent principal"); - } catch (RuntimeException e) { + } catch (AccumuloSecurityException e) { // Pass -- no explicit principal and no token to infer a principal from } assertNull(args.getSecurePassword()); - try { - args.getToken(); - fail("Expected to receive exception fetching non-existent token"); - } catch (RuntimeException e) { - // pass - no console to prompt user for password - } + assertNull(args.getToken()); assertEquals(Long.valueOf(cfg.getMaxLatency(TimeUnit.MILLISECONDS)), bwOpts.batchLatency); assertEquals(Long.valueOf(cfg.getTimeout(TimeUnit.MILLISECONDS)), bwOpts.batchTimeout); assertEquals(Long.valueOf(cfg.getMaxMemory()), bwOpts.batchMemory); http://git-wip-us.apache.org/repos/asf/accumulo/blob/221dc3fe/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java index bd080ec..9a8f6ed 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java @@ -43,6 +43,7 @@ import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.admin.InstanceOperations; import org.apache.accumulo.core.client.impl.ClientContext; import org.apache.accumulo.core.client.impl.ClientExec; +import org.apache.accumulo.core.client.impl.Credentials; import org.apache.accumulo.core.client.impl.MasterClient; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.DefaultConfiguration; @@ -208,7 +209,18 @@ public class Admin implements KeywordExecutable { ServerConfigurationFactory confFactory = new ServerConfigurationFactory(instance); try { - ClientContext context = new AccumuloServerContext(confFactory); + ClientContext context; + if (opts.getToken() == null) { + context = new AccumuloServerContext(confFactory); + } else { + final Credentials userCreds = new Credentials(opts.getPrincipal(), opts.getToken()); + context = new AccumuloServerContext(confFactory) { + @Override + public synchronized Credentials getCredentials() { + return userCreds; + } + }; + } int rc = 0;