Java Code Examples for org.apache.zookeeper.ZooDefs.Ids#OPEN_ACL_UNSAFE

The following examples show how to use org.apache.zookeeper.ZooDefs.Ids#OPEN_ACL_UNSAFE . 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: ZookeeperUtil.java    From javabase with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @return
 */
public List<ACL> getCreateNodeAcls() {
    List<ACL> listAcls = new ArrayList<ACL>(3);
    try {
        Id id = new Id(PropertiesDynLoading.authScheme,
                DigestAuthenticationProvider.generateDigest(PropertiesDynLoading.accessKey));
        ACL acl = new ACL(Perms.CREATE, id);
        listAcls.add(acl);

    } catch (NoSuchAlgorithmException e) {

        e.printStackTrace();
        return Ids.OPEN_ACL_UNSAFE;
    }
    return listAcls;
}
 
Example 2
Source File: ZooKeeperStateProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(final StateProviderInitializationContext context) {
    connectionString = context.getProperty(CONNECTION_STRING).getValue();
    rootNode = context.getProperty(ROOT_NODE).getValue();
    timeoutMillis = context.getProperty(SESSION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();

    if (context.getProperty(ACCESS_CONTROL).getValue().equalsIgnoreCase(CREATOR_ONLY.getValue())) {
        acl = Ids.CREATOR_ALL_ACL;
    } else {
        acl = Ids.OPEN_ACL_UNSAFE;
    }
}
 
Example 3
Source File: TestActiveStandbyElectorRealZK.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  
  zkServer = getServer(serverFactory);

  for (int i = 0; i < NUM_ELECTORS; i++) {
    cbs[i] =  Mockito.mock(ActiveStandbyElectorCallback.class);
    appDatas[i] = Ints.toByteArray(i);
    electors[i] = new ActiveStandbyElector(hostPort, 5000, PARENT_DIR,
        Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), cbs[i],
        CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  }
}
 
Example 4
Source File: TestActiveStandbyElector.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws IOException, KeeperException {
  count = 0;
  mockZK = Mockito.mock(ZooKeeper.class);
  mockApp = Mockito.mock(ActiveStandbyElectorCallback.class);
  elector = new ActiveStandbyElectorTester("hostPort", 1000, ZK_PARENT_NAME,
      Ids.OPEN_ACL_UNSAFE, mockApp);
}
 
Example 5
Source File: TestActiveStandbyElector.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * verify the zookeeper connection establishment
 */
@Test
public void testWithoutZKServer() throws Exception {
  try {
    new ActiveStandbyElector("127.0.0.1", 2000, ZK_PARENT_NAME,
        Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), mockApp,
        CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
    Assert.fail("Did not throw zookeeper connection loss exceptions!");
  } catch (KeeperException ke) {
    GenericTestUtils.assertExceptionContains( "ConnectionLoss", ke);
  }
}
 
Example 6
Source File: ZookeeperUtil.java    From javabase with Apache License 2.0 5 votes vote down vote up
public List<ACL> getAdminAcls() {
    List<ACL> listAcls = new ArrayList<ACL>(3);
    try {
        Id id = new Id(PropertiesDynLoading.authScheme,
                DigestAuthenticationProvider.generateDigest(PropertiesDynLoading.accessKey));
        ACL acl = new ACL(Perms.ALL, id);
        listAcls.add(acl);

    } catch (NoSuchAlgorithmException e) {

        e.printStackTrace();
        return Ids.OPEN_ACL_UNSAFE;
    }
    return listAcls;
}
 
Example 7
Source File: TestActiveStandbyElectorRealZK.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  
  zkServer = getServer(serverFactory);

  for (int i = 0; i < NUM_ELECTORS; i++) {
    cbs[i] =  Mockito.mock(ActiveStandbyElectorCallback.class);
    appDatas[i] = Ints.toByteArray(i);
    electors[i] = new ActiveStandbyElector(hostPort, 5000, PARENT_DIR,
        Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), cbs[i],
        CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  }
}
 
Example 8
Source File: TestActiveStandbyElector.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws IOException, KeeperException {
  count = 0;
  mockZK = Mockito.mock(ZooKeeper.class);
  mockApp = Mockito.mock(ActiveStandbyElectorCallback.class);
  elector = new ActiveStandbyElectorTester("hostPort", 1000, ZK_PARENT_NAME,
      Ids.OPEN_ACL_UNSAFE, mockApp);
}
 
Example 9
Source File: TestActiveStandbyElector.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * verify the zookeeper connection establishment
 */
@Test
public void testWithoutZKServer() throws Exception {
  try {
    new ActiveStandbyElector("127.0.0.1", 2000, ZK_PARENT_NAME,
        Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), mockApp,
        CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
    Assert.fail("Did not throw zookeeper connection loss exceptions!");
  } catch (KeeperException ke) {
    GenericTestUtils.assertExceptionContains( "ConnectionLoss", ke);
  }
}
 
Example 10
Source File: ZooKeeperStateProvider.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(final StateProviderInitializationContext context) {
    connectionString = context.getProperty(CONNECTION_STRING).getValue();
    rootNode = context.getProperty(ROOT_NODE).getValue();
    timeoutMillis = context.getProperty(SESSION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();

    if (context.getProperty(ACCESS_CONTROL).getValue().equalsIgnoreCase(CREATOR_ONLY.getValue())) {
        acl = Ids.CREATOR_ALL_ACL;
    } else {
        acl = Ids.OPEN_ACL_UNSAFE;
    }
}
 
Example 11
Source File: ZKUtil.java    From hbase with Apache License 2.0 4 votes vote down vote up
public static ArrayList<ACL> createACL(ZKWatcher zkw, String node,
                                       boolean isSecureZooKeeper) {
  if (!node.startsWith(zkw.getZNodePaths().baseZNode)) {
    return Ids.OPEN_ACL_UNSAFE;
  }
  if (isSecureZooKeeper) {
    ArrayList<ACL> acls = new ArrayList<>();
    // add permission to hbase supper user
    String[] superUsers = zkw.getConfiguration().getStrings(Superusers.SUPERUSER_CONF_KEY);
    String hbaseUser = null;
    try {
      hbaseUser = UserGroupInformation.getCurrentUser().getShortUserName();
    } catch (IOException e) {
      LOG.debug("Could not acquire current User.", e);
    }
    if (superUsers != null) {
      List<String> groups = new ArrayList<>();
      for (String user : superUsers) {
        if (AuthUtil.isGroupPrincipal(user)) {
          // TODO: Set node ACL for groups when ZK supports this feature
          groups.add(user);
        } else {
          if(!user.equals(hbaseUser)) {
            acls.add(new ACL(Perms.ALL, new Id("sasl", user)));
          }
        }
      }
      if (!groups.isEmpty()) {
        LOG.warn("Znode ACL setting for group {} is skipped, ZooKeeper doesn't support this " +
          "feature presently.", groups);
      }
    }
    // Certain znodes are accessed directly by the client,
    // so they must be readable by non-authenticated clients
    if (zkw.getZNodePaths().isClientReadable(node)) {
      acls.addAll(Ids.CREATOR_ALL_ACL);
      acls.addAll(Ids.READ_ACL_UNSAFE);
    } else {
      acls.addAll(Ids.CREATOR_ALL_ACL);
    }
    return acls;
  } else {
    return Ids.OPEN_ACL_UNSAFE;
  }
}