accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [accumulo] branch master updated: Fixes #414 - Create Connector for new user from existing (#455)
Date Thu, 10 May 2018 16:43:50 GMT
This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 35edb2a  Fixes #414 - Create Connector for new user from existing (#455)
35edb2a is described below

commit 35edb2a4122641f2d17c4919e02c7162d2433962
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Thu May 10 12:43:48 2018 -0400

    Fixes #414 - Create Connector for new user from existing (#455)
---
 .../org/apache/accumulo/core/client/Connector.java  | 12 +++++++++++-
 .../accumulo/core/client/impl/ConnectorImpl.java    | 21 +++++++++++----------
 .../accumulo/core/client/mock/MockConnector.java    |  5 +++++
 .../accumulo/test/functional/ConnectorIT.java       | 14 ++++++++++++++
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/client/Connector.java b/core/src/main/java/org/apache/accumulo/core/client/Connector.java
index cf5661b..41a87c4 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/Connector.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/Connector.java
@@ -314,6 +314,12 @@ public abstract class Connector {
   public abstract ReplicationOperations replicationOperations();
 
   /**
+   * @return {@link ConnectionInfo} which contains information about Connection to Accumulo
+   * @since 2.0.0
+   */
+  public abstract ConnectionInfo info();
+
+  /**
    * Builds ConnectionInfo after all options have been specified
    *
    * @since 2.0.0
@@ -391,7 +397,7 @@ public abstract class Connector {
      *          ConnectionInfo object
      * @return this builder
      */
-    ConnectorFactory usingConnectionInfo(ConnectionInfo connectionInfo);
+    FromOptions usingConnectionInfo(ConnectionInfo connectionInfo);
   }
 
   /**
@@ -574,6 +580,10 @@ public abstract class Connector {
     ConnectionOptions withBatchWriterConfig(BatchWriterConfig batchWriterConfig);
   }
 
+  public interface FromOptions extends ConnectionOptions, PropertyOptions, AuthenticationArgs
{
+
+  }
+
   /**
    * Creates builder for Connector
    *
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
index 1078932..c02169e 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
@@ -46,7 +46,6 @@ import org.apache.accumulo.core.client.admin.NamespaceOperations;
 import org.apache.accumulo.core.client.admin.ReplicationOperations;
 import org.apache.accumulo.core.client.admin.SecurityOperations;
 import org.apache.accumulo.core.client.admin.TableOperations;
-import org.apache.accumulo.core.client.impl.thrift.ClientService;
 import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
 import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
 import org.apache.accumulo.core.client.security.tokens.CredentialProviderToken;
@@ -82,13 +81,10 @@ public class ConnectorImpl extends Connector {
     // server jar
     final String tokenClassName = context.getCredentials().getToken().getClass().getName();
     if (!SYSTEM_TOKEN_NAME.equals(tokenClassName)) {
-      ServerClient.executeVoid(context, new ClientExec<ClientService.Client>() {
-        @Override
-        public void execute(ClientService.Client iface) throws Exception {
-          if (!iface.authenticate(Tracer.traceInfo(), context.rpcCreds()))
-            throw new AccumuloSecurityException("Authentication failed, access denied",
-                SecurityErrorCode.BAD_CREDENTIALS);
-        }
+      ServerClient.executeVoid(context, iface -> {
+        if (!iface.authenticate(Tracer.traceInfo(), context.rpcCreds()))
+          throw new AccumuloSecurityException("Authentication failed, access denied",
+              SecurityErrorCode.BAD_CREDENTIALS);
       });
     }
 
@@ -243,9 +239,14 @@ public class ConnectorImpl extends Connector {
     return replicationops;
   }
 
+  @Override
+  public ConnectionInfo info() {
+    return this.context.getConnectionInfo();
+  }
+
   public static class ConnectorBuilderImpl
       implements InstanceArgs, PropertyOptions, ConnectionInfoOptions, AuthenticationArgs,
-      ConnectionOptions, SslOptions, SaslOptions, ConnectorFactory {
+      ConnectionOptions, SslOptions, SaslOptions, ConnectorFactory, FromOptions {
 
     private Properties properties = new Properties();
     private AuthenticationToken token = null;
@@ -451,7 +452,7 @@ public class ConnectorImpl extends Connector {
     }
 
     @Override
-    public ConnectorFactory usingConnectionInfo(ConnectionInfo connectionInfo) {
+    public FromOptions usingConnectionInfo(ConnectionInfo connectionInfo) {
       this.properties = connectionInfo.getProperties();
       this.token = connectionInfo.getAuthenticationToken();
       return this;
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
index e473f71..c00318a 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
@@ -25,6 +25,7 @@ import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
 import org.apache.accumulo.core.client.ConditionalWriter;
 import org.apache.accumulo.core.client.ConditionalWriterConfig;
+import org.apache.accumulo.core.client.ConnectionInfo;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.client.MultiTableBatchWriter;
@@ -187,4 +188,8 @@ public class MockConnector extends Connector {
     throw new UnsupportedOperationException();
   }
 
+  @Override
+  public ConnectionInfo info() {
+    throw new UnsupportedOperationException();
+  }
 }
diff --git a/test/src/main/java/org/apache/accumulo/test/functional/ConnectorIT.java b/test/src/main/java/org/apache/accumulo/test/functional/ConnectorIT.java
index bf02ac9..4ca61fb 100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/ConnectorIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/ConnectorIT.java
@@ -61,5 +61,19 @@ public class ConnectorIT extends AccumuloClusterHarness {
     Assert.assertEquals(instanceName, conn.getInstance().getInstanceName());
     Assert.assertEquals(zookeepers, conn.getInstance().getZooKeepers());
     Assert.assertEquals(user, conn.whoami());
+
+    final String user2 = "testuser2";
+    final String password2 = "testpassword2";
+    c.securityOperations().createLocalUser(user2, new PasswordToken(password2));
+
+    Connector conn2 = Connector.builder().usingConnectionInfo(conn.info())
+        .usingToken(user2, new PasswordToken(password2)).build();
+    Assert.assertEquals(instanceName, conn2.getInstance().getInstanceName());
+    Assert.assertEquals(zookeepers, conn2.getInstance().getZooKeepers());
+    Assert.assertEquals(user2, conn2.whoami());
+    info = conn2.info();
+    Assert.assertEquals(instanceName, info.getInstanceName());
+    Assert.assertEquals(zookeepers, info.getZooKeepers());
+    Assert.assertEquals(user2, info.getPrincipal());
   }
 }

-- 
To stop receiving notification emails like this one, please contact
mwalch@apache.org.

Mime
View raw message