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 4b95503eb19cf862fb6efa614c9746b477337158..89fcddf39654fdce4103ac4bdf73279fe8e4fa4b 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 3dc0aa86e2d4acc9604e27dabb8f683d4cd0705d..3ea8e6594cc38dab25da2efff245f2585b3538ee 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 @@ 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); + 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 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 1d4aba2cc37930d87b620815fb317c1977f6e901..9b0b14da52f7cfbf1a425ef4f5aae831453aa238 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 @@ private static List groupFilter; private String customQuery; - LdapAuthenticationProviderImpl() { - HiveConf conf = new HiveConf(); + LdapAuthenticationProviderImpl(HiveConf conf) { init(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 fd58081653af1a846394eddd513d94751e0129e2..437064b1ab7456aefe85f8d509ba55745a4d4009 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 e5cee37ac72001086323c94392274fb86f4307ef..832ebdfb8d7bc0dd5f4c3bbb50a7d04d023a9c30 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 5e91a0eb8a1bfc8a8d6e6774b195de9731035bdd..f2769064051182e6a90c06c697de73f6e7c12896 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);