curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject [1/3] curator git commit: CURATOR-228 - Modified the background callback to explicitly handle the NOAUTH case. This will now log a warning and set a flag indicating that an auth failure has occured.
Date Mon, 31 Aug 2015 23:14:46 GMT
Repository: curator
Updated Branches:
  refs/heads/master 38011678c -> 9d2d6851e


CURATOR-228 - Modified the background callback to explicitly handle the NOAUTH case. This
will now log a warning and set a flag indicating that an auth failure has occured.


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

Branch: refs/heads/master
Commit: ecf67df891d31b43acb45a65743c97976913b3ca
Parents: 870b4d5
Author: Cam McKenzie <cammckenzie@apache.org>
Authored: Thu Jul 23 13:38:37 2015 +1000
Committer: Cam McKenzie <cammckenzie@apache.org>
Committed: Thu Jul 23 13:38:37 2015 +1000

----------------------------------------------------------------------
 .../recipes/nodes/PersistentEphemeralNode.java  | 14 +++++++
 .../nodes/TestPersistentEphemeralNode.java      | 39 ++++++++++++++++++++
 2 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/ecf67df8/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
index f50dca4..35e18a5 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
@@ -41,6 +41,7 @@ import java.io.IOException;
 import java.util.Arrays;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.curator.utils.PathUtils;
@@ -65,6 +66,7 @@ public class PersistentEphemeralNode implements Closeable
     private final Mode mode;
     private final AtomicReference<byte[]> data = new AtomicReference<byte[]>();
     private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
+    private final AtomicBoolean authFailure = new AtomicBoolean(false);
     private final BackgroundCallback backgroundCallback;
     private final Watcher watcher = new Watcher()
     {
@@ -233,8 +235,15 @@ public class PersistentEphemeralNode implements Closeable
                 {
                     path = event.getName();
                 }
+                else if ( event.getResultCode() == KeeperException.Code.NOAUTH.intValue()
)
+                {
+                	log.warn("Client does not have authorisation to write ephemeral node at
path {}", path);
+                	authFailure.set(true);
+                	return;
+                }
                 if ( path != null )
                 {
+                	authFailure.set(false);
                     nodePath.set(path);
                     watchNode();
 
@@ -406,4 +415,9 @@ public class PersistentEphemeralNode implements Closeable
     {
         return (state.get() == State.STARTED);
     }
+    
+    public boolean isAuthFailure()
+    {
+    	return authFailure.get();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/ecf67df8/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
index 34620ff..b199872 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
@@ -35,7 +35,9 @@ import org.apache.curator.utils.ZKPaths;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.Watcher.Event.EventType;
+import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
@@ -572,6 +574,43 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
             node.close();
         }
     }
+    
+    @Test
+    public void testNoWritePermission() throws Exception
+    {
+        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
+        CuratorFramework client = builder
+            .connectString(server.getConnectString())
+            .authorization("digest", "me1:pass1".getBytes())
+            .retryPolicy(new RetryOneTime(1))
+            .build();
+        client.start();
+        
+        ACL acl = new ACL(ZooDefs.Perms.WRITE, ZooDefs.Ids.AUTH_IDS);
+        List<ACL> aclList = Lists.newArrayList(acl);
+        client.create().withACL(aclList).forPath(DIR, new byte[0]);
+        client.close();
+        
+        PersistentEphemeralNode node = null;
+        try {
+        	//New client without authentication
+        	client = newCurator();
+        
+        	node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL,
PATH,
+                                                                   new byte[0]);
+        	node.start();
+        
+            node.waitForInitialCreate(timing.seconds(), TimeUnit.SECONDS);
+            assertNodeDoesNotExist(client, PATH);
+            assertTrue(node.isAuthFailure());
+        } finally {
+        	if(node != null) {
+        	    node.close();
+        	}
+        	
+        	client.close();
+        }
+    }
 
     private void assertNodeExists(CuratorFramework curator, String path) throws Exception
     {


Mime
View raw message