org.apache.hadoop.hive.common.FileUtils.checkFileAccessWithImpersonation()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.apache.hadoop.hive.common.FileUtils.checkFileAccessWithImpersonation()方法的一些代码示例,展示了FileUtils.checkFileAccessWithImpersonation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.checkFileAccessWithImpersonation()方法的具体详情如下:
包路径:org.apache.hadoop.hive.common.FileUtils
类名称:FileUtils
方法名:checkFileAccessWithImpersonation

FileUtils.checkFileAccessWithImpersonation介绍

[英]Perform a check to determine if the user is able to access the file passed in. If the user name passed in is different from the current user, this method will attempt to do impersonate the user to do the check; the current user should be able to create proxy users in this case.
[中]执行检查以确定用户是否能够访问传入的文件。如果传入的用户名与当前用户不同,此方法将尝试模拟用户进行检查;在这种情况下,当前用户应该能够创建代理用户。

代码示例

代码示例来源:origin: apache/hive

public static void checkFileAccessWithImpersonation(final FileSystem fs, final FileStatus stat,
  final FsAction action, final String user)
  throws IOException, AccessControlException, InterruptedException, Exception {
 checkFileAccessWithImpersonation(fs, stat, action, user, null);
}

代码示例来源:origin: apache/hive

checkFileAccessWithImpersonation(fs, fileStatus, action, userName, subDirsToCheck);
} catch (AccessControlException err) {

代码示例来源:origin: apache/hive

/**
 * Checks the permissions for the given path and current user on Hadoop FS. If the given path
 * does not exists, it returns.
 */
@SuppressWarnings("deprecation")
protected static void checkPermissions(final FileSystem fs, final FileStatus stat,
  final EnumSet<FsAction> actions, String user) throws IOException,
  AccessControlException, HiveException {
 if (stat == null) {
  // File named by path doesn't exist; nothing to validate.
  return;
 }
 FsAction checkActions = FsAction.NONE;
 for (FsAction action : actions) {
  checkActions = checkActions.or(action);
 }
 try {
  FileUtils.checkFileAccessWithImpersonation(fs, stat, checkActions, user);
 } catch (Exception err) {
  // fs.permission.AccessControlException removed by HADOOP-11356, but Hive users on older
  // Hadoop versions may still see this exception .. have to reference by name.
  if (err.getClass().getName().equals("org.apache.hadoop.fs.permission.AccessControlException")) {
   throw accessControlException(err);
  }
  throw new HiveException(err);
 }
}

代码示例来源:origin: apache/drill

/**
 * Checks the permissions for the given path and current user on Hadoop FS. If the given path
 * does not exists, it returns.
 */
@SuppressWarnings("deprecation")
protected static void checkPermissions(final FileSystem fs, final FileStatus stat,
  final EnumSet<FsAction> actions, String user) throws IOException,
  AccessControlException, HiveException {
 if (stat == null) {
  // File named by path doesn't exist; nothing to validate.
  return;
 }
 FsAction checkActions = FsAction.NONE;
 for (FsAction action : actions) {
  checkActions = checkActions.or(action);
 }
 try {
  FileUtils.checkFileAccessWithImpersonation(fs, stat, checkActions, user);
 } catch (Exception err) {
  // fs.permission.AccessControlException removed by HADOOP-11356, but Hive users on older
  // Hadoop versions may still see this exception .. have to reference by name.
  if (err.getClass().getName().equals("org.apache.hadoop.fs.permission.AccessControlException")) {
   throw accessControlException(err);
  }
  throw new HiveException(err);
 }
}

代码示例来源:origin: apache/hive

/**
 * Checks if a given path has read-only access permissions.
 *
 * @param path The path to check for read-only permissions.
 * @return True if the path is read-only; False otherwise.
 * @throws HiveException If an error occurs while checking file permissions.
 */
private boolean isPathReadOnly(Path path) throws HiveException {
 HiveConf conf = SessionState.get().getConf();
 try {
  FileSystem fs = path.getFileSystem(conf);
  UserGroupInformation ugi = Utils.getUGI();
  FileStatus status = fs.getFileStatus(path);
  // We just check for writing permissions. If it fails with AccessControException, then it
  // means the location may be read-only.
  FileUtils.checkFileAccessWithImpersonation(fs, status, FsAction.WRITE, ugi.getUserName());
  // Path has writing permissions
  return false;
 } catch (AccessControlException e) {
  // An AccessControlException may be caused for other different errors,
  // but we take it as if our path is read-only
  return true;
 } catch (Exception e) {
  throw new HiveException("Unable to determine if " + path + " is read only: " + e, e);
 }
}

代码示例来源:origin: apache/drill

/**
 * Checks if a given path has read-only access permissions.
 *
 * @param path The path to check for read-only permissions.
 * @return True if the path is read-only; False otherwise.
 * @throws HiveException If an error occurs while checking file permissions.
 */
private boolean isPathReadOnly(Path path) throws HiveException {
 HiveConf conf = SessionState.get().getConf();
 try {
  FileSystem fs = path.getFileSystem(conf);
  UserGroupInformation ugi = Utils.getUGI();
  FileStatus status = fs.getFileStatus(path);
  // We just check for writing permissions. If it fails with AccessControException, then it
  // means the location may be read-only.
  FileUtils.checkFileAccessWithImpersonation(fs, status, FsAction.WRITE, ugi.getUserName());
  // Path has writing permissions
  return false;
 } catch (AccessControlException e) {
  // An AccessControlException may be caused for other different errors,
  // but we take it as if our path is read-only
  return true;
 } catch (Exception e) {
  throw new HiveException("Unable to determine if " + path + " is read only: " + e, e);
 }
}

代码示例来源:origin: apache/hive

FileUtils.checkFileAccessWithImpersonation(fs, stat, FsAction.WRITE, user);

代码示例来源:origin: org.apache.hive/hive-common

public static void checkFileAccessWithImpersonation(final FileSystem fs, final FileStatus stat,
  final FsAction action, final String user)
  throws IOException, AccessControlException, InterruptedException, Exception {
 checkFileAccessWithImpersonation(fs, stat, action, user, null);
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache

/**
 * Checks the permissions for the given path and current user on Hadoop FS. If the given path
 * does not exists, it returns.
 */
@SuppressWarnings("deprecation")
protected static void checkPermissions(final FileSystem fs, final FileStatus stat,
  final EnumSet<FsAction> actions, String user) throws IOException,
  AccessControlException, HiveException {
 if (stat == null) {
  // File named by path doesn't exist; nothing to validate.
  return;
 }
 FsAction checkActions = FsAction.NONE;
 for (FsAction action : actions) {
  checkActions = checkActions.or(action);
 }
 try {
  FileUtils.checkFileAccessWithImpersonation(fs, stat, checkActions, user);
 } catch (Exception err) {
  // fs.permission.AccessControlException removed by HADOOP-11356, but Hive users on older
  // Hadoop versions may still see this exception .. have to reference by name.
  if (err.getClass().getName().equals("org.apache.hadoop.fs.permission.AccessControlException")) {
   throw accessControlException(err);
  }
  throw new HiveException(err);
 }
}

代码示例来源:origin: org.apache.hive/hive-common

checkFileAccessWithImpersonation(fs, fileStatus, action, userName, subDirsToCheck);
} catch (AccessControlException err) {

代码示例来源:origin: com.facebook.presto.hive/hive-apache

/**
 * Checks if a given path has read-only access permissions.
 *
 * @param path The path to check for read-only permissions.
 * @return True if the path is read-only; False otherwise.
 * @throws HiveException If an error occurs while checking file permissions.
 */
private boolean isPathReadOnly(Path path) throws HiveException {
 HiveConf conf = SessionState.get().getConf();
 try {
  FileSystem fs = path.getFileSystem(conf);
  UserGroupInformation ugi = Utils.getUGI();
  FileStatus status = fs.getFileStatus(path);
  // We just check for writing permissions. If it fails with AccessControException, then it
  // means the location may be read-only.
  FileUtils.checkFileAccessWithImpersonation(fs, status, FsAction.WRITE, ugi.getUserName());
  // Path has writing permissions
  return false;
 } catch (AccessControlException e) {
  // An AccessControlException may be caused for other different errors,
  // but we take it as if our path is read-only
  return true;
 } catch (Exception e) {
  throw new HiveException("Unable to determine if " + path + " is read only: " + e, e);
 }
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache

checkFileAccessWithImpersonation(fs, fileStatus, action, userName);
} catch (AccessControlException err) {

代码示例来源:origin: com.facebook.presto.hive/hive-apache

FileUtils.checkFileAccessWithImpersonation(fs, stat, FsAction.WRITE, user);

代码示例来源:origin: org.apache.hive/hive-common

FileUtils.checkFileAccessWithImpersonation(fs, stat, FsAction.WRITE, user);

相关文章