Java Code Examples for org.apache.hadoop.fs.permission.FsAction#implies()

The following examples show how to use org.apache.hadoop.fs.permission.FsAction#implies() . 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: ListHDFS.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private String getPerms(final FsAction action) {
    final StringBuilder sb = new StringBuilder();
    if (action.implies(FsAction.READ)) {
        sb.append("r");
    } else {
        sb.append("-");
    }

    if (action.implies(FsAction.WRITE)) {
        sb.append("w");
    } else {
        sb.append("-");
    }

    if (action.implies(FsAction.EXECUTE)) {
        sb.append("x");
    } else {
        sb.append("-");
    }

    return sb.toString();
}
 
Example 2
Source File: FSDownload.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static boolean checkPublicPermsForAll(FileSystem fs, 
      FileStatus status, FsAction dir, FsAction file) 
  throws IOException {
  FsPermission perms = status.getPermission();
  FsAction otherAction = perms.getOtherAction();
  if (status.isDirectory()) {
    if (!otherAction.implies(dir)) {
      return false;
    }
    
    for (FileStatus child : fs.listStatus(status.getPath())) {
      if(!checkPublicPermsForAll(fs, child, dir, file)) {
        return false;
      }
    }
    return true;
  }
  return (otherAction.implies(file));
}
 
Example 3
Source File: FSDownload.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static boolean checkPublicPermsForAll(FileSystem fs, 
      FileStatus status, FsAction dir, FsAction file) 
  throws IOException {
  FsPermission perms = status.getPermission();
  FsAction otherAction = perms.getOtherAction();
  if (status.isDirectory()) {
    if (!otherAction.implies(dir)) {
      return false;
    }
    
    for (FileStatus child : fs.listStatus(status.getPath())) {
      if(!checkPublicPermsForAll(fs, child, dir, file)) {
        return false;
      }
    }
    return true;
  }
  return (otherAction.implies(file));
}
 
Example 4
Source File: GetHDFSFileInfo.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected String getPerms(final FsPermission permission) {

        final StringBuilder sb = new StringBuilder();
        for (FsAction action : new FsAction[]{permission.getUserAction(), permission.getGroupAction(), permission.getOtherAction()}) {
            if (action.implies(FsAction.READ)) {
                sb.append("r");
            } else {
                sb.append("-");
            }

            if (action.implies(FsAction.WRITE)) {
                sb.append("w");
            } else {
                sb.append("-");
            }

            if (action.implies(FsAction.EXECUTE)) {
                sb.append("x");
            } else {
                sb.append("-");
            }
        }

        return sb.toString();
    }
 
Example 5
Source File: ListHDFS.java    From nifi with Apache License 2.0 6 votes vote down vote up
private String getPerms(final FsAction action) {
    final StringBuilder sb = new StringBuilder();
    if (action.implies(FsAction.READ)) {
        sb.append("r");
    } else {
        sb.append("-");
    }

    if (action.implies(FsAction.WRITE)) {
        sb.append("w");
    } else {
        sb.append("-");
    }

    if (action.implies(FsAction.EXECUTE)) {
        sb.append("x");
    } else {
        sb.append("-");
    }

    return sb.toString();
}
 
Example 6
Source File: ClientDistributedCacheManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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, Map<URI, FileStatus> statCache) throws IOException {
  FileStatus status = getFileStatus(fs, path.toUri(), statCache);
  FsPermission perms = status.getPermission();
  FsAction otherAction = perms.getOtherAction();
  if (otherAction.implies(action)) {
    return true;
  }
  return false;
}
 
Example 7
Source File: FSPermissionChecker.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void checkPermission(String fsOwner, String supergroup,
    UserGroupInformation callerUgi, INodeAttributes[] inodeAttrs,
    INode[] inodes, byte[][] pathByNameArr, int snapshotId, String path,
    int ancestorIndex, boolean doCheckOwner, FsAction ancestorAccess,
    FsAction parentAccess, FsAction access, FsAction subAccess,
    boolean ignoreEmptyDir)
    throws AccessControlException {
  for(; ancestorIndex >= 0 && inodes[ancestorIndex] == null;
      ancestorIndex--);
  checkTraverse(inodeAttrs, path, ancestorIndex);

  final INodeAttributes last = inodeAttrs[inodeAttrs.length - 1];
  if (parentAccess != null && parentAccess.implies(FsAction.WRITE)
      && inodeAttrs.length > 1 && last != null) {
    checkStickyBit(inodeAttrs[inodeAttrs.length - 2], last);
  }
  if (ancestorAccess != null && inodeAttrs.length > 1) {
    check(inodeAttrs, path, ancestorIndex, ancestorAccess);
  }
  if (parentAccess != null && inodeAttrs.length > 1) {
    check(inodeAttrs, path, inodeAttrs.length - 2, parentAccess);
  }
  if (access != null) {
    check(last, path, access);
  }
  if (subAccess != null) {
    INode rawLast = inodes[inodeAttrs.length - 1];
    checkSubAccess(pathByNameArr, inodeAttrs.length - 1, rawLast,
        snapshotId, subAccess, ignoreEmptyDir);
  }
  if (doCheckOwner) {
    checkOwner(last);
  }
}
 
Example 8
Source File: FileUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException
 */
public static void setPermission(File f, FsPermission permission
                                 ) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }
  
  boolean rv = true;
  
  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
Example 9
Source File: ClientDistributedCacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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, Map<URI, FileStatus> statCache) throws IOException {
  FileStatus status = getFileStatus(fs, path.toUri(), statCache);
  FsPermission perms = status.getPermission();
  FsAction otherAction = perms.getOtherAction();
  if (otherAction.implies(action)) {
    return true;
  }
  return false;
}
 
Example 10
Source File: FSPermissionChecker.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void checkPermission(String fsOwner, String supergroup,
    UserGroupInformation callerUgi, INodeAttributes[] inodeAttrs,
    INode[] inodes, byte[][] pathByNameArr, int snapshotId, String path,
    int ancestorIndex, boolean doCheckOwner, FsAction ancestorAccess,
    FsAction parentAccess, FsAction access, FsAction subAccess,
    boolean ignoreEmptyDir)
    throws AccessControlException {
  for(; ancestorIndex >= 0 && inodes[ancestorIndex] == null;
      ancestorIndex--);
  checkTraverse(inodeAttrs, path, ancestorIndex);

  final INodeAttributes last = inodeAttrs[inodeAttrs.length - 1];
  if (parentAccess != null && parentAccess.implies(FsAction.WRITE)
      && inodeAttrs.length > 1 && last != null) {
    checkStickyBit(inodeAttrs[inodeAttrs.length - 2], last);
  }
  if (ancestorAccess != null && inodeAttrs.length > 1) {
    check(inodeAttrs, path, ancestorIndex, ancestorAccess);
  }
  if (parentAccess != null && inodeAttrs.length > 1) {
    check(inodeAttrs, path, inodeAttrs.length - 2, parentAccess);
  }
  if (access != null) {
    check(last, path, access);
  }
  if (subAccess != null) {
    INode rawLast = inodes[inodeAttrs.length - 1];
    checkSubAccess(pathByNameArr, inodeAttrs.length - 1, rawLast,
        snapshotId, subAccess, ignoreEmptyDir);
  }
  if (doCheckOwner) {
    checkOwner(last);
  }
}
 
Example 11
Source File: FileUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException
 */
public static void setPermission(File f, FsPermission permission
                                 ) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }
  
  boolean rv = true;
  
  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
Example 12
Source File: FileUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException exception on setPermission
 */
public static void setPermission(File f, FsPermission permission
) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }

  boolean rv = true;

  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
Example 13
Source File: FSDownload.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: FSDownload.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}