You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cd...@apache.org on 2008/11/25 01:24:47 UTC

svn commit: r720366 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/security/UnixUserGroupInformation.java

Author: cdouglas
Date: Mon Nov 24 16:24:46 2008
New Revision: 720366

URL: http://svn.apache.org/viewvc?rev=720366&view=rev
Log:
HADOOP-4429. Set defaults for user, group in UnixUserGroupInformation so
login fails more predictably when misconfigured. Contributed by Alex Loddengaard.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/core/org/apache/hadoop/security/UnixUserGroupInformation.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=720366&r1=720365&r2=720366&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Nov 24 16:24:46 2008
@@ -193,6 +193,10 @@
 
     HADOOP-4598. '-setrep' command skips under-replicated blocks. (hairong)
 
+    HADOOP-4429. Set defaults for user, group in UnixUserGroupInformation so
+    login fails more predictably when misconfigured. (Alex Loddengaard via
+    cdouglas)
+
 Release 0.19.0 - 2008-11-18
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/core/org/apache/hadoop/security/UnixUserGroupInformation.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/security/UnixUserGroupInformation.java?rev=720366&r1=720365&r2=720366&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/security/UnixUserGroupInformation.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/security/UnixUserGroupInformation.java Mon Nov 24 16:24:46 2008
@@ -35,6 +35,9 @@
 
 /** An implementation of UserGroupInformation in the Unix system */
 public class UnixUserGroupInformation extends UserGroupInformation {
+  public static final String DEFAULT_USERNAME = "DrWho";
+  public static final String DEFAULT_GROUP = "Tardis";
+
   final static public String UGI_PROPERTY_NAME = "hadoop.job.ugi";
   final static private HashMap<String, UnixUserGroupInformation> user2UGIMap =
     new HashMap<String, UnixUserGroupInformation>();
@@ -226,10 +229,23 @@
    * has a UGI in the ugi map, return the ugi in the map.
    * Otherwise get the current user's information from Unix, store it
    * in the map, and return it.
+   *
+   * If the current user's UNIX username or groups are configured in such a way
+   * to throw an Exception, for example if the user uses LDAP, then this method
+   * will use a the {@link #DEFAULT_USERNAME} and {@link #DEFAULT_GROUP}
+   * constants.
    */
   public static UnixUserGroupInformation login() throws LoginException {
     try {
-      String userName =  getUnixUserName();
+      String userName;
+
+      // if an exception occurs, then uses the
+      // default user
+      try {
+        userName =  getUnixUserName();
+      } catch (Exception e) {
+        userName = DEFAULT_USERNAME;
+      }
 
       // check if this user already has a UGI object in the ugi map
       UnixUserGroupInformation ugi = user2UGIMap.get(userName);
@@ -240,7 +256,16 @@
       /* get groups list from UNIX. 
        * It's assumed that the first group is the default group.
        */
-      String[]  groupNames = getUnixGroups();
+      String[]  groupNames;
+
+      // if an exception occurs, then uses the
+      // default group
+      try {
+        groupNames = getUnixGroups();
+      } catch (Exception e) {
+        groupNames = new String[1];
+        groupNames[0] = DEFAULT_GROUP;
+      }
 
       // construct a Unix UGI
       ugi = new UnixUserGroupInformation(userName, groupNames);