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);
}
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;
}
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));
}
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());
}
}
}
}
}
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);
}
Aggregations