From c5ffb781d45427f136741a386d5a29bfef44d2c4 Mon Sep 17 00:00:00 2001 From: Rajesh Balamohan Date: Thu, 16 Jan 2020 18:23:48 +0530 Subject: [PATCH] HIVE-22720: Optimise AuthenticationProviderFactory::getAuthenticationProvider (Rajesh Balamohan, reviewed by Ashutosh Chauhan, Gopal V) --- .../auth/AuthenticationProviderFactory.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 c684318986b0..e7cabc9a452e 100644 --- a/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java +++ b/service/src/java/org/apache/hive/service/auth/AuthenticationProviderFactory.java @@ -34,6 +34,8 @@ public enum AuthMethods { private final String authMethod; + private final HiveConf conf = new HiveConf(); + AuthMethods(String authMethod) { this.authMethod = authMethod; } @@ -42,6 +44,10 @@ public String getAuthMethod() { return authMethod; } + public HiveConf getConf() { + return conf; + } + public static AuthMethods getValidAuthMethod(String authMethodStr) throws AuthenticationException { for (AuthMethods auth : AuthMethods.values()) { @@ -58,16 +64,16 @@ private AuthenticationProviderFactory() { public static PasswdAuthenticationProvider getAuthenticationProvider(AuthMethods authMethod) throws AuthenticationException { - return getAuthenticationProvider(authMethod, new HiveConf()); + return getAuthenticationProvider(authMethod, null); } public static PasswdAuthenticationProvider getAuthenticationProvider(AuthMethods authMethod, HiveConf conf) throws AuthenticationException { if (authMethod == AuthMethods.LDAP) { - return new LdapAuthenticationProviderImpl(conf); + return new LdapAuthenticationProviderImpl((conf == null) ? AuthMethods.LDAP.getConf() : conf); } else if (authMethod == AuthMethods.PAM) { - return new PamAuthenticationProviderImpl(conf); + return new PamAuthenticationProviderImpl((conf == null) ? AuthMethods.PAM.getConf() : conf); } else if (authMethod == AuthMethods.CUSTOM) { - return new CustomAuthenticationProviderImpl(conf); + return new CustomAuthenticationProviderImpl((conf == null) ? AuthMethods.CUSTOM.getConf() : conf); } else if (authMethod == AuthMethods.NONE) { return new AnonymousAuthenticationProviderImpl(); } else {