Search in sources :

Example 86 with ACL

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

the class LearnerTest method syncTest.

@Test
public void syncTest() throws Exception {
    File tmpFile = File.createTempFile("test", ".dir", testData);
    tmpFile.delete();
    try {
        FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
        SimpleLearner sl = new SimpleLearner(ftsl);
        long startZxid = sl.zk.getLastProcessedZxid();
        // Set up bogus streams
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
        sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
        // make streams and socket do something innocuous
        sl.bufferedOutput = new BufferedOutputStream(System.out);
        sl.sock = new Socket();
        // fake messages from the server
        QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
        oa.writeRecord(qp, null);
        sl.zk.getZKDatabase().serializeSnapshot(oa);
        oa.writeString("BenWasHere", "signature");
        TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
        CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
        ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
        hdr.serialize(boa, "hdr");
        txn.serialize(boa, "txn");
        tbaos.close();
        qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
        oa.writeRecord(qp, null);
        // setup the messages to be streamed to follower
        sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
        try {
            sl.syncWithLeader(3);
        } catch (EOFException e) {
        }
        sl.zk.shutdown();
        sl = new SimpleLearner(ftsl);
        assertEquals(startZxid, sl.zk.getLastProcessedZxid());
    } finally {
        TestUtils.deleteFileRecursively(tmpFile);
    }
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) ACL(org.apache.zookeeper.data.ACL) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) CreateTxn(org.apache.zookeeper.txn.CreateTxn) ByteArrayInputStream(java.io.ByteArrayInputStream) EOFException(java.io.EOFException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) TxnHeader(org.apache.zookeeper.txn.TxnHeader) Test(org.junit.jupiter.api.Test)

Example 87 with ACL

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

the class KeyAuthClientTest method createNodePrintAcl.

public void createNodePrintAcl(ZooKeeper zk, String path, String testName) {
    try {
        LOG.debug("KeyAuthenticationProvider Creating Test Node:{}\n", path);
        zk.create(path, null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
        List<ACL> acls = zk.getACL(path, null);
        LOG.debug("Node:{} Test:{} ACLs:", path, testName);
        for (ACL acl : acls) {
            LOG.debug("  {}", acl.toString());
        }
    } catch (Exception e) {
        LOG.debug("  EXCEPTION THROWN", e);
    }
}
Also used : ACL(org.apache.zookeeper.data.ACL) KeeperException(org.apache.zookeeper.KeeperException)

Example 88 with ACL

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

the class MultiOperationTest method testMultiGetChildrenAuthentication.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiGetChildrenAuthentication(boolean useAsync) throws KeeperException, InterruptedException {
    List<ACL> writeOnly = Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, new Id("world", "anyone")));
    zk.create("/foo_auth", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_auth/bar", null, Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_no_auth", null, writeOnly, CreateMode.PERSISTENT);
    // Check for normal behaviour.
    List<OpResult> multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_auth")), useAsync);
    assertEquals(multiChildrenList.size(), 1);
    assertTrue(multiChildrenList.get(0) instanceof OpResult.GetChildrenResult);
    List<String> childrenList = ((OpResult.GetChildrenResult) multiChildrenList.get(0)).getChildren();
    assertEquals(childrenList.size(), 1);
    assertEquals(childrenList.get(0), "bar");
    // Check for authentication violation.
    multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_no_auth")), useAsync);
    assertEquals(multiChildrenList.size(), 1);
    assertTrue(multiChildrenList.get(0) instanceof OpResult.ErrorResult);
    assertEquals(((OpResult.ErrorResult) multiChildrenList.get(0)).getErr(), KeeperException.Code.NOAUTH.intValue(), "Expected NoAuthException for getting the children of a write only node");
}
Also used : OpResult(org.apache.zookeeper.OpResult) ErrorResult(org.apache.zookeeper.OpResult.ErrorResult) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with ACL

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

the class MultiOperationTest method testMultiGetChildrenMixedAuthenticationCorrectFirst.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiGetChildrenMixedAuthenticationCorrectFirst(boolean useAsync) throws KeeperException, InterruptedException {
    List<ACL> writeOnly = Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, new Id("world", "anyone")));
    zk.create("/foo_auth", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_auth/bar", null, Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_no_auth", null, writeOnly, CreateMode.PERSISTENT);
    // Check for getting the children of the nodes with mixed authentication.
    // The getChildren operation returns GetChildrenResult if it happened before the error.
    List<OpResult> multiChildrenList;
    multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_auth"), Op.getChildren("/foo_no_auth")), useAsync);
    assertSame(multiChildrenList.size(), 2);
    assertTrue(multiChildrenList.get(0) instanceof OpResult.GetChildrenResult);
    List<String> childrenList = ((OpResult.GetChildrenResult) multiChildrenList.get(0)).getChildren();
    assertEquals(childrenList.size(), 1);
    assertEquals(childrenList.get(0), "bar");
    assertTrue(multiChildrenList.get(1) instanceof OpResult.ErrorResult);
    assertEquals(((OpResult.ErrorResult) multiChildrenList.get(1)).getErr(), KeeperException.Code.NOAUTH.intValue(), "Expected NoAuthException for getting the children of a write only node");
}
Also used : OpResult(org.apache.zookeeper.OpResult) ErrorResult(org.apache.zookeeper.OpResult.ErrorResult) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with ACL

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

the class FinalRequestProcessorTest method testACLDigestHashHiding_OnlyAdmin.

@Test
public void testACLDigestHashHiding_OnlyAdmin() {
    // Arrange
    testACLs.clear();
    testACLs.addAll(Arrays.asList(new ACL(ZooDefs.Perms.READ, new Id("digest", "user:secrethash")), new ACL(ZooDefs.Perms.ADMIN, new Id("digest", "adminuser:adminsecret"))));
    List<Id> authInfo = new ArrayList<Id>();
    authInfo.add(new Id("digest", "adminuser:adminsecret"));
    // Act
    Request r = new Request(cnxn, 0, 0, ZooDefs.OpCode.getACL, bb, authInfo);
    processor.processRequest(r);
    // Assert
    assertTrue(responseRecord[0] instanceof GetACLResponse, "Not a GetACL response. Auth failed?");
    GetACLResponse rsp = (GetACLResponse) responseRecord[0];
    assertThat("Number of ACLs in the response are different", rsp.getAcl().size(), equalTo(2));
    // Verify ACLs in the response
    assertThat("Password hash mismatch in the response", rsp.getAcl().get(0).getId().getId(), equalTo("user:secrethash"));
    assertThat("Password hash mismatch in the response", rsp.getAcl().get(1).getId().getId(), equalTo("adminuser:adminsecret"));
}
Also used : ArrayList(java.util.ArrayList) GetACLRequest(org.apache.zookeeper.proto.GetACLRequest) ACL(org.apache.zookeeper.data.ACL) GetACLResponse(org.apache.zookeeper.proto.GetACLResponse) Id(org.apache.zookeeper.data.Id) 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