You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2012/08/01 23:38:05 UTC

svn commit: r1368267 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/ClientCnxn.java src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java

Author: phunt
Date: Wed Aug  1 21:38:05 2012
New Revision: 1368267

URL: http://svn.apache.org/viewvc?rev=1368267&view=rev
Log:
ZOOKEEPER-1510. Should not log SASL errors for non-secure usage (Todd Lipcon via phunt)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1368267&r1=1368266&r2=1368267&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Wed Aug  1 21:38:05 2012
@@ -339,7 +339,10 @@ IMPROVEMENTS:
     installed in a non-standard directory (Michi Mutsuzaki via phunt)
 
   ZOOKEEPER-1503. remove redundant JAAS configuration code in SaslAuthTest and
-    SaslAuthFailTest ((Eugene Koontz via phunt)
+    SaslAuthFailTest (Eugene Koontz via phunt)
+
+  ZOOKEEPER-1510. Should not log SASL errors for non-secure usage
+    (Todd Lipcon via phunt)
 
 Release 3.4.0 - 
 

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java?rev=1368267&r1=1368266&r2=1368267&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java Wed Aug  1 21:38:05 2012
@@ -941,19 +941,23 @@ public class ClientCnxn {
                 addr = hostProvider.next(1000);
             }
 
-            LOG.info("Opening socket connection to server " + addr);
-
             setName(getName().replaceAll("\\(.*\\)",
                     "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
             try {
                 zooKeeperSaslClient = new ZooKeeperSaslClient("zookeeper/"+addr.getHostName());
             } catch (LoginException e) {
-                LOG.warn("SASL authentication failed: " + e + " Will continue connection to Zookeeper server without "
+                LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without "
                         + "SASL authentication, if Zookeeper server allows it.");
                 eventThread.queueEvent(new WatchedEvent(
                         Watcher.Event.EventType.None,
                         Watcher.Event.KeeperState.AuthFailed, null));
             }
+            String log = "Opening socket connection to server " + addr;
+            if (zooKeeperSaslClient != null) {
+              log += ". " + zooKeeperSaslClient.getConfigStatus();
+            }
+            LOG.info(log);
+
             clientCnxnSocket.connect(addr);
         }
 

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java?rev=1368267&r1=1368266&r2=1368267&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java Wed Aug  1 21:38:05 2012
@@ -67,6 +67,8 @@ public class ZooKeeperSaslClient {
 
     private SaslState saslState = SaslState.INITIAL;
 
+    private final String configStatus;
+
     public SaslState getSaslState() {
         return saslState;
     }
@@ -95,7 +97,7 @@ public class ZooKeeperSaslClient {
             securityException = e;
         }
         if (entries != null) {
-            LOG.info("Found Login Context section '" + clientSection + "': will use it to attempt to SASL-authenticate.");
+            this.configStatus = "Will attempt to SASL-authenticate using Login Context section '" + clientSection + "'";
             this.saslClient = createSaslClient(serverPrincipal, clientSection);
         } else {
             // Handle situation of clientSection's being null: it might simply because the client does not intend to 
@@ -119,12 +121,13 @@ public class ZooKeeperSaslClient {
             } else {
                 // The user did not override the default context. It might be that they just don't intend to use SASL,
                 // so log at INFO, not WARN, since they don't expect any SASL-related information.
+                String msg = "Will not attempt to authenticate using SASL ";
                 if (securityException != null) {
-                    LOG.warn("SecurityException: " + securityException + " occurred when trying to find JAAS configuration.");
+                    msg += "(" + securityException.getLocalizedMessage() + ")";
+                } else {
+                    msg += "(unknown error)";
                 }
-                LOG.info("Client will not SASL-authenticate because the default JAAS configuration section 'Client' " +
-                        "could not be found. If you are not using SASL, you may ignore this. On the other hand, " +
-                        "if you expected SASL to work, please fix your JAAS configuration.");
+                this.configStatus = msg;
             }
             if (System.getProperty("java.security.auth.login.config")  != null) {
                 // Again, the user explicitly set something SASL-related, so they probably expected SASL to succeed.
@@ -144,6 +147,10 @@ public class ZooKeeperSaslClient {
         }
     }
 
+    public String getConfigStatus() {
+        return configStatus;
+    }
+
     public boolean isComplete() {
         return (saslState == SaslState.COMPLETE);
     }