Search in sources :

Example 21 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method testRemoveReadsCurrentState.

@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);
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) FSAclBaseTest(org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest) Test(org.junit.Test)

Example 22 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method doSnapshotContentsRemovalAssertions.

private static void doSnapshotContentsRemovalAssertions(Path filePath, Path fileSnapshotPath, Path subdirPath, Path subdirSnapshotPath) throws Exception {
    AclEntry[] expected = new AclEntry[] {};
    AclStatus s = hdfs.getAclStatus(filePath);
    AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 0500, filePath);
    assertFilePermissionDenied(fsAsBruce, BRUCE, filePath);
    assertFilePermissionDenied(fsAsDiana, DIANA, filePath);
    s = hdfs.getAclStatus(subdirPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 0500, subdirPath);
    assertDirPermissionDenied(fsAsBruce, BRUCE, subdirPath);
    assertDirPermissionDenied(fsAsDiana, DIANA, subdirPath);
    expected = new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE) };
    s = hdfs.getAclStatus(fileSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, fileSnapshotPath);
    assertFilePermissionGranted(fsAsBruce, BRUCE, fileSnapshotPath);
    assertFilePermissionDenied(fsAsDiana, DIANA, fileSnapshotPath);
    s = hdfs.getAclStatus(subdirSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, subdirSnapshotPath);
    assertDirPermissionGranted(fsAsBruce, BRUCE, subdirSnapshotPath);
    assertDirPermissionDenied(fsAsDiana, DIANA, subdirSnapshotPath);
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry)

Example 23 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestLs method resetMock.

@Before
public void resetMock() throws IOException {
    reset(mockFs);
    AclStatus mockAclStatus = mock(AclStatus.class);
    when(mockAclStatus.getEntries()).thenReturn(new ArrayList<AclEntry>());
    when(mockFs.getAclStatus(any(Path.class))).thenReturn(mockAclStatus);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Before(org.junit.Before)

Example 24 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestViewFileSystemDelegation method testAclMethods.

/**
   * Tests that ViewFileSystem dispatches calls for every ACL method through the
   * mount table to the correct underlying FileSystem with all Path arguments
   * translated as required.
   */
@Test
public void testAclMethods() throws Exception {
    Configuration conf = ViewFileSystemTestSetup.createConfig();
    FileSystem mockFs1 = setupMockFileSystem(conf, new URI("mockfs1:/"));
    FileSystem mockFs2 = setupMockFileSystem(conf, new URI("mockfs2:/"));
    FileSystem viewFs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
    Path viewFsPath1 = new Path("/mounts/mockfs1/a/b/c");
    Path mockFsPath1 = new Path("/a/b/c");
    Path viewFsPath2 = new Path("/mounts/mockfs2/d/e/f");
    Path mockFsPath2 = new Path("/d/e/f");
    List<AclEntry> entries = Collections.emptyList();
    viewFs.modifyAclEntries(viewFsPath1, entries);
    verify(mockFs1).modifyAclEntries(mockFsPath1, entries);
    viewFs.modifyAclEntries(viewFsPath2, entries);
    verify(mockFs2).modifyAclEntries(mockFsPath2, entries);
    viewFs.removeAclEntries(viewFsPath1, entries);
    verify(mockFs1).removeAclEntries(mockFsPath1, entries);
    viewFs.removeAclEntries(viewFsPath2, entries);
    verify(mockFs2).removeAclEntries(mockFsPath2, entries);
    viewFs.removeDefaultAcl(viewFsPath1);
    verify(mockFs1).removeDefaultAcl(mockFsPath1);
    viewFs.removeDefaultAcl(viewFsPath2);
    verify(mockFs2).removeDefaultAcl(mockFsPath2);
    viewFs.removeAcl(viewFsPath1);
    verify(mockFs1).removeAcl(mockFsPath1);
    viewFs.removeAcl(viewFsPath2);
    verify(mockFs2).removeAcl(mockFsPath2);
    viewFs.setAcl(viewFsPath1, entries);
    verify(mockFs1).setAcl(mockFsPath1, entries);
    viewFs.setAcl(viewFsPath2, entries);
    verify(mockFs2).setAcl(mockFsPath2, entries);
    viewFs.getAclStatus(viewFsPath1);
    verify(mockFs1).getAclStatus(mockFsPath1);
    viewFs.getAclStatus(viewFsPath2);
    verify(mockFs2).getAclStatus(mockFsPath2);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) MockFileSystem(org.apache.hadoop.fs.viewfs.TestChRootedFileSystem.MockFileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) AclEntry(org.apache.hadoop.fs.permission.AclEntry) URI(java.net.URI)

Example 25 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class OfflineImageReconstructor method aclXmlToProto.

private INodeSection.AclFeatureProto.Builder aclXmlToProto(Node acls) throws IOException {
    AclFeatureProto.Builder b = AclFeatureProto.newBuilder();
    while (true) {
        Node acl = acls.removeChild(INODE_SECTION_ACL);
        if (acl == null) {
            break;
        }
        String val = acl.getVal();
        AclEntry entry = AclEntry.parseAclEntry(val, true);
        int nameId = registerStringId(entry.getName() == null ? EMPTY_STRING : entry.getName());
        int v = ((nameId & ACL_ENTRY_NAME_MASK) << ACL_ENTRY_NAME_OFFSET) | (entry.getType().ordinal() << ACL_ENTRY_TYPE_OFFSET) | (entry.getScope().ordinal() << ACL_ENTRY_SCOPE_OFFSET) | (entry.getPermission().ordinal());
        b.addEntries(v);
    }
    return b;
}
Also used : AclFeatureProto(org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeSection.AclFeatureProto) AclEntry(org.apache.hadoop.fs.permission.AclEntry) ByteString(com.google.protobuf.ByteString)

Aggregations

AclEntry (org.apache.hadoop.fs.permission.AclEntry)136 Test (org.junit.Test)90 AclStatus (org.apache.hadoop.fs.permission.AclStatus)81 Path (org.apache.hadoop.fs.Path)52 FsPermission (org.apache.hadoop.fs.permission.FsPermission)24 ArrayList (java.util.ArrayList)11 FSAclBaseTest (org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest)11 FileSystem (org.apache.hadoop.fs.FileSystem)10 Configuration (org.apache.hadoop.conf.Configuration)7 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)5 FileStatus (org.apache.hadoop.fs.FileStatus)5 ScopedAclEntries (org.apache.hadoop.fs.permission.ScopedAclEntries)5 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)5 DatanodeInfoBuilder (org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder)5 List (java.util.List)4 AclEntryScope (org.apache.hadoop.fs.permission.AclEntryScope)4 AclEntryProto (org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto)4 IOException (java.io.IOException)3 URI (java.net.URI)3 AclEntryType (org.apache.hadoop.fs.permission.AclEntryType)3