Java Code Examples for org.apache.zookeeper.data.ACL#setId()

The following examples show how to use org.apache.zookeeper.data.ACL#setId() . 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: RegistrySecurity.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the IDs, adding a realm if needed, setting the permissions
 * @param principalList id string
 * @param realm realm to add
 * @param perms permissions
 * @return the relevant ACLs
 * @throws IOException
 */
public List<ACL> buildACLs(String principalList, String realm, int perms)
    throws IOException {
  List<String> aclPairs = splitAclPairs(principalList, realm);
  List<ACL> ids = new ArrayList<ACL>(aclPairs.size());
  for (String aclPair : aclPairs) {
    ACL newAcl = new ACL();
    newAcl.setId(parse(aclPair, realm));
    newAcl.setPerms(perms);
    ids.add(newAcl);
  }
  return ids;
}
 
Example 2
Source File: ZKUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Parse comma separated list of ACL entries to secure generated nodes, e.g.
 * <code>sasl:hdfs/[email protected]:cdrwa,sasl:hdfs/[email protected]:cdrwa</code>
 *
 * @return ACL list
 * @throws {@link BadAclFormatException} if an ACL is invalid
 */
public static List<ACL> parseACLs(String aclString) throws
    BadAclFormatException {
  List<ACL> acl = Lists.newArrayList();
  if (aclString == null) {
    return acl;
  }
  
  List<String> aclComps = Lists.newArrayList(
      Splitter.on(',').omitEmptyStrings().trimResults()
      .split(aclString));
  for (String a : aclComps) {
    // from ZooKeeperMain private method
    int firstColon = a.indexOf(':');
    int lastColon = a.lastIndexOf(':');
    if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) {
      throw new BadAclFormatException(
          "ACL '" + a + "' not of expected form scheme:id:perm");
    }

    ACL newAcl = new ACL();
    newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
        firstColon + 1, lastColon)));
    newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
    acl.add(newAcl);
  }
  
  return acl;
}
 
Example 3
Source File: RegistrySecurity.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the IDs, adding a realm if needed, setting the permissions
 * @param principalList id string
 * @param realm realm to add
 * @param perms permissions
 * @return the relevant ACLs
 * @throws IOException
 */
public List<ACL> buildACLs(String principalList, String realm, int perms)
    throws IOException {
  List<String> aclPairs = splitAclPairs(principalList, realm);
  List<ACL> ids = new ArrayList<ACL>(aclPairs.size());
  for (String aclPair : aclPairs) {
    ACL newAcl = new ACL();
    newAcl.setId(parse(aclPair, realm));
    newAcl.setPerms(perms);
    ids.add(newAcl);
  }
  return ids;
}
 
Example 4
Source File: ZKUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Parse comma separated list of ACL entries to secure generated nodes, e.g.
 * <code>sasl:hdfs/[email protected]:cdrwa,sasl:hdfs/[email protected]:cdrwa</code>
 *
 * @return ACL list
 * @throws {@link BadAclFormatException} if an ACL is invalid
 */
public static List<ACL> parseACLs(String aclString) throws
    BadAclFormatException {
  List<ACL> acl = Lists.newArrayList();
  if (aclString == null) {
    return acl;
  }
  
  List<String> aclComps = Lists.newArrayList(
      Splitter.on(',').omitEmptyStrings().trimResults()
      .split(aclString));
  for (String a : aclComps) {
    // from ZooKeeperMain private method
    int firstColon = a.indexOf(':');
    int lastColon = a.lastIndexOf(':');
    if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) {
      throw new BadAclFormatException(
          "ACL '" + a + "' not of expected form scheme:id:perm");
    }

    ACL newAcl = new ACL();
    newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
        firstColon + 1, lastColon)));
    newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
    acl.add(newAcl);
  }
  
  return acl;
}