cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [3/6] git commit: Support authentication in CqlRecordReader
Date Wed, 14 May 2014 22:37:07 GMT
Support authentication in CqlRecordReader

Patch by Jacek Lewandowski, reviewed by Alex Liu for CASSANDRA-7221


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/569177fb
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/569177fb
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/569177fb

Branch: refs/heads/trunk
Commit: 569177fb9e7c2b7935ff2e7f8b7c0b10806b8f50
Parents: b927f79
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Wed May 14 17:35:38 2014 -0500
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Wed May 14 17:35:38 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/hadoop/cql3/CqlConfigHelper.java  | 32 ++++++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/569177fb/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9a43040..285efd1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.9
+ * (Hadoop) support authentication in CqlRecordReader (CASSANDRA-7221)
  * (Hadoop) Close java driver Cluster in CQLRR.close (CASSANDRA-7228)
  * Fix potential SlabAllocator yield-starvation (CASSANDRA-7133)
  * Warn when 'USING TIMESTAMP' is used on a CAS BATCH (CASSANDRA-7067)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/569177fb/src/java/org/apache/cassandra/hadoop/cql3/CqlConfigHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/CqlConfigHelper.java b/src/java/org/apache/cassandra/hadoop/cql3/CqlConfigHelper.java
index a4a9c44..a2cf1e7 100644
--- a/src/java/org/apache/cassandra/hadoop/cql3/CqlConfigHelper.java
+++ b/src/java/org/apache/cassandra/hadoop/cql3/CqlConfigHelper.java
@@ -40,9 +40,11 @@ import javax.net.ssl.TrustManagerFactory;
 
 import org.apache.cassandra.hadoop.ConfigHelper;
 import org.apache.cassandra.io.util.FileUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 
 import com.datastax.driver.core.AuthProvider;
+import com.datastax.driver.core.PlainTextAuthProvider;
 import com.datastax.driver.core.Cluster;
 import com.datastax.driver.core.Host;
 import com.datastax.driver.core.HostDistance;
@@ -64,6 +66,9 @@ public class CqlConfigHelper
     private static final String INPUT_CQL_WHERE_CLAUSE_CONFIG = "cassandra.input.where.clause";
     private static final String INPUT_CQL = "cassandra.input.cql";
 
+    private static final String USERNAME = "cassandra.username";
+    private static final String PASSWORD = "cassandra.password";
+
     private static final String INPUT_NATIVE_PORT = "cassandra.input.native.port";
     private static final String INPUT_NATIVE_CORE_CONNECTIONS_PER_HOST = "cassandra.input.native.core.connections.per.host";
     private static final String INPUT_NATIVE_MAX_CONNECTIONS_PER_HOST = "cassandra.input.native.max.connections.per.host";
@@ -152,6 +157,16 @@ public class CqlConfigHelper
         conf.set(INPUT_CQL, cql);
     }
 
+    public static void setUserNameAndPassword(Configuration conf, String username, String
password)
+    {
+        if (StringUtils.isNotBlank(username))
+        {
+            conf.set(INPUT_NATIVE_AUTH_PROVIDER, PlainTextAuthProvider.class.getName());
+            conf.set(USERNAME, username);
+            conf.set(PASSWORD, password);
+        }
+    }
+
     public static Optional<Integer> getInputCoreConnections(Configuration conf)
     {
         return getIntSetting(INPUT_NATIVE_CORE_CONNECTIONS_PER_HOST, conf);
@@ -547,7 +562,7 @@ public class CqlConfigHelper
         if (!authProvider.isPresent())
             return Optional.absent();
 
-        return Optional.of(getClientAuthProvider(authProvider.get()));  
+        return Optional.of(getClientAuthProvider(authProvider.get(), conf));
     }
 
     private static Optional<SSLOptions> getSSLOptions(Configuration conf)
@@ -602,11 +617,22 @@ public class CqlConfigHelper
         return Optional.of(setting);  
     }
 
-    private static AuthProvider getClientAuthProvider(String factoryClassName)
+    private static AuthProvider getClientAuthProvider(String factoryClassName, Configuration
conf)
     {
         try
         {
-            return (AuthProvider) Class.forName(factoryClassName).newInstance();
+            Class<?> c = Class.forName(factoryClassName);
+            if (PlainTextAuthProvider.class.equals(c))
+            {
+                String username = getStringSetting(USERNAME, conf).or("");
+                String password = getStringSetting(PASSWORD, conf).or("");
+                return (AuthProvider) c.getConstructor(String.class, String.class)
+                        .newInstance(username, password);
+            }
+            else
+            {
+                return (AuthProvider) c.newInstance();
+            }
         }
         catch (Exception e)
         {


Mime
View raw message