DfsUtil { public static boolean canDoAction(FileSystem hdfs, String user, String[] groups, Path path, FsAction action) throws IOException { FileStatus status = hdfs.getFileStatus(path); FsPermission permission = status.getPermission(); if (permission.getOtherAction().implies(action)) { return true; } for (String group : groups) { if (group.equals(status.getGroup()) && permission.getGroupAction().implies(action)) { return true; } } return user.equals(status.getOwner()) && permission.getUserAction().implies(action); }  static boolean canDoAction(FileSystem hdfs, String user, String[] groups, Path path, FsAction action); static Set<Path> listFiles(FileSystem hdfs, Path path, boolean recurse, boolean filterMetaData); static Set<Path> listDirs(FileSystem hdfs, Path path, boolean recurse, boolean filterMetaData);  }
@Test public void testCanDoAction() throws IllegalArgumentException, IOException { assertTrue( DfsUtil.canDoAction(dfsServer.getFileSystem(), "me", new String[]{"me"}, new Path(dfsServer.getPathUri("/tmp")), FsAction.READ)); assertTrue(DfsUtil.canDoAction(dfsServer.getFileSystem(), "me", new String[]{"me"}, new Path(dfsServer.getPathUri("/tmp")), FsAction.WRITE)); assertFalse(DfsUtil.canDoAction(dfsServer.getFileSystem(), "me", new String[]{"me"}, new Path(dfsServer.getPathUri("/tmp/t")), FsAction.READ)); assertFalse(DfsUtil.canDoAction(dfsServer.getFileSystem(), "me", new String[]{"me"}, new Path(dfsServer.getPathUri("/tmp/t")), FsAction.WRITE)); }