accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [1/9] accumulo git commit: Revert "ACCUMULO-4461: modified commands to not prompt for a password"
Date Mon, 26 Sep 2016 13:13:41 GMT
Repository: accumulo
Updated Branches:
  refs/heads/1.7 deb5edd8d -> 064ae0aa7
  refs/heads/1.8 509ce9895 -> c1dda7786
  refs/heads/master 34b85c944 -> ababa81c3


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/1.7
Commit: 221dc3fe3e13f57a6f21541390fbaa88622aaec5
Parents: deb5edd
Author: Josh Elser <elserj@apache.org>
Authored: Mon Sep 26 09:10:34 2016 -0400
Committer: Josh Elser <elserj@apache.org>
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<Long> {
@@ -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<Password> {
@@ -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;
 


Mime
View raw message