Java Code Examples for org.apache.zookeeper.KeeperException#AuthFailedException

The following examples show how to use org.apache.zookeeper.KeeperException#AuthFailedException . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KdcLocalClusterZookeeperIntegrationTest.java    From hadoop-mini-clusters with Apache License 2.0 5 votes vote down vote up
@Test
public void testZookeeper() throws Exception {

    try (CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperLocalCluster.getZookeeperConnectionString(),
            new ExponentialBackoffRetry(1000, 3))) {
        client.start();
        client.getChildren().forPath("/");
        fail();
    } catch (KeeperException.AuthFailedException e) {
        LOG.debug("Not authenticated!");
    }

    System.setProperty("zookeeper.sasl.client", "true");
    System.setProperty("zookeeper.sasl.clientconfig", "Client");
    javax.security.auth.login.Configuration.setConfiguration(new Jaas()
            .addEntry("Client", kdcLocalCluster.getKrbPrincipalWithRealm("guest"), kdcLocalCluster.getKeytabForPrincipal("guest")));

    try (CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperLocalCluster.getZookeeperConnectionString(),
            new ExponentialBackoffRetry(1000, 3))) {
        client.start();
        client.getChildren().forPath("/").forEach(LOG::debug);

        List<ACL> perms = new ArrayList<>();
        perms.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.AUTH_IDS));
        perms.add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE_ID_UNSAFE));

        client.create().withMode(CreateMode.PERSISTENT).withACL(perms).forPath(propertyParser.getProperty(ConfigVars.HBASE_ZNODE_PARENT_KEY));
    }
}
 
Example 2
Source File: TestActiveStandbyElector.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * verify that receiveActiveData gives data when active exists, tells that
 * active does not exist and reports error in getting active information
 * 
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 * @throws ActiveNotFoundException
 */
@Test
public void testGetActiveData() throws ActiveNotFoundException,
    KeeperException, InterruptedException, IOException {
  // get valid active data
  byte[] data = new byte[8];
  Mockito.when(
      mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
          Mockito.<Stat> anyObject())).thenReturn(data);
  Assert.assertEquals(data, elector.getActiveData());
  Mockito.verify(mockZK, Mockito.times(1)).getData(
      Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
      Mockito.<Stat> anyObject());

  // active does not exist
  Mockito.when(
      mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
          Mockito.<Stat> anyObject())).thenThrow(
      new KeeperException.NoNodeException());
  try {
    elector.getActiveData();
    Assert.fail("ActiveNotFoundException expected");
  } catch(ActiveNotFoundException e) {
    Mockito.verify(mockZK, Mockito.times(2)).getData(
        Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
        Mockito.<Stat> anyObject());
  }

  // error getting active data rethrows keeperexception
  try {
    Mockito.when(
        mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
            Mockito.<Stat> anyObject())).thenThrow(
        new KeeperException.AuthFailedException());
    elector.getActiveData();
    Assert.fail("KeeperException.AuthFailedException expected");
  } catch(KeeperException.AuthFailedException ke) {
    Mockito.verify(mockZK, Mockito.times(3)).getData(
        Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
        Mockito.<Stat> anyObject());
  }
}
 
Example 3
Source File: TestActiveStandbyElector.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * verify that receiveActiveData gives data when active exists, tells that
 * active does not exist and reports error in getting active information
 * 
 * @throws IOException
 * @throws InterruptedException
 * @throws KeeperException
 * @throws ActiveNotFoundException
 */
@Test
public void testGetActiveData() throws ActiveNotFoundException,
    KeeperException, InterruptedException, IOException {
  // get valid active data
  byte[] data = new byte[8];
  Mockito.when(
      mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
          Mockito.<Stat> anyObject())).thenReturn(data);
  Assert.assertEquals(data, elector.getActiveData());
  Mockito.verify(mockZK, Mockito.times(1)).getData(
      Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
      Mockito.<Stat> anyObject());

  // active does not exist
  Mockito.when(
      mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
          Mockito.<Stat> anyObject())).thenThrow(
      new KeeperException.NoNodeException());
  try {
    elector.getActiveData();
    Assert.fail("ActiveNotFoundException expected");
  } catch(ActiveNotFoundException e) {
    Mockito.verify(mockZK, Mockito.times(2)).getData(
        Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
        Mockito.<Stat> anyObject());
  }

  // error getting active data rethrows keeperexception
  try {
    Mockito.when(
        mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
            Mockito.<Stat> anyObject())).thenThrow(
        new KeeperException.AuthFailedException());
    elector.getActiveData();
    Assert.fail("KeeperException.AuthFailedException expected");
  } catch(KeeperException.AuthFailedException ke) {
    Mockito.verify(mockZK, Mockito.times(3)).getData(
        Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
        Mockito.<Stat> anyObject());
  }
}