You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ga...@apache.org on 2011/10/01 03:44:40 UTC
svn commit: r1177881 - in /hbase/trunk: CHANGES.txt
src/main/java/org/apache/hadoop/hbase/security/User.java
src/test/java/org/apache/hadoop/hbase/security/TestUser.java
Author: garyh
Date: Sat Oct 1 01:44:39 2011
New Revision: 1177881
URL: http://svn.apache.org/viewvc?rev=1177881&view=rev
Log:
HBASE-4515 User.getCurrent() can fail to initialize the current user
Modified:
hbase/trunk/CHANGES.txt
hbase/trunk/src/main/java/org/apache/hadoop/hbase/security/User.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/security/TestUser.java
Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1177881&r1=1177880&r2=1177881&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Sat Oct 1 01:44:39 2011
@@ -682,6 +682,7 @@ Release 0.90.5 - Unreleased
(Lars Hofhansl)
HBASE-4295 rowcounter does not return the correct number of rows in
certain circumstances (David Revell)
+ HBASE-4515 User.getCurrent() can fail to initialize the current user
IMPROVEMENT
HBASE-4205 Enhance HTable javadoc (Eric Charles)
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/security/User.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/security/User.java?rev=1177881&r1=1177880&r2=1177881&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/security/User.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/security/User.java Sat Oct 1 01:44:39 2011
@@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.security
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.util.Methods;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.Job;
@@ -97,11 +98,16 @@ public abstract class User {
* Returns the {@code User} instance within current execution context.
*/
public static User getCurrent() throws IOException {
+ User user;
if (IS_SECURE_HADOOP) {
- return new SecureHadoopUser();
+ user = new SecureHadoopUser();
} else {
- return new HadoopUser();
+ user = new HadoopUser();
}
+ if (user.ugi == null) {
+ return null;
+ }
+ return user;
}
/**
@@ -170,6 +176,17 @@ public abstract class User {
private HadoopUser() {
try {
ugi = (UserGroupInformation) callStatic("getCurrentUGI");
+ if (ugi == null) {
+ // Secure Hadoop UGI will perform an implicit login if the current
+ // user is null. Emulate the same behavior here for consistency
+ Configuration conf = HBaseConfiguration.create();
+ ugi = (UserGroupInformation) callStatic("login",
+ new Class[]{ Configuration.class }, new Object[]{ conf });
+ if (ugi != null) {
+ callStatic("setCurrentUser",
+ new Class[]{ UserGroupInformation.class }, new Object[]{ ugi });
+ }
+ }
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/security/TestUser.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/security/TestUser.java?rev=1177881&r1=1177880&r2=1177881&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/security/TestUser.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/security/TestUser.java Sat Oct 1 01:44:39 2011
@@ -21,8 +21,12 @@ package org.apache.hadoop.hbase.security
import static org.junit.Assert.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.security.UnixUserGroupInformation;
+import org.apache.hadoop.security.UserGroupInformation;
import org.junit.Test;
import java.io.IOException;
@@ -30,6 +34,8 @@ import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
public class TestUser {
+ private static Log LOG = LogFactory.getLog(TestUser.class);
+
@Test
public void testBasicAttributes() throws Exception {
Configuration conf = HBaseConfiguration.create();
@@ -79,4 +85,22 @@ public class TestUser {
}
});
}
+
+ /**
+ * Make sure that we're returning a result for the current user.
+ * Previously getCurrent() was returning null if not initialized on
+ * non-secure Hadoop variants.
+ */
+ @Test
+ public void testGetCurrent() throws Exception {
+ User user1 = User.getCurrent();
+ assertNotNull(user1.ugi);
+ LOG.debug("User1 is "+user1.getName());
+
+ for (int i =0 ; i< 100; i++) {
+ User u = User.getCurrent();
+ assertNotNull(u);
+ assertEquals(user1.getName(), u.getName());
+ }
+ }
}