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 @@ 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 @@ private 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 { 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..c52153d 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,16 @@ private final PasswdAuthenticationProvider customProvider; @SuppressWarnings("unchecked") - CustomAuthenticationProviderImpl() { - HiveConf conf = new HiveConf(); + CustomAuthenticationProviderImpl(HiveConf conf) { Class customHandlerClass = (Class) conf.getClass( HiveConf.ConfVars.HIVE_SERVER2_CUSTOM_AUTHENTICATION_CLASS.varname, PasswdAuthenticationProvider.class); - customProvider = ReflectionUtils.newInstance(customHandlerClass, conf); + try { + customProvider = customHandlerClass.getConstructor(HiveConf.class).newInstance(conf); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { + customProvider = ReflectionUtils.newInstance(customHandlerClass, conf); + } } @Override 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..ef8864f 100644 --- a/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java +++ b/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java @@ -52,9 +52,7 @@ private static List groupFilter; private String customQuery; - LdapAuthenticationProviderImpl() { - HiveConf conf = new HiveConf(); - init(conf); + LdapAuthenticationProviderImpl(HiveConf conf) { } protected void init(HiveConf conf) { 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 @@ private final String pamServiceNames; - PamAuthenticationProviderImpl() { - HiveConf conf = new HiveConf(); + PamAuthenticationProviderImpl(HiveConf conf) { pamServiceNames = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PAM_SERVICES); } 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 void shutdown() throws Exception { public static void init() throws Exception { hiveConf = new HiveConf(); - ldapProvider = new LdapAuthenticationProviderImpl(); + ldapProvider = new LdapAuthenticationProviderImpl(hiveConf); ldapProvider.init(hiveConf); } 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 void setUp() throws Exception { } public void testLdapEmptyPassword() { - LdapAuthenticationProviderImpl ldapImpl = new LdapAuthenticationProviderImpl(); + LdapAuthenticationProviderImpl ldapImpl = new LdapAuthenticationProviderImpl(hiveConf); try { ldapImpl.Authenticate("user", ""); assertFalse(true);