Prechádzať zdrojové kódy

HADOOP-6520. Adds APIs to read/write Token and secret keys. Also adds the automatic loading of tokens into UserGroupInformation upon login. The tokens are read from a file specified in the environment variable. Contributed by Devaraj Das.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@904861 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das 15 rokov pred
rodič
commit
ba8647f511

+ 5 - 0
CHANGES.txt

@@ -43,6 +43,11 @@ Trunk (unreleased changes)
 
     HADOOP-6464. Write a Rackspace cloud provider. (tomwhite)
 
+    HADOOP-6520. Adds APIs to read/write Token and secret keys. Also
+    adds the automatic loading of tokens into UserGroupInformation
+    upon login. The tokens are read from a file specified in the
+    environment variable. (ddas)
+
   IMPROVEMENTS
 
     HADOOP-6283. Improve the exception messages thrown by

+ 8 - 1
src/java/org/apache/hadoop/security/UserGroupInformation.java

@@ -34,7 +34,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -132,6 +131,10 @@ public class UserGroupInformation {
   /** Server-side groups fetching service */
   private static Groups groups;
   
+  /**Environment variable pointing to the token cache file*/
+  public static final String HADOOP_TOKEN_FILE_LOCATION = 
+    "HADOOP_TOKEN_FILE_LOCATION";
+  
   /** 
    * A method to initialize the fields that depend on a configuration.
    * Must be called before useKerberos or groups is used.
@@ -317,6 +320,10 @@ public class UserGroupInformation {
         }
         login.login();
         loginUser = new UserGroupInformation(login.getSubject());
+        String tokenFile = System.getenv(HADOOP_TOKEN_FILE_LOCATION);
+        if (tokenFile != null && isSecurityEnabled()) {
+          TokenStorage.readTokensAndLoadInUGI(tokenFile, new Configuration(), loginUser);
+        }
       } catch (LoginException le) {
         throw new IOException("failure to login", le);
       }