org.apache.hadoop.fs.permission.AclEntry#parseAclSpec ( )源码实例Demo

下面列出了org.apache.hadoop.fs.permission.AclEntry#parseAclSpec ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop   文件: TestAclCommands.java
@Test
public void testMultipleAclSpecParsing() throws Exception {
  List<AclEntry> parsedList = AclEntry.parseAclSpec(
      "group::rwx,user:user1:rwx,user:user2:rw-,"
          + "group:group1:rw-,default:group:group1:rw-", true);

  AclEntry basicAcl = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setPermission(FsAction.ALL).build();
  AclEntry user1Acl = new AclEntry.Builder().setType(AclEntryType.USER)
      .setPermission(FsAction.ALL).setName("user1").build();
  AclEntry user2Acl = new AclEntry.Builder().setType(AclEntryType.USER)
      .setPermission(FsAction.READ_WRITE).setName("user2").build();
  AclEntry group1Acl = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setPermission(FsAction.READ_WRITE).setName("group1").build();
  AclEntry defaultAcl = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setPermission(FsAction.READ_WRITE).setName("group1")
      .setScope(AclEntryScope.DEFAULT).build();
  List<AclEntry> expectedList = new ArrayList<AclEntry>();
  expectedList.add(basicAcl);
  expectedList.add(user1Acl);
  expectedList.add(user2Acl);
  expectedList.add(group1Acl);
  expectedList.add(defaultAcl);
  assertEquals("Parsed Acl not correct", expectedList, parsedList);
}
 
源代码2 项目: big-c   文件: TestAclCommands.java
@Test
public void testMultipleAclSpecParsing() throws Exception {
  List<AclEntry> parsedList = AclEntry.parseAclSpec(
      "group::rwx,user:user1:rwx,user:user2:rw-,"
          + "group:group1:rw-,default:group:group1:rw-", true);

  AclEntry basicAcl = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setPermission(FsAction.ALL).build();
  AclEntry user1Acl = new AclEntry.Builder().setType(AclEntryType.USER)
      .setPermission(FsAction.ALL).setName("user1").build();
  AclEntry user2Acl = new AclEntry.Builder().setType(AclEntryType.USER)
      .setPermission(FsAction.READ_WRITE).setName("user2").build();
  AclEntry group1Acl = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setPermission(FsAction.READ_WRITE).setName("group1").build();
  AclEntry defaultAcl = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setPermission(FsAction.READ_WRITE).setName("group1")
      .setScope(AclEntryScope.DEFAULT).build();
  List<AclEntry> expectedList = new ArrayList<AclEntry>();
  expectedList.add(basicAcl);
  expectedList.add(user1Acl);
  expectedList.add(user2Acl);
  expectedList.add(group1Acl);
  expectedList.add(defaultAcl);
  assertEquals("Parsed Acl not correct", expectedList, parsedList);
}
 
源代码3 项目: hadoop   文件: TestAclCommands.java
@Test
public void testSetfaclValidationsWithoutPermissions() throws Exception {
  List<AclEntry> parsedList = new ArrayList<AclEntry>();
  try {
    parsedList = AclEntry.parseAclSpec("user:user1:", true);
  } catch (IllegalArgumentException e) {
  }
  assertTrue(parsedList.size() == 0);
  assertFalse("setfacl should fail with less arguments",
      0 == runCommand(new String[] { "-setfacl", "-m", "user:user1:",
          "/path" }));
}
 
源代码4 项目: hadoop   文件: TestAclCommands.java
@Test
public void testMultipleAclSpecParsingWithoutPermissions() throws Exception {
  List<AclEntry> parsedList = AclEntry.parseAclSpec(
      "user::,user:user1:,group::,group:group1:,mask::,other::,"
          + "default:user:user1::,default:mask::", false);

  AclEntry owner = new AclEntry.Builder().setType(AclEntryType.USER).build();
  AclEntry namedUser = new AclEntry.Builder().setType(AclEntryType.USER)
      .setName("user1").build();
  AclEntry group = new AclEntry.Builder().setType(AclEntryType.GROUP).build();
  AclEntry namedGroup = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setName("group1").build();
  AclEntry mask = new AclEntry.Builder().setType(AclEntryType.MASK).build();
  AclEntry other = new AclEntry.Builder().setType(AclEntryType.OTHER).build();
  AclEntry defaultUser = new AclEntry.Builder()
      .setScope(AclEntryScope.DEFAULT).setType(AclEntryType.USER)
      .setName("user1").build();
  AclEntry defaultMask = new AclEntry.Builder()
      .setScope(AclEntryScope.DEFAULT).setType(AclEntryType.MASK).build();
  List<AclEntry> expectedList = new ArrayList<AclEntry>();
  expectedList.add(owner);
  expectedList.add(namedUser);
  expectedList.add(group);
  expectedList.add(namedGroup);
  expectedList.add(mask);
  expectedList.add(other);
  expectedList.add(defaultUser);
  expectedList.add(defaultMask);
  assertEquals("Parsed Acl not correct", expectedList, parsedList);
}
 
源代码5 项目: big-c   文件: TestAclCommands.java
@Test
public void testSetfaclValidationsWithoutPermissions() throws Exception {
  List<AclEntry> parsedList = new ArrayList<AclEntry>();
  try {
    parsedList = AclEntry.parseAclSpec("user:user1:", true);
  } catch (IllegalArgumentException e) {
  }
  assertTrue(parsedList.size() == 0);
  assertFalse("setfacl should fail with less arguments",
      0 == runCommand(new String[] { "-setfacl", "-m", "user:user1:",
          "/path" }));
}
 
源代码6 项目: big-c   文件: TestAclCommands.java
@Test
public void testMultipleAclSpecParsingWithoutPermissions() throws Exception {
  List<AclEntry> parsedList = AclEntry.parseAclSpec(
      "user::,user:user1:,group::,group:group1:,mask::,other::,"
          + "default:user:user1::,default:mask::", false);

  AclEntry owner = new AclEntry.Builder().setType(AclEntryType.USER).build();
  AclEntry namedUser = new AclEntry.Builder().setType(AclEntryType.USER)
      .setName("user1").build();
  AclEntry group = new AclEntry.Builder().setType(AclEntryType.GROUP).build();
  AclEntry namedGroup = new AclEntry.Builder().setType(AclEntryType.GROUP)
      .setName("group1").build();
  AclEntry mask = new AclEntry.Builder().setType(AclEntryType.MASK).build();
  AclEntry other = new AclEntry.Builder().setType(AclEntryType.OTHER).build();
  AclEntry defaultUser = new AclEntry.Builder()
      .setScope(AclEntryScope.DEFAULT).setType(AclEntryType.USER)
      .setName("user1").build();
  AclEntry defaultMask = new AclEntry.Builder()
      .setScope(AclEntryScope.DEFAULT).setType(AclEntryType.MASK).build();
  List<AclEntry> expectedList = new ArrayList<AclEntry>();
  expectedList.add(owner);
  expectedList.add(namedUser);
  expectedList.add(group);
  expectedList.add(namedGroup);
  expectedList.add(mask);
  expectedList.add(other);
  expectedList.add(defaultUser);
  expectedList.add(defaultMask);
  assertEquals("Parsed Acl not correct", expectedList, parsedList);
}
 
源代码7 项目: hadoop   文件: AclPermissionParam.java
public List<AclEntry> getAclPermission(boolean includePermission) {
  final String v = getValue();
  return (v != null ? AclEntry.parseAclSpec(v, includePermission) : AclEntry
      .parseAclSpec(DEFAULT, includePermission));
}
 
源代码8 项目: hadoop   文件: AclCommands.java
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
  cf.parse(args);
  setRecursive(cf.getOpt("R"));
  // Mix of remove and modify acl flags are not allowed
  boolean bothRemoveOptions = cf.getOpt("b") && cf.getOpt("k");
  boolean bothModifyOptions = cf.getOpt("m") && cf.getOpt("x");
  boolean oneRemoveOption = cf.getOpt("b") || cf.getOpt("k");
  boolean oneModifyOption = cf.getOpt("m") || cf.getOpt("x");
  boolean setOption = cf.getOpt("-set");
  if ((bothRemoveOptions || bothModifyOptions)
      || (oneRemoveOption && oneModifyOption)
      || (setOption && (oneRemoveOption || oneModifyOption))) {
    throw new HadoopIllegalArgumentException(
        "Specified flags contains both remove and modify flags");
  }

  // Only -m, -x and --set expects <acl_spec>
  if (oneModifyOption || setOption) {
    if (args.size() < 2) {
      throw new HadoopIllegalArgumentException("<acl_spec> is missing");
    }
    aclEntries = AclEntry.parseAclSpec(args.removeFirst(), !cf.getOpt("x"));
  }

  if (args.isEmpty()) {
    throw new HadoopIllegalArgumentException("<path> is missing");
  }
  if (args.size() > 1) {
    throw new HadoopIllegalArgumentException("Too many arguments");
  }

  // In recursive mode, save a separate list of just the access ACL entries.
  // Only directories may have a default ACL.  When a recursive operation
  // encounters a file under the specified path, it must pass only the
  // access ACL entries.
  if (isRecursive() && (oneModifyOption || setOption)) {
    accessAclEntries = Lists.newArrayList();
    for (AclEntry entry: aclEntries) {
      if (entry.getScope() == AclEntryScope.ACCESS) {
        accessAclEntries.add(entry);
      }
    }
  }
}
 
源代码9 项目: big-c   文件: AclPermissionParam.java
public List<AclEntry> getAclPermission(boolean includePermission) {
  final String v = getValue();
  return (v != null ? AclEntry.parseAclSpec(v, includePermission) : AclEntry
      .parseAclSpec(DEFAULT, includePermission));
}
 
源代码10 项目: big-c   文件: AclCommands.java
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
  cf.parse(args);
  setRecursive(cf.getOpt("R"));
  // Mix of remove and modify acl flags are not allowed
  boolean bothRemoveOptions = cf.getOpt("b") && cf.getOpt("k");
  boolean bothModifyOptions = cf.getOpt("m") && cf.getOpt("x");
  boolean oneRemoveOption = cf.getOpt("b") || cf.getOpt("k");
  boolean oneModifyOption = cf.getOpt("m") || cf.getOpt("x");
  boolean setOption = cf.getOpt("-set");
  if ((bothRemoveOptions || bothModifyOptions)
      || (oneRemoveOption && oneModifyOption)
      || (setOption && (oneRemoveOption || oneModifyOption))) {
    throw new HadoopIllegalArgumentException(
        "Specified flags contains both remove and modify flags");
  }

  // Only -m, -x and --set expects <acl_spec>
  if (oneModifyOption || setOption) {
    if (args.size() < 2) {
      throw new HadoopIllegalArgumentException("<acl_spec> is missing");
    }
    aclEntries = AclEntry.parseAclSpec(args.removeFirst(), !cf.getOpt("x"));
  }

  if (args.isEmpty()) {
    throw new HadoopIllegalArgumentException("<path> is missing");
  }
  if (args.size() > 1) {
    throw new HadoopIllegalArgumentException("Too many arguments");
  }

  // In recursive mode, save a separate list of just the access ACL entries.
  // Only directories may have a default ACL.  When a recursive operation
  // encounters a file under the specified path, it must pass only the
  // access ACL entries.
  if (isRecursive() && (oneModifyOption || setOption)) {
    accessAclEntries = Lists.newArrayList();
    for (AclEntry entry: aclEntries) {
      if (entry.getScope() == AclEntryScope.ACCESS) {
        accessAclEntries.add(entry);
      }
    }
  }
}
 
源代码11 项目: hadoop   文件: FSOperations.java
/**
 * Creates a set-acl executor.
 *
 * @param path path to set the acl.
 * @param aclSpec acl to set.
 */
public FSSetAcl(String path, String aclSpec) {
  this.path = new Path(path);
  this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
}
 
源代码12 项目: hadoop   文件: FSOperations.java
/**
 * Creates a modify-acl executor.
 *
 * @param path path to set the acl.
 * @param aclSpec acl to set.
 */
public FSModifyAclEntries(String path, String aclSpec) {
  this.path = new Path(path);
  this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
}
 
源代码13 项目: hadoop   文件: FSOperations.java
/**
 * Creates a remove acl entry executor.
 *
 * @param path path to set the acl.
 * @param aclSpec acl parts to remove.
 */
public FSRemoveAclEntries(String path, String aclSpec) {
  this.path = new Path(path);
  this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
}
 
源代码14 项目: big-c   文件: FSOperations.java
/**
 * Creates a set-acl executor.
 *
 * @param path path to set the acl.
 * @param aclSpec acl to set.
 */
public FSSetAcl(String path, String aclSpec) {
  this.path = new Path(path);
  this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
}
 
源代码15 项目: big-c   文件: FSOperations.java
/**
 * Creates a modify-acl executor.
 *
 * @param path path to set the acl.
 * @param aclSpec acl to set.
 */
public FSModifyAclEntries(String path, String aclSpec) {
  this.path = new Path(path);
  this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
}
 
源代码16 项目: big-c   文件: FSOperations.java
/**
 * Creates a remove acl entry executor.
 *
 * @param path path to set the acl.
 * @param aclSpec acl parts to remove.
 */
public FSRemoveAclEntries(String path, String aclSpec) {
  this.path = new Path(path);
  this.aclEntries = AclEntry.parseAclSpec(aclSpec, true);
}