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;
}
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();
}
}
}
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();
}
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");
}
}
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");
}
}
Aggregations