Java Code Examples for org.apache.hadoop.fs.permission.AclEntry#parseAclSpec()

The following examples show how to use org.apache.hadoop.fs.permission.AclEntry#parseAclSpec() . 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: TestAclCommands.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: TestAclCommands.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: TestAclCommands.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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" }));
}
 
Example 4
Source File: TestAclCommands.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: TestAclCommands.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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" }));
}
 
Example 6
Source File: TestAclCommands.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: AclPermissionParam.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public List<AclEntry> getAclPermission(boolean includePermission) {
  final String v = getValue();
  return (v != null ? AclEntry.parseAclSpec(v, includePermission) : AclEntry
      .parseAclSpec(DEFAULT, includePermission));
}
 
Example 8
Source File: AclCommands.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@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);
      }
    }
  }
}
 
Example 9
Source File: AclPermissionParam.java    From big-c with Apache License 2.0 4 votes vote down vote up
public List<AclEntry> getAclPermission(boolean includePermission) {
  final String v = getValue();
  return (v != null ? AclEntry.parseAclSpec(v, includePermission) : AclEntry
      .parseAclSpec(DEFAULT, includePermission));
}
 
Example 10
Source File: AclCommands.java    From big-c with Apache License 2.0 4 votes vote down vote up
@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);
      }
    }
  }
}
 
Example 11
Source File: FSOperations.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: FSOperations.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: FSOperations.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: FSOperations.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: FSOperations.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: FSOperations.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}