hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jia...@apache.org
Subject hadoop git commit: YARN-6104. RegistrySecurity overrides zookeeper sasl system properties. Contributed by Billie Rinaldi
Date Thu, 19 Jan 2017 18:19:09 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 7e8d32147 -> efc8faa1b


YARN-6104. RegistrySecurity overrides zookeeper sasl system properties. Contributed by Billie
Rinaldi


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

Branch: refs/heads/trunk
Commit: efc8faa1bae79c17047e920beeb8af983db08e93
Parents: 7e8d321
Author: Jian He <jianhe@apache.org>
Authored: Thu Jan 19 10:18:59 2017 -0800
Committer: Jian He <jianhe@apache.org>
Committed: Thu Jan 19 10:18:59 2017 -0800

----------------------------------------------------------------------
 .../client/impl/zk/RegistrySecurity.java        | 11 ++++++++--
 .../registry/secure/TestSecureRegistry.java     | 22 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/efc8faa1/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java
index a3ec77a..bdb79be 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java
@@ -749,8 +749,15 @@ public class RegistrySecurity extends AbstractService {
       String context)  {
     RegistrySecurity.validateContext(context);
     enableZookeeperClientSASL();
-    System.setProperty(PROP_ZK_SASL_CLIENT_USERNAME, username);
-    System.setProperty(PROP_ZK_SASL_CLIENT_CONTEXT, context);
+    setSystemPropertyIfUnset(PROP_ZK_SASL_CLIENT_USERNAME, username);
+    setSystemPropertyIfUnset(PROP_ZK_SASL_CLIENT_CONTEXT, context);
+  }
+
+  private static void setSystemPropertyIfUnset(String name, String value) {
+    String existingValue = System.getProperty(name);
+    if (existingValue == null || existingValue.isEmpty()) {
+      System.setProperty(name, value);
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/efc8faa1/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
index 083f7f9..9d5848e 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
@@ -37,6 +37,8 @@ import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.LoginContext;
 
 import static org.apache.hadoop.registry.client.api.RegistryConstants.*;
+import static org.apache.hadoop.registry.client.impl.zk.ZookeeperConfigOptions.PROP_ZK_SASL_CLIENT_CONTEXT;
+import static org.apache.hadoop.registry.client.impl.zk.ZookeeperConfigOptions.PROP_ZK_SASL_CLIENT_USERNAME;
 
 /**
  * Verify that the Mini ZK service can be started up securely
@@ -138,6 +140,26 @@ public class TestSecureRegistry extends AbstractSecureRegistryTest {
     }
   }
 
+  @Test
+  public void testSystemPropertyOverwrite() {
+    System.setProperty(PROP_ZK_SASL_CLIENT_USERNAME, "");
+    System.setProperty(PROP_ZK_SASL_CLIENT_CONTEXT, "");
+    RegistrySecurity.setZKSaslClientProperties(ZOOKEEPER,
+        ZOOKEEPER_CLIENT_CONTEXT);
+    assertEquals(ZOOKEEPER, System.getProperty(PROP_ZK_SASL_CLIENT_USERNAME));
+    assertEquals(ZOOKEEPER_CLIENT_CONTEXT,
+        System.getProperty(PROP_ZK_SASL_CLIENT_CONTEXT));
+
+    String userName = "user1";
+    String context = "context1";
+    System.setProperty(PROP_ZK_SASL_CLIENT_USERNAME, userName);
+    System.setProperty(PROP_ZK_SASL_CLIENT_CONTEXT, context);
+    RegistrySecurity.setZKSaslClientProperties(ZOOKEEPER,
+        ZOOKEEPER_CLIENT_CONTEXT);
+    assertEquals(userName, System.getProperty(PROP_ZK_SASL_CLIENT_USERNAME));
+    assertEquals(context, System.getProperty(PROP_ZK_SASL_CLIENT_CONTEXT));
+  }
+
   /**
    * Start a curator service instance
    * @param name name


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message