Repository: storm
Updated Branches:
  refs/heads/1.x-branch 7fc342cbc -> f8887470b


Merge branch 'master' of https://github.com/dbahir/storm into STORM-1521


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/17da503f
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/17da503f
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/17da503f

Branch: refs/heads/1.x-branch
Commit: 17da503f49e09fbe309416a434cd7f394a7b5470
Parents: 7fc342c
Author: Parth Brahmbhatt <[email protected]>
Authored: Wed Feb 10 11:55:53 2016 -0800
Committer: Sriharsha Chintalapani <[email protected]>
Committed: Mon Feb 29 08:57:37 2016 -0800

----------------------------------------------------------------------
 .../storm/hbase/security/HBaseSecurityUtil.java | 36 ++++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/17da503f/external/storm-hbase/src/main/java/org/apache/storm/hbase/security/HBaseSecurityUtil.java
----------------------------------------------------------------------
diff --git 
a/external/storm-hbase/src/main/java/org/apache/storm/hbase/security/HBaseSecurityUtil.java
 
b/external/storm-hbase/src/main/java/org/apache/storm/hbase/security/HBaseSecurityUtil.java
index f306a51..e579015 100644
--- 
a/external/storm-hbase/src/main/java/org/apache/storm/hbase/security/HBaseSecurityUtil.java
+++ 
b/external/storm-hbase/src/main/java/org/apache/storm/hbase/security/HBaseSecurityUtil.java
@@ -39,26 +39,34 @@ public class HBaseSecurityUtil {
 
     public static final String STORM_KEYTAB_FILE_KEY = "storm.keytab.file";
     public static final String STORM_USER_NAME_KEY = 
"storm.kerberos.principal";
+    private static  UserProvider legacyProvider = null;
 
     public static UserProvider login(Map conf, Configuration hbaseConfig) 
throws IOException {
         //Allowing keytab based login for backward compatibility.
-        UserProvider provider = UserProvider.instantiate(hbaseConfig);
-        if (conf.get(TOPOLOGY_AUTO_CREDENTIALS) == null ||
-                !(((List) 
conf.get(TOPOLOGY_AUTO_CREDENTIALS)).contains(AutoHBase.class.getName()))) {
+        if (UserGroupInformation.isSecurityEnabled() && 
(conf.get(TOPOLOGY_AUTO_CREDENTIALS) == null ||
+                !(((List) 
conf.get(TOPOLOGY_AUTO_CREDENTIALS)).contains(AutoHBase.class.getName())))) {
             LOG.info("Logging in using keytab as AutoHBase is not specified 
for " + TOPOLOGY_AUTO_CREDENTIALS);
-            if (UserGroupInformation.isSecurityEnabled()) {
-                String keytab = (String) conf.get(STORM_KEYTAB_FILE_KEY);
-                if (keytab != null) {
-                    hbaseConfig.set(STORM_KEYTAB_FILE_KEY, keytab);
+            //insure that if keytab is used only one login per process executed
+            if(legacyProvider == null) {
+                synchronized (HBaseSecurityUtil.class) {
+                    if(legacyProvider == null) {
+                        legacyProvider = UserProvider.instantiate(hbaseConfig);
+                        String keytab = (String) 
conf.get(STORM_KEYTAB_FILE_KEY);
+                        if (keytab != null) {
+                            hbaseConfig.set(STORM_KEYTAB_FILE_KEY, keytab);
+                        }
+                        String userName = (String) 
conf.get(STORM_USER_NAME_KEY);
+                        if (userName != null) {
+                            hbaseConfig.set(STORM_USER_NAME_KEY, userName);
+                        }
+                        legacyProvider.login(STORM_KEYTAB_FILE_KEY, 
STORM_USER_NAME_KEY,
+                                
InetAddress.getLocalHost().getCanonicalHostName());
+                    }
                 }
-                String userName = (String) conf.get(STORM_USER_NAME_KEY);
-                if (userName != null) {
-                    hbaseConfig.set(STORM_USER_NAME_KEY, userName);
-                }
-                provider.login(STORM_KEYTAB_FILE_KEY, STORM_USER_NAME_KEY,
-                        InetAddress.getLocalHost().getCanonicalHostName());
             }
+            return legacyProvider;
+        } else {
+            return UserProvider.instantiate(hbaseConfig);
         }
-        return provider;
     }
 }

Reply via email to