org.apache.hadoop.fs.permission.AclStatus Java Examples

The following examples show how to use org.apache.hadoop.fs.permission.AclStatus. 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: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetPermissionOnlyAccess() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, READ_WRITE),
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  fs.setPermission(path, FsPermission.createImmutable((short)0600));
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ) }, returned);
  assertPermission((short)010600);
  assertAclFeature(true);
}
 
Example #2
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclEntriesStickyBit() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)01750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo"),
    aclEntry(DEFAULT, USER, "foo"));
  fs.removeAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, READ_EXECUTE),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)011750);
  assertAclFeature(true);
}
 
Example #3
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultAclNewDir() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  Path dirPath = new Path(path, "dir1");
  fs.mkdirs(dirPath);
  AclStatus s = fs.getAclStatus(dirPath);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission(dirPath, (short)010750);
  assertAclFeature(dirPath, true);
}
 
Example #4
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclEntriesMinimalDefault() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo"),
    aclEntry(ACCESS, MASK),
    aclEntry(DEFAULT, USER, "foo"),
    aclEntry(DEFAULT, MASK));
  fs.removeAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010750);
  assertAclFeature(true);
}
 
Example #5
Source File: TestAclWithSnapshot.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static void doSnapshotRootChangeAssertions(Path path,
    Path snapshotPath) throws Exception {
  AclStatus s = hdfs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "diana", READ_EXECUTE),
    aclEntry(ACCESS, GROUP, NONE) }, returned);
  assertPermission((short)010550, path);

  s = hdfs.getAclStatus(snapshotPath);
  returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "bruce", READ_EXECUTE),
    aclEntry(ACCESS, GROUP, NONE) }, returned);
  assertPermission((short)010750, snapshotPath);

  assertDirPermissionDenied(fsAsBruce, BRUCE, path);
  assertDirPermissionGranted(fsAsDiana, DIANA, path);
  assertDirPermissionGranted(fsAsBruce, BRUCE, snapshotPath);
  assertDirPermissionDenied(fsAsDiana, DIANA, snapshotPath);
}
 
Example #6
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveDefaultAclOnlyDefault() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.removeDefaultAcl(path);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] { }, returned);
  assertPermission((short)0750);
  assertAclFeature(false);
  // restart of the cluster
  restartCluster();
  s = fs.getAclStatus(path);
  AclEntry[] afterRestart = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(returned, afterRestart);
}
 
Example #7
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultAclRenamedDir() throws Exception {
  Path dirPath = new Path(path, "dir");
  FileSystem.mkdirs(fs, dirPath, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(dirPath, aclSpec);
  Path subdirPath = new Path(path, "subdir");
  FileSystem.mkdirs(fs, subdirPath, FsPermission.createImmutable((short)0750));
  Path renamedSubdirPath = new Path(dirPath, "subdir");
  fs.rename(subdirPath, renamedSubdirPath);
  AclEntry[] expected = new AclEntry[] { };
  AclStatus s = fs.getAclStatus(renamedSubdirPath);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(expected, returned);
  assertPermission(renamedSubdirPath, (short)0750);
  assertAclFeature(renamedSubdirPath, false);
}
 
Example #8
Source File: TestAclWithSnapshot.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static void doSnapshotRootChangeAssertions(Path path,
    Path snapshotPath) throws Exception {
  AclStatus s = hdfs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "diana", READ_EXECUTE),
    aclEntry(ACCESS, GROUP, NONE) }, returned);
  assertPermission((short)010550, path);

  s = hdfs.getAclStatus(snapshotPath);
  returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "bruce", READ_EXECUTE),
    aclEntry(ACCESS, GROUP, NONE) }, returned);
  assertPermission((short)010750, snapshotPath);

  assertDirPermissionDenied(fsAsBruce, BRUCE, path);
  assertDirPermissionGranted(fsAsDiana, DIANA, path);
  assertDirPermissionGranted(fsAsBruce, BRUCE, snapshotPath);
  assertDirPermissionDenied(fsAsDiana, DIANA, snapshotPath);
}
 
Example #9
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAclOnlyAccess() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, READ_WRITE),
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ) }, returned);
  assertPermission((short)010640);
  assertAclFeature(true);
}
 
Example #10
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetPermissionOnlyDefault() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.setPermission(path, FsPermission.createImmutable((short)0700));
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010700);
  assertAclFeature(true);
}
 
Example #11
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclStickyBit() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)01750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.removeAcl(path);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] { }, returned);
  assertPermission((short)01750);
  assertAclFeature(false);
}
 
Example #12
Source File: TestJsonUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testToJsonFromAclStatus() {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user:user1:rwx\",\"group::rw-\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.stickyBit(false);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER,"user1", ALL),
          aclEntry(ACCESS, GROUP, READ_WRITE));

  aclStatusBuilder.addEntries(aclSpec);
  Assert.assertEquals(jsonString,
      JsonUtil.toJsonString(aclStatusBuilder.build()));

}
 
Example #13
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAclEntriesOnlyAccess() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo", READ_EXECUTE));
  fs.modifyAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
    aclEntry(ACCESS, GROUP, READ_EXECUTE) }, returned);
  assertPermission((short)010750);
  assertAclFeature(true);
}
 
Example #14
Source File: FSOperations.java    From big-c with Apache License 2.0 6 votes vote down vote up
/** Converts an <code>AclStatus</code> object into a JSON object.
 *
 * @param aclStatus AclStatus object
 *
 * @return The JSON representation of the ACLs for the file
 */
@SuppressWarnings({"unchecked"})
private static Map<String,Object> aclStatusToJSON(AclStatus aclStatus) {
  Map<String,Object> json = new LinkedHashMap<String,Object>();
  Map<String,Object> inner = new LinkedHashMap<String,Object>();
  JSONArray entriesArray = new JSONArray();
  inner.put(HttpFSFileSystem.OWNER_JSON, aclStatus.getOwner());
  inner.put(HttpFSFileSystem.GROUP_JSON, aclStatus.getGroup());
  inner.put(HttpFSFileSystem.ACL_STICKY_BIT_JSON, aclStatus.isStickyBit());
  for ( AclEntry e : aclStatus.getEntries() ) {
    entriesArray.add(e.toString());
  }
  inner.put(HttpFSFileSystem.ACL_ENTRIES_JSON, entriesArray);
  json.put(HttpFSFileSystem.ACL_STATUS_JSON, inner);
  return json;
}
 
Example #15
Source File: TestAclWithSnapshot.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveReadsCurrentState() throws Exception {
  FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short)0700));

  SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);

  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "bruce", ALL));
  hdfs.modifyAclEntries(path, aclSpec);

  hdfs.removeAcl(path);

  AclEntry[] expected = new AclEntry[] { };
  AclStatus s = hdfs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(expected, returned);
  assertPermission((short)0700, path);
  assertDirPermissionDenied(fsAsBruce, BRUCE, path);
  assertDirPermissionDenied(fsAsDiana, DIANA, path);
}
 
Example #16
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultMinimalAclNewFile() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  Path filePath = new Path(path, "file1");
  fs.create(filePath).close();
  AclStatus s = fs.getAclStatus(filePath);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] { }, returned);
  assertPermission(filePath, (short)0640);
  assertAclFeature(filePath, false);
}
 
Example #17
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetPermission() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.setPermission(path, FsPermission.createImmutable((short)0700));
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010700);
  assertAclFeature(true);
}
 
Example #18
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAclCustomMask() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, READ_WRITE),
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ),
    aclEntry(ACCESS, MASK, ALL),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ) }, returned);
  assertPermission((short)010670);
  assertAclFeature(true);
}
 
Example #19
Source File: AclCommands.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void processPath(PathData item) throws IOException {
  out.println("# file: " + item);
  out.println("# owner: " + item.stat.getOwner());
  out.println("# group: " + item.stat.getGroup());
  FsPermission perm = item.stat.getPermission();
  if (perm.getStickyBit()) {
    out.println("# flags: --" +
      (perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T"));
  }

  AclStatus aclStatus = item.fs.getAclStatus(item.path);
  List<AclEntry> entries = perm.getAclBit() ? aclStatus.getEntries()
      : Collections.<AclEntry> emptyList();
  ScopedAclEntries scopedEntries = new ScopedAclEntries(
    AclUtil.getAclFromPermAndEntries(perm, entries));
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getAccessEntries());
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getDefaultEntries());
  out.println();
}
 
Example #20
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultAclNewDir() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  Path dirPath = new Path(path, "dir1");
  fs.mkdirs(dirPath);
  AclStatus s = fs.getAclStatus(dirPath);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission(dirPath, (short)010750);
  assertAclFeature(dirPath, true);
}
 
Example #21
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclEntries() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo"),
    aclEntry(DEFAULT, USER, "foo"));
  fs.removeAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, READ_EXECUTE),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010750);
  assertAclFeature(true);
}
 
Example #22
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclEntriesOnlyAccess() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, USER, "bar", READ_WRITE),
    aclEntry(ACCESS, GROUP, READ_WRITE),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo"));
  fs.removeAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "bar", READ_WRITE),
    aclEntry(ACCESS, GROUP, READ_WRITE) }, returned);
  assertPermission((short)010760);
  assertAclFeature(true);
}
 
Example #23
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultAclNewFileWithMode() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0755));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  Path filePath = new Path(path, "file1");
  int bufferSize = cluster.getConfiguration(0).getInt(
    CommonConfigurationKeys.IO_FILE_BUFFER_SIZE_KEY,
    CommonConfigurationKeys.IO_FILE_BUFFER_SIZE_DEFAULT);
  fs.create(filePath, new FsPermission((short)0740), false, bufferSize,
    fs.getDefaultReplication(filePath), fs.getDefaultBlockSize(path), null)
    .close();
  AclStatus s = fs.getAclStatus(filePath);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE) }, returned);
  assertPermission(filePath, (short)010740);
  assertAclFeature(filePath, true);
}
 
Example #24
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAclOnlyDefault() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010750);
  assertAclFeature(true);
}
 
Example #25
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclEntriesMinimalDefault() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo"),
    aclEntry(ACCESS, MASK),
    aclEntry(DEFAULT, USER, "foo"),
    aclEntry(DEFAULT, MASK));
  fs.removeAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010750);
  assertAclFeature(true);
}
 
Example #26
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAclOnlyAccess() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, READ_WRITE),
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", READ),
    aclEntry(ACCESS, GROUP, READ) }, returned);
  assertPermission((short)010640);
  assertAclFeature(true);
}
 
Example #27
Source File: TestJsonUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testToJsonFromAclStatus() {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user:user1:rwx\",\"group::rw-\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.stickyBit(false);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER,"user1", ALL),
          aclEntry(ACCESS, GROUP, READ_WRITE));

  aclStatusBuilder.addEntries(aclSpec);
  Assert.assertEquals(jsonString,
      JsonUtil.toJsonString(aclStatusBuilder.build()));

}
 
Example #28
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclOnlyDefault() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.removeAcl(path);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] { }, returned);
  assertPermission((short)0750);
  assertAclFeature(false);
}
 
Example #29
Source File: FSAclBaseTest.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAclStickyBit() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)01750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.removeAcl(path);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] { }, returned);
  assertPermission((short)01750);
  assertAclFeature(false);
}
 
Example #30
Source File: FSAclBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testModifyAclEntriesCustomMask() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, MASK, NONE));
  fs.modifyAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ) }, returned);
  assertPermission((short)010600);
  assertAclFeature(true);
}