You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by am...@apache.org on 2016/03/05 14:46:42 UTC

hive git commit: HIVE-13179 : Allow custom HiveConf to be passed to Authentication Providers (Rajat Khandelwal, reviewed by Amareshwari Sriramadasu

Repository: hive
Updated Branches:
  refs/heads/master 74facd79e -> 33005ac10


HIVE-13179 : Allow custom HiveConf to be passed to Authentication Providers (Rajat Khandelwal, reviewed by Amareshwari Sriramadasu


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/33005ac1
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/33005ac1
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/33005ac1

Branch: refs/heads/master
Commit: 33005ac100ff702afb020da6c3cc9f8134107c35
Parents: 74facd7
Author: Rajat Khandelwal <pr...@apache.org>
Authored: Sat Mar 5 19:15:09 2016 +0530
Committer: Amareshwari Sriramadasu <am...@apache.org>
Committed: Sat Mar 5 19:15:09 2016 +0530

----------------------------------------------------------------------
 .../service/auth/AuthenticationProviderFactory.java    | 12 +++++++++---
 .../service/auth/CustomAuthenticationProviderImpl.java | 13 ++++++++++---
 .../service/auth/LdapAuthenticationProviderImpl.java   |  3 +--
 .../service/auth/PamAuthenticationProviderImpl.java    |  3 +--
 .../service/auth/TestLdapAtnProviderWithMiniDS.java    |  2 +-
 .../auth/TestLdapAuthenticationProviderImpl.java       |  2 +-
 6 files changed, 23 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/33005ac1/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java b/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java
index 4b95503..89fcddf 100644
--- a/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java
+++ b/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java
@@ -19,6 +19,8 @@ package org.apache.hive.service.auth;
 
 import javax.security.sasl.AuthenticationException;
 
+import org.apache.hadoop.hive.conf.HiveConf;
+
 /**
  * This class helps select a {@link PasswdAuthenticationProvider} for a given {@code AuthMethod}.
  */
@@ -56,12 +58,16 @@ public final class AuthenticationProviderFactory {
 
   public static PasswdAuthenticationProvider getAuthenticationProvider(AuthMethods authMethod)
     throws AuthenticationException {
+    return getAuthenticationProvider(authMethod, new HiveConf());
+  }
+  public static PasswdAuthenticationProvider getAuthenticationProvider(AuthMethods authMethod, HiveConf conf)
+    throws AuthenticationException {
     if (authMethod == AuthMethods.LDAP) {
-      return new LdapAuthenticationProviderImpl();
+      return new LdapAuthenticationProviderImpl(conf);
     } else if (authMethod == AuthMethods.PAM) {
-      return new PamAuthenticationProviderImpl();
+      return new PamAuthenticationProviderImpl(conf);
     } else if (authMethod == AuthMethods.CUSTOM) {
-      return new CustomAuthenticationProviderImpl();
+      return new CustomAuthenticationProviderImpl(conf);
     } else if (authMethod == AuthMethods.NONE) {
       return new AnonymousAuthenticationProviderImpl();
     } else {

http://git-wip-us.apache.org/repos/asf/hive/blob/33005ac1/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java b/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java
index 3dc0aa8..3ea8e65 100644
--- a/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java
+++ b/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java
@@ -17,6 +17,8 @@
  */
 package org.apache.hive.service.auth;
 
+import java.lang.reflect.InvocationTargetException;
+
 import javax.security.sasl.AuthenticationException;
 
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -33,13 +35,18 @@ public class CustomAuthenticationProviderImpl implements PasswdAuthenticationPro
   private final PasswdAuthenticationProvider customProvider;
 
   @SuppressWarnings("unchecked")
-  CustomAuthenticationProviderImpl() {
-    HiveConf conf = new HiveConf();
+  CustomAuthenticationProviderImpl(HiveConf conf) {
     Class<? extends PasswdAuthenticationProvider> customHandlerClass =
       (Class<? extends PasswdAuthenticationProvider>) conf.getClass(
         HiveConf.ConfVars.HIVE_SERVER2_CUSTOM_AUTHENTICATION_CLASS.varname,
         PasswdAuthenticationProvider.class);
-    customProvider = ReflectionUtils.newInstance(customHandlerClass, conf);
+    PasswdAuthenticationProvider customProvider;
+    try {
+      customProvider = customHandlerClass.getConstructor(HiveConf.class).newInstance(conf);
+    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
+      customProvider = ReflectionUtils.newInstance(customHandlerClass, conf);
+    }
+    this.customProvider = customProvider;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hive/blob/33005ac1/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java b/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java
index 1d4aba2..9b0b14d 100644
--- a/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java
+++ b/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java
@@ -52,8 +52,7 @@ public class LdapAuthenticationProviderImpl implements PasswdAuthenticationProvi
   private static List<String> groupFilter;
   private String customQuery;
 
-  LdapAuthenticationProviderImpl() {
-    HiveConf conf = new HiveConf();
+  LdapAuthenticationProviderImpl(HiveConf conf) {
     init(conf);
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/33005ac1/service/src/java/org/apache/hive/service/auth/PamAuthenticationProviderImpl.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/auth/PamAuthenticationProviderImpl.java b/service/src/java/org/apache/hive/service/auth/PamAuthenticationProviderImpl.java
index fd58081..437064b 100644
--- a/service/src/java/org/apache/hive/service/auth/PamAuthenticationProviderImpl.java
+++ b/service/src/java/org/apache/hive/service/auth/PamAuthenticationProviderImpl.java
@@ -27,8 +27,7 @@ public class PamAuthenticationProviderImpl implements PasswdAuthenticationProvid
 
   private final String pamServiceNames;
 
-  PamAuthenticationProviderImpl() {
-    HiveConf conf = new HiveConf();
+  PamAuthenticationProviderImpl(HiveConf conf) {
     pamServiceNames = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PAM_SERVICES);
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/33005ac1/service/src/test/org/apache/hive/service/auth/TestLdapAtnProviderWithMiniDS.java
----------------------------------------------------------------------
diff --git a/service/src/test/org/apache/hive/service/auth/TestLdapAtnProviderWithMiniDS.java b/service/src/test/org/apache/hive/service/auth/TestLdapAtnProviderWithMiniDS.java
index e5cee37..832ebdf 100644
--- a/service/src/test/org/apache/hive/service/auth/TestLdapAtnProviderWithMiniDS.java
+++ b/service/src/test/org/apache/hive/service/auth/TestLdapAtnProviderWithMiniDS.java
@@ -172,7 +172,7 @@ public class TestLdapAtnProviderWithMiniDS extends AbstractLdapTestUnit {
   public static void init() throws Exception {
     hiveConf = new HiveConf();
 
-    ldapProvider = new LdapAuthenticationProviderImpl();
+    ldapProvider = new LdapAuthenticationProviderImpl(hiveConf);
     ldapProvider.init(hiveConf);
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/33005ac1/service/src/test/org/apache/hive/service/auth/TestLdapAuthenticationProviderImpl.java
----------------------------------------------------------------------
diff --git a/service/src/test/org/apache/hive/service/auth/TestLdapAuthenticationProviderImpl.java b/service/src/test/org/apache/hive/service/auth/TestLdapAuthenticationProviderImpl.java
index 5e91a0e..f276906 100644
--- a/service/src/test/org/apache/hive/service/auth/TestLdapAuthenticationProviderImpl.java
+++ b/service/src/test/org/apache/hive/service/auth/TestLdapAuthenticationProviderImpl.java
@@ -45,7 +45,7 @@ public class TestLdapAuthenticationProviderImpl extends TestCase {
   }
 
   public void testLdapEmptyPassword() {
-    LdapAuthenticationProviderImpl ldapImpl = new LdapAuthenticationProviderImpl();
+    LdapAuthenticationProviderImpl ldapImpl = new LdapAuthenticationProviderImpl(hiveConf);
     try {
       ldapImpl.Authenticate("user", "");
       assertFalse(true);