Browse Source

HADOOP-7982. UserGroupInformation fails to login if thread's context classloader can't load HadoopLoginModule. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1233750 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon 13 years ago
parent
commit
a980e4a4b8

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -140,6 +140,9 @@ Release 0.23.1 - Unreleased
    HADOOP-7971. Adding back job/pipes/queue commands to bin/hadoop for
    backward compatibility. (Prashath Sharma via acmurthy) 
 
+   HADOOP-7982. UserGroupInformation fails to login if thread's context
+   classloader can't load HadoopLoginModule. (todd)
+
 Release 0.23.0 - 2011-11-01 
 
   INCOMPATIBLE CHANGES

+ 12 - 2
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java

@@ -416,9 +416,19 @@ public class UserGroupInformation {
   
   private static LoginContext
   newLoginContext(String appName, Subject subject) throws LoginException {
-    return new LoginContext(appName, subject, null, new HadoopConfiguration());
+    // Temporarily switch the thread's ContextClassLoader to match this
+    // class's classloader, so that we can properly load HadoopLoginModule
+    // from the JAAS libraries.
+    Thread t = Thread.currentThread();
+    ClassLoader oldCCL = t.getContextClassLoader();
+    t.setContextClassLoader(HadoopLoginModule.class.getClassLoader());
+    try {
+      return new LoginContext(appName, subject, null, new HadoopConfiguration());
+    } finally {
+      t.setContextClassLoader(oldCCL);
+    }
   }
-  
+
   private LoginContext getLogin() {
     return user.getLogin();
   }