Search in sources :

Example 21 with AclStatus

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

the class FSAclBaseTest method testUMaskDefaultAclNewFile.

@Test
public void testUMaskDefaultAclNewFile() throws Exception {
    FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short) 0750));
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(DEFAULT, GROUP, READ_WRITE), aclEntry(DEFAULT, USER, "foo", ALL));
    fs.setAcl(path, aclSpec);
    String oldUMask = fs.getConf().get(FS_PERMISSIONS_UMASK_KEY);
    fs.getConf().set(FS_PERMISSIONS_UMASK_KEY, "027");
    FSDirectory fsDirectory = cluster.getNamesystem().getFSDirectory();
    boolean oldEnabled = fsDirectory.isPosixAclInheritanceEnabled();
    try {
        fsDirectory.setPosixAclInheritanceEnabled(false);
        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[] { aclEntry(ACCESS, USER, "foo", ALL), aclEntry(ACCESS, GROUP, READ_WRITE) }, returned);
        assertPermission(filePath, (short) 010640);
        fsDirectory.setPosixAclInheritanceEnabled(true);
        Path file2Path = new Path(path, "file2");
        fs.create(file2Path).close();
        AclStatus s2 = fs.getAclStatus(file2Path);
        AclEntry[] returned2 = s2.getEntries().toArray(new AclEntry[0]);
        assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "foo", ALL), aclEntry(ACCESS, GROUP, READ_WRITE) }, returned2);
        assertPermission(file2Path, (short) 010660);
    } finally {
        fsDirectory.setPosixAclInheritanceEnabled(oldEnabled);
        fs.getConf().set(FS_PERMISSIONS_UMASK_KEY, oldUMask);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Example 22 with AclStatus

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

the class FSAclBaseTest method testRemoveDefaultAclMinimal.

@Test
public void testRemoveDefaultAclMinimal() throws Exception {
    FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short) 0750));
    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);
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Example 23 with AclStatus

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

the class FSAclBaseTest method testSetAclMinimalDefault.

@Test
public void testSetAclMinimalDefault() throws IOException {
    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);
    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);
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Example 24 with AclStatus

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

the class FSAclBaseTest method testDefaultMinimalAclNewDir.

@Test
public void testDefaultMinimalAclNewDir() 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 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(DEFAULT, USER, ALL), aclEntry(DEFAULT, GROUP, READ_EXECUTE), aclEntry(DEFAULT, OTHER, NONE) }, returned);
    assertPermission(dirPath, (short) 010750);
    assertAclFeature(dirPath, true);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Example 25 with AclStatus

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

the class FSAclBaseTest method testUMaskDefaultAclNewDir.

@Test
public void testUMaskDefaultAclNewDir() throws Exception {
    FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short) 0750));
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(DEFAULT, GROUP, ALL), aclEntry(DEFAULT, USER, "foo", ALL));
    fs.setAcl(path, aclSpec);
    String oldUMask = fs.getConf().get(FS_PERMISSIONS_UMASK_KEY);
    fs.getConf().set(FS_PERMISSIONS_UMASK_KEY, "027");
    FSDirectory fsDirectory = cluster.getNamesystem().getFSDirectory();
    boolean oldEnabled = fsDirectory.isPosixAclInheritanceEnabled();
    try {
        fsDirectory.setPosixAclInheritanceEnabled(false);
        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, ALL), aclEntry(DEFAULT, USER, ALL), aclEntry(DEFAULT, USER, "foo", ALL), aclEntry(DEFAULT, GROUP, ALL), aclEntry(DEFAULT, MASK, ALL), aclEntry(DEFAULT, OTHER, NONE) }, returned);
        assertPermission(dirPath, (short) 010750);
        fsDirectory.setPosixAclInheritanceEnabled(true);
        Path dir2Path = new Path(path, "dir2");
        fs.mkdirs(dir2Path);
        AclStatus s2 = fs.getAclStatus(dir2Path);
        AclEntry[] returned2 = s2.getEntries().toArray(new AclEntry[0]);
        assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "foo", ALL), aclEntry(ACCESS, GROUP, ALL), aclEntry(DEFAULT, USER, ALL), aclEntry(DEFAULT, USER, "foo", ALL), aclEntry(DEFAULT, GROUP, ALL), aclEntry(DEFAULT, MASK, ALL), aclEntry(DEFAULT, OTHER, NONE) }, returned2);
        assertPermission(dir2Path, (short) 010770);
    } finally {
        fsDirectory.setPosixAclInheritanceEnabled(oldEnabled);
        fs.getConf().set(FS_PERMISSIONS_UMASK_KEY, oldUMask);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) Test(org.junit.Test)

Aggregations

AclStatus (org.apache.hadoop.fs.permission.AclStatus)91 AclEntry (org.apache.hadoop.fs.permission.AclEntry)81 Test (org.junit.Test)73 Path (org.apache.hadoop.fs.Path)38 FsPermission (org.apache.hadoop.fs.permission.FsPermission)12 FSAclBaseTest (org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest)10 FileSystem (org.apache.hadoop.fs.FileSystem)5 Configuration (org.apache.hadoop.conf.Configuration)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)3 DatanodeInfoBuilder (org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Builder (org.apache.hadoop.fs.ContentSummary.Builder)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 Message (com.google.protobuf.Message)1