Search in sources :

Example 6 with FsAction

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

the class FSDownload method checkPermissionOfOther.

/**
   * Checks for a given path whether the Other permissions on it 
   * imply the permission in the passed FsAction
   * @param fs
   * @param path
   * @param action
   * @return true if the path in the uri is visible to all, false otherwise
   * @throws IOException
   */
private static boolean checkPermissionOfOther(FileSystem fs, Path path, FsAction action, LoadingCache<Path, Future<FileStatus>> statCache) throws IOException {
    FileStatus status = getFileStatus(fs, path, statCache);
    FsPermission perms = status.getPermission();
    FsAction otherAction = perms.getOtherAction();
    return otherAction.implies(action);
}
Also used : FsAction(org.apache.hadoop.fs.permission.FsAction) FileStatus(org.apache.hadoop.fs.FileStatus) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Example 7 with FsAction

use of org.apache.hadoop.fs.permission.FsAction in project hive by apache.

the class FileUtils method isActionPermittedForFileHierarchy.

public static boolean isActionPermittedForFileHierarchy(FileSystem fs, FileStatus fileStatus, String userName, FsAction action, boolean recurse) throws Exception {
    boolean isDir = fileStatus.isDir();
    FsAction dirActionNeeded = action;
    if (isDir) {
        // for dirs user needs execute privileges as well
        dirActionNeeded.and(FsAction.EXECUTE);
    }
    try {
        checkFileAccessWithImpersonation(fs, fileStatus, action, userName);
    } catch (AccessControlException err) {
        // Action not permitted for user
        return false;
    }
    if ((!isDir) || (!recurse)) {
        // no sub dirs to be checked
        return true;
    }
    // check all children
    FileStatus[] childStatuses = fs.listStatus(fileStatus.getPath());
    for (FileStatus childStatus : childStatuses) {
        // check children recursively - recurse is true if we're here.
        if (!isActionPermittedForFileHierarchy(fs, childStatus, userName, action, true)) {
            return false;
        }
    }
    return true;
}
Also used : FsAction(org.apache.hadoop.fs.permission.FsAction) FileStatus(org.apache.hadoop.fs.FileStatus) AccessControlException(java.security.AccessControlException)

Example 8 with FsAction

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

the class TestFsPermission method testFsAction.

public void testFsAction() {
    //implies
    for (FsAction a : FsAction.values()) {
        assertTrue(ALL.implies(a));
    }
    for (FsAction a : FsAction.values()) {
        assertTrue(a == NONE ? NONE.implies(a) : !NONE.implies(a));
    }
    for (FsAction a : FsAction.values()) {
        assertTrue(a == READ_EXECUTE || a == READ || a == EXECUTE || a == NONE ? READ_EXECUTE.implies(a) : !READ_EXECUTE.implies(a));
    }
    //masks
    assertEquals(EXECUTE, EXECUTE.and(READ_EXECUTE));
    assertEquals(READ, READ.and(READ_EXECUTE));
    assertEquals(NONE, WRITE.and(READ_EXECUTE));
    assertEquals(READ, READ_EXECUTE.and(READ_WRITE));
    assertEquals(NONE, READ_EXECUTE.and(WRITE));
    assertEquals(WRITE_EXECUTE, ALL.and(WRITE_EXECUTE));
}
Also used : FsAction(org.apache.hadoop.fs.permission.FsAction)

Example 9 with FsAction

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

the class TestFsPermission method testSpecialBitsToString.

public void testSpecialBitsToString() {
    for (boolean sb : new boolean[] { false, true }) {
        for (FsAction u : FsAction.values()) {
            for (FsAction g : FsAction.values()) {
                for (FsAction o : FsAction.values()) {
                    FsPermission f = new FsPermission(u, g, o, sb);
                    String fString = f.toString();
                    // Check that sticky bit is represented correctly.
                    if (f.getStickyBit() && f.getOtherAction().implies(EXECUTE))
                        assertEquals('t', fString.charAt(8));
                    else if (f.getStickyBit() && !f.getOtherAction().implies(EXECUTE))
                        assertEquals('T', fString.charAt(8));
                    else if (!f.getStickyBit() && f.getOtherAction().implies(EXECUTE))
                        assertEquals('x', fString.charAt(8));
                    else
                        assertEquals('-', fString.charAt(8));
                    assertEquals(9, fString.length());
                }
            }
        }
    }
}
Also used : FsAction(org.apache.hadoop.fs.permission.FsAction)

Example 10 with FsAction

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

the class FTPFileSystem method getPermissions.

private FsPermission getPermissions(FTPFile ftpFile) {
    FsAction user, group, others;
    user = getFsAction(FTPFile.USER_ACCESS, ftpFile);
    group = getFsAction(FTPFile.GROUP_ACCESS, ftpFile);
    others = getFsAction(FTPFile.WORLD_ACCESS, ftpFile);
    return new FsPermission(user, group, others);
}
Also used : FsAction(org.apache.hadoop.fs.permission.FsAction) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Aggregations

FsAction (org.apache.hadoop.fs.permission.FsAction)16 FsPermission (org.apache.hadoop.fs.permission.FsPermission)8 FileStatus (org.apache.hadoop.fs.FileStatus)4 AclEntry (org.apache.hadoop.fs.permission.AclEntry)3 AclEntryType (org.apache.hadoop.fs.permission.AclEntryType)2 AccessControlException (java.security.AccessControlException)1 Configuration (org.apache.hadoop.conf.Configuration)1 AclEntryScope (org.apache.hadoop.fs.permission.AclEntryScope)1 ScopedAclEntries (org.apache.hadoop.fs.permission.ScopedAclEntries)1 AclException (org.apache.hadoop.hdfs.protocol.AclException)1