sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [sqoop] branch trunk updated: SQOOP-3423: Let user pass password to connect Hive when it set to LDAP authentication
Date Mon, 06 May 2019 13:48:55 GMT
This is an automated email from the ASF dual-hosted git repository.

bogi pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/sqoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new dfeb145  SQOOP-3423: Let user pass password to connect Hive when it set to LDAP authentication
dfeb145 is described below

commit dfeb14534ff0c57ebe27625aa9c79e37b4e12558
Author: Denes Bodo <bod.denes@gmail.com>
AuthorDate: Mon May 6 15:48:49 2019 +0200

    SQOOP-3423: Let user pass password to connect Hive when it set to LDAP authentication
    
    (Denes Bodo via Boglarka Egyed)
---
 src/docs/user/hive-args.txt                                  |  2 ++
 src/docs/user/hive.txt                                       |  2 +-
 src/java/org/apache/sqoop/SqoopOptions.java                  | 11 +++++++++++
 .../sqoop/hive/HiveServer2ConnectionFactoryInitializer.java  |  8 ++++++--
 src/java/org/apache/sqoop/tool/BaseSqoopTool.java            |  8 ++++++++
 .../hive/HiveServer2ConnectionFactoryInitializerTest.java    | 12 ++++++++++++
 6 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/src/docs/user/hive-args.txt b/src/docs/user/hive-args.txt
index 4edf338..14834da 100644
--- a/src/docs/user/hive-args.txt
+++ b/src/docs/user/hive-args.txt
@@ -47,6 +47,8 @@ Argument                      Description
 +\--hs2-url+                  The JDBC connection string to HiveServer2 as you would specify
in Beeline. If you use this option with \
                     --hive-import then Sqoop will try to connect to HiveServer2 instead of
using Hive CLI.
 +\--hs2-user+                 The user for creating the JDBC connection to HiveServer2. The
default is the current OS user.
++\--hs2-password+             The password for creating the JDBC connection to HiveServer2.
If not specified, kerberos\
+                              authentication will be used.
 +\--hs2-keytab+               The path to the keytab file of the user connecting to HiveServer2.
If you choose another \
                        HiveServer2 user (with --hs2-user) then --hs2-keytab has to be also
specified otherwise it can be omitted.
 +\--external-table-dir+       Used to specify that the table is external, not managed. \
diff --git a/src/docs/user/hive.txt b/src/docs/user/hive.txt
index 979e7af..59d9b00 100644
--- a/src/docs/user/hive.txt
+++ b/src/docs/user/hive.txt
@@ -48,7 +48,7 @@ Sqoop will use +$HIVE_HOME/bin/hive+ from here.
  will not be transferred via the JDBC connection it is written directly to HDFS
  just like in case of the default hive import. As HiveServer2 provides proper
  authorization and auditing features it is recommended to use this instead of
- the default. Currently only Kerberos authentication and text file format is
+ the default. Currently only Kerberos and LDAP authentication and text file format is
  supported with this option.
 
 NOTE: This function is incompatible with +\--as-avrodatafile+ and
diff --git a/src/java/org/apache/sqoop/SqoopOptions.java b/src/java/org/apache/sqoop/SqoopOptions.java
index 99eb8e6..a7c19da 100644
--- a/src/java/org/apache/sqoop/SqoopOptions.java
+++ b/src/java/org/apache/sqoop/SqoopOptions.java
@@ -467,6 +467,9 @@ public class SqoopOptions implements Cloneable {
   @StoredAsProperty("hs2.user")
   private String hs2User;
 
+  @StoredAsProperty("hs2.password")
+  private String hs2Password;
+
   @StoredAsProperty("hs2.keytab")
   private String hs2Keytab;
 
@@ -2975,10 +2978,18 @@ public class SqoopOptions implements Cloneable {
     return hs2User;
   }
 
+  public String getHs2Password() {
+    return hs2Password;
+  }
+
   public void setHs2User(String hs2User) {
     this.hs2User = hs2User;
   }
 
+  public void setHs2Password(String hs2Password) {
+    this.hs2Password = hs2Password;
+  }
+
   public String getHs2Keytab() {
     return hs2Keytab;
   }
diff --git a/src/java/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializer.java b/src/java/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializer.java
index 1d959f9..adb2559 100644
--- a/src/java/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializer.java
+++ b/src/java/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializer.java
@@ -34,8 +34,12 @@ public class HiveServer2ConnectionFactoryInitializer {
 
   public JdbcConnectionFactory createJdbcConnectionFactory(SqoopOptions sqoopOptions) {
     String connectionUsername = determineConnectionUsername(sqoopOptions);
-    JdbcConnectionFactory connectionFactory = new HiveServer2ConnectionFactory(sqoopOptions.getHs2Url(),
connectionUsername);
-    if (useKerberizedConnection(sqoopOptions)) {
+    String connectionPassword = sqoopOptions.getHs2Password();
+    JdbcConnectionFactory connectionFactory = new HiveServer2ConnectionFactory(
+            sqoopOptions.getHs2Url(),
+            connectionUsername,
+            connectionPassword);
+    if (connectionPassword == null && useKerberizedConnection(sqoopOptions)) {
       KerberosAuthenticator authenticator = createKerberosAuthenticator(sqoopOptions);
       connectionFactory = new KerberizedConnectionFactoryDecorator(connectionFactory, authenticator);
     }
diff --git a/src/java/org/apache/sqoop/tool/BaseSqoopTool.java b/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
index 955d3a6..96f06de 100644
--- a/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
+++ b/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
@@ -142,6 +142,7 @@ public abstract class BaseSqoopTool extends org.apache.sqoop.tool.SqoopTool
{
   public static final String HCATALOG_HOME_ARG = "hcatalog-home";
   public static final String HS2_URL_ARG = "hs2-url";
   public static final String HS2_USER_ARG = "hs2-user";
+  public static final String HS2_PASSWORD_ARG = "hs2-password";
   public static final String HS2_KEYTAB_ARG = "hs2-keytab";
   public static final String MAPREDUCE_JOB_NAME = "mapreduce-job-name";
   public static final String NUM_MAPPERS_ARG = "num-mappers";
@@ -637,6 +638,10 @@ public abstract class BaseSqoopTool extends org.apache.sqoop.tool.SqoopTool
{
         .withDescription("The user/principal for HiveServer2.")
         .withLongOpt(HS2_USER_ARG)
         .create());
+    hiveOpts.addOption(OptionBuilder.hasArg()
+        .withDescription("The LDAP password for HiveServer2.")
+        .withLongOpt(HS2_PASSWORD_ARG)
+        .create());
     hiveOpts.addOption(OptionBuilder
         .hasArg()
         .withDescription("The location of the keytab of the HiveServer2 user.")
@@ -1283,6 +1288,9 @@ public abstract class BaseSqoopTool extends org.apache.sqoop.tool.SqoopTool
{
    if (in.hasOption(HS2_USER_ARG)) {
       out.setHs2User(in.getOptionValue(HS2_USER_ARG));
    }
+    if (in.hasOption(HS2_PASSWORD_ARG)) {
+      out.setHs2Password(in.getOptionValue(HS2_PASSWORD_ARG));
+    }
    if (in.hasOption(HS2_KEYTAB_ARG)) {
       out.setHs2Keytab(in.getOptionValue(HS2_KEYTAB_ARG));
    }
diff --git a/src/test/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializerTest.java
b/src/test/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializerTest.java
index 544659d..d554c6d 100644
--- a/src/test/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializerTest.java
+++ b/src/test/org/apache/sqoop/hive/HiveServer2ConnectionFactoryInitializerTest.java
@@ -42,6 +42,8 @@ public class HiveServer2ConnectionFactoryInitializerTest {
 
   private static final String TEST_HS2_USER = "testuser";
 
+  private static final String TEST_HS2_PASSWORD = "testPass@123";
+
   private static final String TEST_HS2_KEYTAB = "testkeytab";
 
   private HiveServer2ConnectionFactoryInitializer connectionFactoryInitializer;
@@ -83,6 +85,7 @@ public class HiveServer2ConnectionFactoryInitializerTest {
     HiveServer2ConnectionFactory connectionFactory = (HiveServer2ConnectionFactory) connectionFactoryInitializer.createJdbcConnectionFactory(sqoopOptions);
 
     assertEquals(TEST_HS2_USER, connectionFactory.getUsername());
+    assertEquals(null, connectionFactory.getPassword());
   }
 
   @Test
@@ -117,4 +120,13 @@ public class HiveServer2ConnectionFactoryInitializerTest {
     softly.assertAll();
   }
 
+  @Test
+  public void testConnectionFactoryWhenHivePasswordIsProvided() {
+    when(sqoopOptions.getHs2Password()).thenReturn(TEST_HS2_PASSWORD);
+
+    HiveServer2ConnectionFactory connectionFactory = (HiveServer2ConnectionFactory) connectionFactoryInitializer.createJdbcConnectionFactory(sqoopOptions);
+
+    assertEquals(TEST_HS2_PASSWORD, connectionFactory.getPassword());
+  }
+
 }
\ No newline at end of file


Mime
View raw message