kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: MINOR: Remove redundant clause in secureAclsEnabled check
Date Tue, 09 Aug 2016 02:45:15 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 91b4e3c00 -> da015585a


MINOR: Remove redundant clause in secureAclsEnabled check

Also include a few minor clean-ups.

Author: Ismael Juma <ismael@juma.me.uk>

Reviewers: Manikumar reddy O <manikumar.reddy@gmail.com>, Grant Henke <granthenke@gmail.com>,
Ewen Cheslack-Postava <ewen@confluent.io>

Closes #1623 from ijuma/fix-zk-inconsistent-security-check


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

Branch: refs/heads/trunk
Commit: da015585a94755d2e499e6fa4723cf1397404e7f
Parents: 91b4e3c
Author: Ismael Juma <ismael@juma.me.uk>
Authored: Mon Aug 8 19:46:08 2016 -0700
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Mon Aug 8 19:46:08 2016 -0700

----------------------------------------------------------------------
 .../apache/kafka/common/security/JaasUtils.java |  2 +-
 .../main/scala/kafka/server/KafkaServer.scala   | 26 ++++++++++----------
 2 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/da015585/clients/src/main/java/org/apache/kafka/common/security/JaasUtils.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/security/JaasUtils.java b/clients/src/main/java/org/apache/kafka/common/security/JaasUtils.java
index 63bbafc..c15d2e3 100644
--- a/clients/src/main/java/org/apache/kafka/common/security/JaasUtils.java
+++ b/clients/src/main/java/org/apache/kafka/common/security/JaasUtils.java
@@ -83,10 +83,10 @@ public class JaasUtils {
     }
 
     public static boolean isZkSecurityEnabled() {
-        boolean isSecurityEnabled = false;
         boolean zkSaslEnabled = Boolean.parseBoolean(System.getProperty(ZK_SASL_CLIENT, "true"));
         String zkLoginContextName = System.getProperty(ZK_LOGIN_CONTEXT_NAME_KEY, "Client");
 
+        boolean isSecurityEnabled;
         try {
             Configuration loginConf = Configuration.getConfiguration();
             isSecurityEnabled = loginConf.getAppConfigurationEntry(zkLoginContextName) !=
null;

http://git-wip-us.apache.org/repos/asf/kafka/blob/da015585/core/src/main/scala/kafka/server/KafkaServer.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/server/KafkaServer.scala b/core/src/main/scala/kafka/server/KafkaServer.scala
index 04a07f9..00b2a8a 100755
--- a/core/src/main/scala/kafka/server/KafkaServer.scala
+++ b/core/src/main/scala/kafka/server/KafkaServer.scala
@@ -271,28 +271,28 @@ class KafkaServer(val config: KafkaConfig, time: Time = SystemTime,
threadNamePr
   }
 
   private def initZk(): ZkUtils = {
-    info("Connecting to zookeeper on " + config.zkConnect)
+    info(s"Connecting to zookeeper on ${config.zkConnect}")
 
-    val chroot = {
-      if (config.zkConnect.indexOf("/") > 0)
-        config.zkConnect.substring(config.zkConnect.indexOf("/"))
-      else
-        ""
+    val chrootIndex = config.zkConnect.indexOf("/")
+    val chrootOption = {
+      if (chrootIndex > 0) Some(config.zkConnect.substring(chrootIndex))
+      else None
     }
 
-    val secureAclsEnabled = JaasUtils.isZkSecurityEnabled() && config.zkEnableSecureAcls
+    val secureAclsEnabled = config.zkEnableSecureAcls
+    val isZkSecurityEnabled = JaasUtils.isZkSecurityEnabled()
 
-    if(config.zkEnableSecureAcls && !secureAclsEnabled) {
-      throw new java.lang.SecurityException("zkEnableSecureAcls is true, but the verification
of the JAAS login file failed.")
-    }
-    if (chroot.length > 1) {
-      val zkConnForChrootCreation = config.zkConnect.substring(0, config.zkConnect.indexOf("/"))
+    if (secureAclsEnabled && !isZkSecurityEnabled)
+      throw new java.lang.SecurityException(s"${KafkaConfig.ZkEnableSecureAclsProp} is true,
but the verification of the JAAS login file failed.")
+
+    chrootOption.foreach { chroot =>
+      val zkConnForChrootCreation = config.zkConnect.substring(0, chrootIndex)
       val zkClientForChrootCreation = ZkUtils(zkConnForChrootCreation,
                                               config.zkSessionTimeoutMs,
                                               config.zkConnectionTimeoutMs,
                                               secureAclsEnabled)
       zkClientForChrootCreation.makeSurePersistentPathExists(chroot)
-      info("Created zookeeper path " + chroot)
+      info(s"Created zookeeper path $chroot")
       zkClientForChrootCreation.zkClient.close()
     }
 


Mime
View raw message