From 42a38a4b587c3f7ffd8f098120c958a100e070b6 Mon Sep 17 00:00:00 2001 From: Boris Shkolnik Date: Mon, 7 Jun 2010 21:50:05 +0000 Subject: [PATCH] HADOOP-6687. user object in the subject in UGI should be reused in case of a relogin. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@952454 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ .../hadoop/security/UserGroupInformation.java | 4 ++++ .../hadoop/security/TestUserGroupInformation.java | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 403fe810940..f58d608d57f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -70,6 +70,9 @@ Trunk (unreleased changes) HADOOP-6649. login object in UGI should be inside the subject (jnp via boryas) + HADOOP-6687. user object in the subject in UGI should be reused in case + of a relogin. (jnp via boryas) + Release 0.21.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/security/UserGroupInformation.java b/src/java/org/apache/hadoop/security/UserGroupInformation.java index 8c3604032f1..4125154cc7e 100644 --- a/src/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/src/java/org/apache/hadoop/security/UserGroupInformation.java @@ -88,6 +88,10 @@ public class UserGroupInformation { @Override public boolean commit() throws LoginException { + // if we already have a user, we are done. + if (!subject.getPrincipals(User.class).isEmpty()) { + return true; + } Principal user = null; // if we are using kerberos, try it out if (useKerberos) { diff --git a/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java b/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java index d9e106aa4cf..f5f9cb213a4 100644 --- a/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java +++ b/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java @@ -302,4 +302,18 @@ public class TestUserGroupInformation { //login1 and login2 must be same instances Assert.assertTrue(login1 == login2); } + + @Test + public void testLoginModuleCommit() throws Exception { + UserGroupInformation loginUgi = UserGroupInformation.getLoginUser(); + User user1 = loginUgi.getSubject().getPrincipals(User.class).iterator() + .next(); + LoginContext login = user1.getLogin(); + login.logout(); + login.login(); + User user2 = loginUgi.getSubject().getPrincipals(User.class).iterator() + .next(); + // user1 and user2 must be same instances. + Assert.assertTrue(user1 == user2); + } }