|
@@ -22,6 +22,7 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.URI;
|
|
|
+import java.security.PrivilegedExceptionAction;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.EnumSet;
|
|
@@ -49,6 +50,7 @@ import org.apache.hadoop.ipc.RpcServerException;
|
|
|
import org.apache.hadoop.ipc.UnexpectedServerException;
|
|
|
import org.apache.hadoop.fs.InvalidPathException;
|
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
|
+import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
|
|
/**
|
|
|
* The FileContext class provides an interface to the application writer for
|
|
@@ -194,12 +196,20 @@ public final class FileContext {
|
|
|
private Path workingDir; // Fully qualified
|
|
|
private FsPermission umask;
|
|
|
private final Configuration conf;
|
|
|
+ private final UserGroupInformation ugi;
|
|
|
|
|
|
private FileContext(final AbstractFileSystem defFs,
|
|
|
final FsPermission theUmask, final Configuration aConf) {
|
|
|
defaultFS = defFs;
|
|
|
umask = FsPermission.getUMask(aConf);
|
|
|
conf = aConf;
|
|
|
+ try {
|
|
|
+ ugi = UserGroupInformation.getCurrentUser();
|
|
|
+ } catch (IOException e) {
|
|
|
+ LOG.error("Exception in getCurrentUser: "+e);
|
|
|
+ throw new RuntimeException("Failed to get the current user " +
|
|
|
+ "while creating a FileContext");
|
|
|
+ }
|
|
|
/*
|
|
|
* Init the wd.
|
|
|
* WorkingDir is implemented at the FileContext layer
|
|
@@ -288,7 +298,25 @@ public final class FileContext {
|
|
|
defaultFS.checkPath(absOrFqPath);
|
|
|
return defaultFS;
|
|
|
} catch (Exception e) { // it is different FileSystem
|
|
|
- return AbstractFileSystem.get(absOrFqPath.toUri(), conf);
|
|
|
+ try {
|
|
|
+ return ugi.doAs(new PrivilegedExceptionAction<AbstractFileSystem>() {
|
|
|
+
|
|
|
+ public AbstractFileSystem run() throws UnsupportedFileSystemException {
|
|
|
+ return AbstractFileSystem.get(absOrFqPath.toUri(), conf);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ } catch (InterruptedException ex) {
|
|
|
+ LOG.error(ex);
|
|
|
+ throw new RuntimeException(
|
|
|
+ "Failed to get the AbstractFileSystem for path: " + absOrFqPath);
|
|
|
+ } catch (UnsupportedFileSystemException ex) {
|
|
|
+ throw ex;
|
|
|
+ } catch (IOException ex) {
|
|
|
+ LOG.error("IOException in doAs: " + ex);
|
|
|
+ throw new RuntimeException(
|
|
|
+ "Failed to get the AbstractFileSystem for path: " + absOrFqPath);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -463,6 +491,14 @@ public final class FileContext {
|
|
|
return workingDir;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Gets the ugi in the file-context
|
|
|
+ * @return UserGroupInformation
|
|
|
+ */
|
|
|
+ public UserGroupInformation getUgi() {
|
|
|
+ return ugi;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
* @return the umask of this FileContext
|