Search in sources :

Example 96 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.

the class GetAclCommand method exec.

@Override
public boolean exec() throws CliException {
    String path = args[1];
    Stat stat = new Stat();
    List<ACL> acl;
    try {
        acl = zk.getACL(path, stat);
    } catch (IllegalArgumentException ex) {
        throw new MalformedPathException(ex.getMessage());
    } catch (KeeperException | InterruptedException ex) {
        throw new CliWrapperException(ex);
    }
    for (ACL a : acl) {
        out.println(a.getId() + ": " + ZKUtil.getPermString(a.getPerms()));
    }
    if (cl.hasOption("s")) {
        new StatPrinter(out).print(stat);
    }
    return false;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ACL(org.apache.zookeeper.data.ACL) KeeperException(org.apache.zookeeper.KeeperException)

Example 97 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.

the class ClientTest method testNullAuthId.

@Test
public void testNullAuthId() throws Exception {
    ZooKeeper zk = null;
    try {
        zk = createClient();
        zk.addAuthInfo("digest", "ben:passwd".getBytes());
        ArrayList<ACL> testACL = new ArrayList<ACL>();
        testACL.add(new ACL(Perms.ALL, new Id("auth", null)));
        zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
        zk.close();
        zk = createClient();
        zk.addAuthInfo("digest", "ben:passwd2".getBytes());
        if (skipACL) {
            try {
                zk.getData("/acltest", false, null);
            } catch (KeeperException e) {
                fail("Badauth reads should succeed with skipACL.");
            }
        } else {
            try {
                zk.getData("/acltest", false, null);
                fail("Should have received a permission error");
            } catch (KeeperException e) {
                assertEquals(Code.NOAUTH, e.code());
            }
        }
        zk.addAuthInfo("digest", "ben:passwd".getBytes());
        zk.getData("/acltest", false, null);
        zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1);
        zk.close();
        zk = createClient();
        zk.getData("/acltest", false, null);
        List<ACL> acls = zk.getACL("/acltest", new Stat());
        assertEquals(1, acls.size());
        assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
    } finally {
        if (zk != null) {
            zk.close();
        }
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.jupiter.api.Test)

Example 98 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.

the class ACLCountTest method testAclCount.

/**
 * Create a node and add 4 ACL values to it, but there are only 2 unique ACL values,
 * and each is repeated once:
 *
 *   ACL(ZooDefs.Perms.READ,ZooDefs.Ids.ANYONE_ID_UNSAFE);
 *   ACL(ZooDefs.Perms.ALL,ZooDefs.Ids.AUTH_IDS);
 *   ACL(ZooDefs.Perms.READ,ZooDefs.Ids.ANYONE_ID_UNSAFE);
 *   ACL(ZooDefs.Perms.ALL,ZooDefs.Ids.AUTH_IDS);
 *
 * Even though we've added 4 ACL values, there should only be 2 ACLs for that node,
 * since there are only 2 *unique* ACL values.
 */
@Test
public void testAclCount() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    ZooKeeper zk;
    final ArrayList<ACL> CREATOR_ALL_AND_WORLD_READABLE = new ArrayList<ACL>() {

        {
            add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE));
            add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.AUTH_IDS));
            add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE));
            add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.AUTH_IDS));
        }
    };
    try {
        LOG.info("starting up the zookeeper server .. waiting");
        assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up");
        zk = ClientBase.createZKClient(HOSTPORT);
        zk.addAuthInfo("digest", "pat:test".getBytes());
        zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
        String path = "/path";
        try {
            assertEquals(4, CREATOR_ALL_AND_WORLD_READABLE.size());
        } catch (Exception e) {
            LOG.error("Something is fundamentally wrong with ArrayList's add() method. add()ing four times to an empty ArrayList should result in an ArrayList with 4 members.");
            throw e;
        }
        zk.create(path, path.getBytes(), CREATOR_ALL_AND_WORLD_READABLE, CreateMode.PERSISTENT);
        List<ACL> acls = zk.getACL("/path", new Stat());
        assertEquals(2, acls.size());
    } catch (Exception e) {
        // test failed somehow.
        assertTrue(false);
    }
    f.shutdown();
    zks.shutdown();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) ACL(org.apache.zookeeper.data.ACL) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Example 99 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.

the class ACLTest method testNullValueACL.

@Test
public void testNullValueACL() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        List<ACL> acls = new ArrayList<ACL>();
        acls.add(null);
        // case 1 : null value in ACL list with create
        try {
            zk.create("/foo", "foo".getBytes(), acls, CreateMode.PERSISTENT);
            fail("Expected InvalidACLException for null value in ACL List");
        } catch (InvalidACLException e) {
        // Expected. Do nothing
        }
        // case 2 : null value in ACL list with other create API
        try {
            zk.create("/foo", "foo".getBytes(), acls, CreateMode.PERSISTENT, null);
            fail("Expected InvalidACLException for null value in ACL List");
        } catch (InvalidACLException e) {
        // Expected. Do nothing
        }
        // case 3 : null value in ACL list with setACL
        try {
            zk.setACL("/foo", acls, -1);
            fail("Expected InvalidACLException for null value in ACL List");
        } catch (InvalidACLException e) {
        // Expected. Do nothing
        }
    } finally {
        zk.close();
        f.shutdown();
        zks.shutdown();
        assertTrue(ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT), "waiting for server down");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) ACL(org.apache.zookeeper.data.ACL) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) Test(org.junit.jupiter.api.Test)

Example 100 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.

the class ACLTest method testAcls.

/**
 * Verify that acl optimization of storing just
 * a few acls and there references in the data
 * node is actually working.
 */
@Test
public void testAcls() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(1000);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    ZooKeeper zk;
    String path;
    try {
        LOG.info("starting up the zookeeper server .. waiting");
        assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up");
        zk = ClientBase.createZKClient(HOSTPORT);
        LOG.info("starting creating acls");
        for (int i = 0; i < 100; i++) {
            path = "/" + i;
            zk.create(path, path.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
        int size = zks.getZKDatabase().getAclSize();
        assertTrue((2 == zks.getZKDatabase().getAclSize()), "size of the acl map ");
        for (int j = 100; j < 200; j++) {
            path = "/" + j;
            ACL acl = new ACL();
            acl.setPerms(0);
            Id id = new Id();
            id.setId("1.1.1." + j);
            id.setScheme("ip");
            acl.setId(id);
            List<ACL> list = new ArrayList<ACL>();
            list.add(acl);
            zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT);
        }
        assertTrue((102 == zks.getZKDatabase().getAclSize()), "size of the acl map ");
    } finally {
        // now shutdown the server and restart it
        f.shutdown();
        zks.shutdown();
        assertTrue(ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server down");
    }
    zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    try {
        assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server up");
        zk = ClientBase.createZKClient(HOSTPORT);
        assertTrue((102 == zks.getZKDatabase().getAclSize()), "acl map ");
        for (int j = 200; j < 205; j++) {
            path = "/" + j;
            ACL acl = new ACL();
            acl.setPerms(0);
            Id id = new Id();
            id.setId("1.1.1." + j);
            id.setScheme("ip");
            acl.setId(id);
            ArrayList<ACL> list = new ArrayList<ACL>();
            list.add(acl);
            zk.create(path, path.getBytes(), list, CreateMode.PERSISTENT);
        }
        assertTrue((107 == zks.getZKDatabase().getAclSize()), "acl map ");
        zk.close();
    } finally {
        f.shutdown();
        zks.shutdown();
        assertTrue(ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT), "waiting for server down");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Aggregations

ACL (org.apache.zookeeper.data.ACL)215 Id (org.apache.zookeeper.data.Id)85 ArrayList (java.util.ArrayList)61 Test (org.junit.Test)56 Stat (org.apache.zookeeper.data.Stat)45 KeeperException (org.apache.zookeeper.KeeperException)35 Test (org.testng.annotations.Test)32 CuratorFramework (org.apache.curator.framework.CuratorFramework)20 Test (org.junit.jupiter.api.Test)18 Configuration (org.apache.hadoop.conf.Configuration)17 ZooKeeper (org.apache.zookeeper.ZooKeeper)16 ACLProvider (org.apache.curator.framework.api.ACLProvider)15 List (java.util.List)11 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)8 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HashMap (java.util.HashMap)6 CreateMode (org.apache.zookeeper.CreateMode)6