log authorisation error when writing node with PersistentData

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

Branch: refs/heads/CURATOR-3.0
Commit: 08102b0f09f1b1ac79699d121bca8076853f4e44
Parents: caf6406
Author: szekizoli <szekiz...@gmail.com>
Authored: Mon Mar 6 13:56:37 2017 +0800
Committer: szekizoli <szekiz...@gmail.com>
Committed: Mon Mar 6 13:56:37 2017 +0800

----------------------------------------------------------------------
 .../framework/recipes/nodes/PersistentNode.java |  7 ++-
 .../nodes/TestPersistentEphemeralNode.java      | 52 +++++++++++++++++++-
 2 files changed, 56 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/08102b0f/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java
 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java
index 1f655ed..18ecf81 100644
--- 
a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java
+++ 
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java
@@ -117,6 +117,9 @@ public class PersistentNode implements Closeable
             {
                 //Update is ok, mark initialisation as complete if required.
                 initialisationComplete();
+            } else if ( event.getResultCode() == 
KeeperException.Code.NOAUTH.intValue() ) {
+                log.warn("Client does not have authorisation to write node at 
path {}", event.getPath());
+                authFailure.set(true);
             }
         }
     };
@@ -213,7 +216,7 @@ public class PersistentNode implements Closeable
         }
         else if ( event.getResultCode() == 
KeeperException.Code.NOAUTH.intValue() )
         {
-            log.warn("Client does not have authorisation to write node at path 
{}", event.getPath());
+            log.warn("Client does not have authorisation to create node at 
path {}", event.getPath());
             authFailure.set(true);
             return;
         }
@@ -323,7 +326,7 @@ public class PersistentNode implements Closeable
         this.data.set(Arrays.copyOf(data, data.length));
         if ( isActive() )
         {
-            client.setData().inBackground().forPath(getActualPath(), 
getData());
+            
client.setData().inBackground(setDataCallback).forPath(getActualPath(), 
getData());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/08102b0f/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 f451feb..ef8a45a 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
@@ -22,6 +22,7 @@ import com.google.common.base.Throwables;
 import com.google.common.collect.Lists;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.ACLProvider;
 import org.apache.curator.framework.api.BackgroundCallback;
 import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.framework.state.ConnectionState;
@@ -45,6 +46,7 @@ import org.testng.annotations.Test;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Semaphore;
@@ -692,7 +694,7 @@ public class TestPersistentEphemeralNode extends 
BaseClassForTests
     }
     
     @Test
-    public void testNoWritePermission() throws Exception
+    public void testNoCreatePermission() throws Exception
     {
         CuratorFrameworkFactory.Builder builder = 
CuratorFrameworkFactory.builder();
         CuratorFramework client = builder
@@ -728,6 +730,54 @@ public class TestPersistentEphemeralNode extends 
BaseClassForTests
         }
     }
 
+    @Test
+    public void testNoWritePermission() throws Exception
+    {
+        final ACLProvider aclProvider = new ACLProvider() {
+            final ACL acl = new ACL(ZooDefs.Perms.READ | ZooDefs.Perms.CREATE 
| ZooDefs.Perms.DELETE, ZooDefs.Ids.ANYONE_ID_UNSAFE);
+            final List<ACL> aclList = Collections.singletonList(acl);
+            @Override
+            public List<ACL> getDefaultAcl() {
+                return aclList;
+            }
+
+            @Override
+            public List<ACL> getAclForPath(String path) {
+                return aclList;
+            }
+        };
+
+        CuratorFrameworkFactory.Builder builder = 
CuratorFrameworkFactory.builder();
+        CuratorFramework client = builder
+                .connectString(server.getConnectString())
+                .aclProvider(aclProvider)
+                .retryPolicy(new RetryOneTime(1))
+                .build();
+
+        PersistentEphemeralNode node = null;
+        try {
+            client.start();
+
+            node = new PersistentEphemeralNode(client, 
PersistentEphemeralNode.Mode.EPHEMERAL, PATH,
+                    new byte[0]);
+            node.start();
+
+            assertTrue(node.waitForInitialCreate(timing.seconds(), 
TimeUnit.SECONDS), "Node not created");
+            assertNodeExists(client, PATH);
+            assertFalse(node.isAuthFailure(), "AuthFailure when creating 
node.");
+
+            byte[] NEW_DATA = "NEW_DATA".getBytes();
+            node.setData(NEW_DATA);
+            timing.sleepABit();
+            byte[] read_data = client.getData().forPath(PATH);
+            assertNotEquals(read_data, NEW_DATA, "Data matches - write went 
through.");
+            assertTrue(node.isAuthFailure(), "AuthFailure response not 
received.");
+        } finally {
+            CloseableUtils.closeQuietly(node);
+            CloseableUtils.closeQuietly(client);
+        }
+    }
+
     private void assertNodeExists(CuratorFramework curator, String path) 
throws Exception
     {
         assertNotNull(path);

Reply via email to