HBASE-4515 User.getCurrent() can fail to initialize the current user
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1177881 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dd224a594b
commit
39c0909e3e
@ -682,6 +682,7 @@ Release 0.90.5 - Unreleased
|
|||||||
(Lars Hofhansl)
|
(Lars Hofhansl)
|
||||||
HBASE-4295 rowcounter does not return the correct number of rows in
|
HBASE-4295 rowcounter does not return the correct number of rows in
|
||||||
certain circumstances (David Revell)
|
certain circumstances (David Revell)
|
||||||
|
HBASE-4515 User.getCurrent() can fail to initialize the current user
|
||||||
|
|
||||||
IMPROVEMENT
|
IMPROVEMENT
|
||||||
HBASE-4205 Enhance HTable javadoc (Eric Charles)
|
HBASE-4205 Enhance HTable javadoc (Eric Charles)
|
||||||
|
@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.security;
|
|||||||
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
import org.apache.hadoop.hbase.util.Methods;
|
import org.apache.hadoop.hbase.util.Methods;
|
||||||
import org.apache.hadoop.mapred.JobConf;
|
import org.apache.hadoop.mapred.JobConf;
|
||||||
import org.apache.hadoop.mapreduce.Job;
|
import org.apache.hadoop.mapreduce.Job;
|
||||||
@ -97,11 +98,16 @@ public abstract class User {
|
|||||||
* Returns the {@code User} instance within current execution context.
|
* Returns the {@code User} instance within current execution context.
|
||||||
*/
|
*/
|
||||||
public static User getCurrent() throws IOException {
|
public static User getCurrent() throws IOException {
|
||||||
|
User user;
|
||||||
if (IS_SECURE_HADOOP) {
|
if (IS_SECURE_HADOOP) {
|
||||||
return new SecureHadoopUser();
|
user = new SecureHadoopUser();
|
||||||
} else {
|
} 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() {
|
private HadoopUser() {
|
||||||
try {
|
try {
|
||||||
ugi = (UserGroupInformation) callStatic("getCurrentUGI");
|
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) {
|
} catch (RuntimeException re) {
|
||||||
throw re;
|
throw re;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -21,8 +21,12 @@ package org.apache.hadoop.hbase.security;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
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.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
|
import org.apache.hadoop.security.UnixUserGroupInformation;
|
||||||
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -30,6 +34,8 @@ import java.security.PrivilegedAction;
|
|||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
|
||||||
public class TestUser {
|
public class TestUser {
|
||||||
|
private static Log LOG = LogFactory.getLog(TestUser.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAttributes() throws Exception {
|
public void testBasicAttributes() throws Exception {
|
||||||
Configuration conf = HBaseConfiguration.create();
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user