From b7eb5334f5ca1fbc033084ffe9690a45e596b7bb Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Fri, 20 Jan 2012 03:33:50 +0000 Subject: [PATCH] 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/trunk@1233751 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../hadoop/security/UserGroupInformation.java | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c2ee27e0d3..c295c8855c 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -279,6 +279,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 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java index e2e6b90512..7c7e975193 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java @@ -416,9 +416,19 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String appName) { 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(); }