Search in sources :

Example 46 with Id

use of org.apache.zookeeper.data.Id in project helios by spotify.

the class RuleBasedZooKeeperAclProviderTest method testNoMatchingRules.

@Test
public void testNoMatchingRules() {
    final Id id = new Id("some_scheme", "id");
    final RuleBasedZooKeeperAclProvider aclProvider = RuleBasedZooKeeperAclProvider.builder().rule("/foo/bar/baz", WRITE, id).build();
    assertNull(aclProvider.getAclForPath("/foo/bar"));
}
Also used : Id(org.apache.zookeeper.data.Id) Test(org.junit.Test)

Example 47 with Id

use of org.apache.zookeeper.data.Id in project helios by spotify.

the class RuleBasedZooKeeperAclProviderTest method testSimple.

@Test
public void testSimple() {
    final Id id1 = new Id("some_scheme", "id1");
    final Id id2 = new Id("some_scheme", "id2");
    final RuleBasedZooKeeperAclProvider aclProvider = RuleBasedZooKeeperAclProvider.builder().rule("/foo/baz", DELETE, id1).rule("/foo/bar", CREATE, id1).rule("/foo/qux", READ | WRITE, id2).build();
    assertThat(aclProvider.getAclForPath("/foo/baz"), contains(new ACL(DELETE, id1)));
    assertThat(aclProvider.getAclForPath("/foo/bar"), contains(new ACL(CREATE, id1)));
    assertThat(aclProvider.getAclForPath("/foo/qux"), contains(new ACL(READ | WRITE, id2)));
}
Also used : ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) Test(org.junit.Test)

Example 48 with Id

use of org.apache.zookeeper.data.Id in project incubator-atlas by apache.

the class SetupStepsTest method shouldDeleteSetupInProgressNodeAfterCompletion.

@Test
public void shouldDeleteSetupInProgressNodeAfterCompletion() throws Exception {
    Set<SetupStep> steps = new LinkedHashSet<>();
    SetupStep setupStep1 = mock(SetupStep.class);
    steps.add(setupStep1);
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("digest:user:pwd");
    List<ACL> aclList = Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("digest", "user:pwd")));
    setupServerIdSelectionMocks();
    DeleteBuilder deleteBuilder = setupSetupInProgressPathMocks(aclList).getRight();
    InterProcessMutex lock = mock(InterProcessMutex.class);
    when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(lock);
    SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
    setupSteps.runSetup();
    verify(deleteBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ACL(org.apache.zookeeper.data.ACL) SetupStep(org.apache.atlas.setup.SetupStep) Id(org.apache.zookeeper.data.Id) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) InterProcessMutex(org.apache.curator.framework.recipes.locks.InterProcessMutex) Test(org.testng.annotations.Test)

Example 49 with Id

use of org.apache.zookeeper.data.Id in project lucene-solr by apache.

the class SaslZkACLProvider method createNonSecurityACLsToAdd.

@Override
protected List<ACL> createNonSecurityACLsToAdd() {
    List<ACL> ret = new ArrayList<ACL>();
    ret.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", superUser)));
    ret.add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    return ret;
}
Also used : ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Example 50 with Id

use of org.apache.zookeeper.data.Id in project lucene-solr by apache.

the class TestZkConfigManager method testUploadWithACL.

@Test
public void testUploadWithACL() throws IOException {
    zkServer.ensurePathExists("/acl");
    final String readOnlyUsername = "readonly";
    final String readOnlyPassword = "readonly";
    final String writeableUsername = "writeable";
    final String writeablePassword = "writeable";
    ZkACLProvider aclProvider = new DefaultZkACLProvider() {

        @Override
        protected List<ACL> createGlobalACLsToAdd() {
            try {
                List<ACL> result = new ArrayList<>();
                result.add(new ACL(ZooDefs.Perms.ALL, new Id("digest", DigestAuthenticationProvider.generateDigest(writeableUsername + ":" + writeablePassword))));
                result.add(new ACL(ZooDefs.Perms.READ, new Id("digest", DigestAuthenticationProvider.generateDigest(readOnlyUsername + ":" + readOnlyPassword))));
                return result;
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException(e);
            }
        }
    };
    ZkCredentialsProvider readonly = new DefaultZkCredentialsProvider() {

        @Override
        protected Collection<ZkCredentials> createCredentials() {
            List<ZkCredentials> credentials = new ArrayList<>();
            credentials.add(new ZkCredentials("digest", (readOnlyUsername + ":" + readOnlyPassword).getBytes(StandardCharsets.UTF_8)));
            return credentials;
        }
    };
    ZkCredentialsProvider writeable = new DefaultZkCredentialsProvider() {

        @Override
        protected Collection<ZkCredentials> createCredentials() {
            List<ZkCredentials> credentials = new ArrayList<>();
            credentials.add(new ZkCredentials("digest", (writeableUsername + ":" + writeablePassword).getBytes(StandardCharsets.UTF_8)));
            return credentials;
        }
    };
    Path configPath = createTempDir("acl-config");
    Files.createFile(configPath.resolve("file1"));
    // Start with all-access client
    try (SolrZkClient client = buildZkClient(zkServer.getZkAddress("/acl"), aclProvider, writeable)) {
        ZkConfigManager configManager = new ZkConfigManager(client);
        configManager.uploadConfigDir(configPath, "acltest");
        assertEquals(1, configManager.listConfigs().size());
    }
    // Readonly access client can get the list of configs, but can't upload
    try (SolrZkClient client = buildZkClient(zkServer.getZkAddress("/acl"), aclProvider, readonly)) {
        ZkConfigManager configManager = new ZkConfigManager(client);
        assertEquals(1, configManager.listConfigs().size());
        configManager.uploadConfigDir(configPath, "acltest2");
        fail("Should have thrown an ACL exception");
    } catch (IOException e) {
        assertEquals(KeeperException.NoAuthException.class, Throwables.getRootCause(e).getClass());
    }
    // Client with no auth whatsoever can't even get the list of configs
    try (SolrZkClient client = new SolrZkClient(zkServer.getZkAddress("/acl"), 10000)) {
        ZkConfigManager configManager = new ZkConfigManager(client);
        configManager.listConfigs();
        fail("Should have thrown an ACL exception");
    } catch (IOException e) {
        assertEquals(KeeperException.NoAuthException.class, Throwables.getRootCause(e).getClass());
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) Id(org.apache.zookeeper.data.Id) Test(org.junit.Test)

Aggregations

Id (org.apache.zookeeper.data.Id)50 ACL (org.apache.zookeeper.data.ACL)39 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)18 KeeperException (org.apache.zookeeper.KeeperException)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)8 Stat (org.apache.zookeeper.data.Stat)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)4 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)4 ByteBuffer (java.nio.ByteBuffer)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Configuration (org.apache.hadoop.conf.Configuration)3 CreateRequest (org.apache.zookeeper.proto.CreateRequest)3 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 SetupStep (org.apache.atlas.setup.SetupStep)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 ACLProvider (org.apache.curator.framework.api.ACLProvider)2 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)2