Browse Source

svn merge -c 1176179 from branch-0.20-security for HDFS-2366.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-205@1176180 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 14 years ago
parent
commit
1322bb5600
2 changed files with 17 additions and 4 deletions
  1. 3 0
      CHANGES.txt
  2. 14 4
      src/hdfs/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java

+ 3 - 0
CHANGES.txt

@@ -217,6 +217,9 @@ Release 0.20.205.0 - 2011.09.12
     MAPREDUCE-3801. Fix for vaidya.sh to work with the new layout
     (Suhas via gkesavan)
 
+    HDFS-2366. Initialize WebHdfsFileSystem.ugi in object construction.
+    (szetszwo)
+
   IMPROVEMENTS
 
     MAPREDUCE-2928. MR-2413 improvements (Eli Collins via mattf)

+ 14 - 4
src/hdfs/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java

@@ -27,8 +27,6 @@ import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.Arrays;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.hadoop.conf.Configuration;
@@ -86,17 +84,24 @@ public class WebHdfsFileSystem extends HftpFileSystem {
 
   private static final KerberosUgiAuthenticator AUTH = new KerberosUgiAuthenticator();
 
-  private UserGroupInformation ugi;
+  private final UserGroupInformation ugi;
   private final AuthenticatedURL.Token authToken = new AuthenticatedURL.Token();
   protected Path workingDir;
 
+  {
+    try {
+      ugi = UserGroupInformation.getCurrentUser();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
   @Override
   public synchronized void initialize(URI uri, Configuration conf
       ) throws IOException {
     super.initialize(uri, conf);
     setConf(conf);
 
-    ugi = UserGroupInformation.getCurrentUser();
     this.workingDir = getHomeDirectory();
   }
 
@@ -110,6 +115,11 @@ public class WebHdfsFileSystem extends HftpFileSystem {
     }
   }
 
+  @Override
+  public Path getHomeDirectory() {
+    return makeQualified(new Path("/user/" + ugi.getShortUserName()));
+  }
+
   @Override
   public synchronized Path getWorkingDirectory() {
     return workingDir;