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 7094b89..7bf906f 100644 --- a/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java +++ b/service/src/java/org/apache/hive/service/auth/CustomAuthenticationProviderImpl.java @@ -20,7 +20,8 @@ import javax.security.sasl.AuthenticationException; import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.util.ReflectionUtils; + +import java.lang.reflect.InvocationTargetException; public class CustomAuthenticationProviderImpl implements PasswdAuthenticationProvider { @@ -29,14 +30,28 @@ PasswdAuthenticationProvider customProvider; @SuppressWarnings("unchecked") - CustomAuthenticationProviderImpl () { - HiveConf conf = new HiveConf(); + CustomAuthenticationProviderImpl(HiveConf conf) throws AuthenticationException { this.customHandlerClass = (Class) conf.getClass( HiveConf.ConfVars.HIVE_SERVER2_CUSTOM_AUTHENTICATION_CLASS.varname, PasswdAuthenticationProvider.class); - this.customProvider = - ReflectionUtils.newInstance(this.customHandlerClass, conf); + // Try initializing the class with non-default and default constructors + try { + this.customProvider = customHandlerClass.getConstructor(HiveConf.class).newInstance(conf); + } catch (NoSuchMethodException e) { + try { + this.customProvider = customHandlerClass.getConstructor().newInstance(); + // in java6, these four extend directly from Exception. So have to handle separately. In java7, + // the common subclass is ReflectiveOperationException + } catch (NoSuchMethodException e1) { + throw new AuthenticationException("Can't instantiate custom authentication provider class. " + + "Either provide a constructor with HiveConf as argument or a default constructor.", e); + } catch (Exception e1) { + throw new AuthenticationException(e.getMessage(), e); + } + } catch (Exception e) { + throw new AuthenticationException(e.getMessage(), e); + } } @Override