/** * Checks the permissions for the given path and current user on Hadoop FS. * If the given path does not exists, it checks for its parent folder. */ protected void checkPermissions(final Configuration conf, final Path path, final EnumSet<FsAction> actions) throws IOException, LoginException, HiveException { if (path == null) { throw new IllegalArgumentException("path is null"); } final FileSystem fs = path.getFileSystem(conf); FileStatus pathStatus = FileUtils.getFileStatusOrNull(fs, path); if (pathStatus != null) { checkPermissions(fs, pathStatus, actions, authenticator.getUserName()); } else if (path.getParent() != null) { // find the ancestor which exists to check its permissions Path par = path.getParent(); FileStatus parStatus = null; while (par != null) { parStatus = FileUtils.getFileStatusOrNull(fs, par); if (parStatus != null) { break; } par = par.getParent(); } checkPermissions(fs, parStatus, actions, authenticator.getUserName()); } }
/** * Checks the permissions for the given path and current user on Hadoop FS. * If the given path does not exists, it checks for its parent folder. */ protected void checkPermissions(final Configuration conf, final Path path, final EnumSet<FsAction> actions) throws IOException, LoginException, HiveException { if (path == null) { throw new IllegalArgumentException("path is null"); } final FileSystem fs = path.getFileSystem(conf); FileStatus pathStatus = FileUtils.getFileStatusOrNull(fs, path); if (pathStatus != null) { checkPermissions(fs, pathStatus, actions, authenticator.getUserName()); } else if (path.getParent() != null) { // find the ancestor which exists to check its permissions Path par = path.getParent(); FileStatus parStatus = null; while (par != null) { parStatus = FileUtils.getFileStatusOrNull(fs, par); if (parStatus != null) { break; } par = par.getParent(); } checkPermissions(fs, parStatus, actions, authenticator.getUserName()); } }
/** * Authorization privileges against a path. * * @param path * a filesystem path * @param readRequiredPriv * a list of privileges needed for inputs. * @param writeRequiredPriv * a list of privileges needed for outputs. */ public void authorize(Path path, Privilege[] readRequiredPriv, Privilege[] writeRequiredPriv) throws HiveException, AuthorizationException { try { EnumSet<FsAction> actions = getFsActions(readRequiredPriv); actions.addAll(getFsActions(writeRequiredPriv)); if (actions.isEmpty()) { return; } checkPermissions(getConf(), path, actions); } catch (AccessControlException ex) { throw authorizationException(ex); } catch (LoginException ex) { throw authorizationException(ex); } catch (IOException ex) { throw hiveException(ex); } }
/** * Authorization privileges against a path. * * @param path * a filesystem path * @param readRequiredPriv * a list of privileges needed for inputs. * @param writeRequiredPriv * a list of privileges needed for outputs. */ public void authorize(Path path, Privilege[] readRequiredPriv, Privilege[] writeRequiredPriv) throws HiveException, AuthorizationException { try { EnumSet<FsAction> actions = getFsActions(readRequiredPriv); actions.addAll(getFsActions(writeRequiredPriv)); if (actions.isEmpty()) { return; } checkPermissions(getConf(), path, actions); } catch (AccessControlException ex) { throw authorizationException(ex); } catch (LoginException ex) { throw authorizationException(ex); } catch (IOException ex) { throw hiveException(ex); } }
/** * Checks the permissions for the given path and current user on Hadoop FS. * If the given path does not exists, it checks for its parent folder. */ protected void checkPermissions(final Configuration conf, final Path path, final EnumSet<FsAction> actions) throws IOException, LoginException, HiveException { if (path == null) { throw new IllegalArgumentException("path is null"); } final FileSystem fs = path.getFileSystem(conf); FileStatus pathStatus = FileUtils.getFileStatusOrNull(fs, path); if (pathStatus != null) { checkPermissions(fs, pathStatus, actions, authenticator.getUserName()); } else if (path.getParent() != null) { // find the ancestor which exists to check its permissions Path par = path.getParent(); FileStatus parStatus = null; while (par != null) { parStatus = FileUtils.getFileStatusOrNull(fs, par); if (parStatus != null) { break; } par = par.getParent(); } checkPermissions(fs, parStatus, actions, authenticator.getUserName()); } }
/** * Authorization privileges against a path. * * @param path * a filesystem path * @param readRequiredPriv * a list of privileges needed for inputs. * @param writeRequiredPriv * a list of privileges needed for outputs. */ public void authorize(Path path, Privilege[] readRequiredPriv, Privilege[] writeRequiredPriv) throws HiveException, AuthorizationException { try { EnumSet<FsAction> actions = getFsActions(readRequiredPriv); actions.addAll(getFsActions(writeRequiredPriv)); if (actions.isEmpty()) { return; } checkPermissions(getConf(), path, actions); } catch (AccessControlException ex) { throw authorizationException(ex); } catch (LoginException ex) { throw authorizationException(ex); } catch (IOException ex) { throw hiveException(ex); } }