Package org.apache.hadoop.hbase.security
Class User
java.lang.Object
org.apache.hadoop.hbase.security.User
- Direct Known Subclasses:
AccessChecker.InputUser
,User.SecureHadoopUser
Wrapper to abstract out usage of user and group information in HBase.
This class provides a common interface for interacting with user and group information across
changing APIs in different versions of Hadoop. It only provides access to the common set of
functionality in UserGroupInformation
currently needed by
HBase, but can be extended as needs change.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
BridgesUser
invocations to underlying calls toUserGroupInformation
for secure Hadoop 0.20 and versions 0.21 and above.static class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addToken
(org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.TokenIdentifier> token) Adds the given Token to the user's credentials.static User
create
(org.apache.hadoop.security.UserGroupInformation ugi) Wraps an underlyingUserGroupInformation
instance.static User
createUserForTesting
(org.apache.hadoop.conf.Configuration conf, String name, String[] groups) Generates a newUser
instance specifically for use in test code.boolean
static User
Returns theUser
instance within current execution context.String[]
Returns the list of groups of which this user is a member.getName()
Returns the full user name.abstract String
Returns the shortened version of the user name -- the portion that maps to an operating system user name.org.apache.hadoop.security.token.Token<?>
Returns the Token of the specified kind associated with this user, or null if the Token is not present.Collection<org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.TokenIdentifier>>
Returns all the tokens stored in the user's credentials.org.apache.hadoop.security.UserGroupInformation
getUGI()
int
hashCode()
static boolean
isHBaseSecurityEnabled
(org.apache.hadoop.conf.Configuration conf) Returns whether or not secure authentication is enabled for HBase.boolean
Returns true if user credentials are obtained from keytab.static boolean
Returns whether or not Kerberos authentication is configured for Hadoop.static void
Login with the given keytab and principal.static void
login
(org.apache.hadoop.conf.Configuration conf, String fileConfKey, String principalConfKey, String localhost) Log in the current process using the given configuration keys for the credential file and login principal.abstract <T> T
runAs
(PrivilegedAction<T> action) Executes the given action within the context of this user.abstract <T> T
runAs
(PrivilegedExceptionAction<T> action) Executes the given action within the context of this user.static <T> T
runAsLoginUser
(PrivilegedExceptionAction<T> action) Executes the given action as the login userstatic boolean
shouldLoginFromKeytab
(org.apache.hadoop.conf.Configuration conf) In secure environment, if a user specified his keytab and principal, a hbase client will try to login with them.toString()
-
Field Details
-
HBASE_SECURITY_CONF_KEY
- See Also:
-
HBASE_SECURITY_AUTHORIZATION_CONF_KEY
- See Also:
-
ugi
-
-
Constructor Details
-
User
public User()
-
-
Method Details
-
getUGI
-
getName
Returns the full user name. For Kerberos principals this will include the host and realm portions of the principal name.- Returns:
- User full name.
-
getGroupNames
Returns the list of groups of which this user is a member. On secure Hadoop this returns the group information for the user as resolved on the server. For 0.20 based Hadoop, the group names are passed from the client. -
getShortName
Returns the shortened version of the user name -- the portion that maps to an operating system user name.- Returns:
- Short name
-
runAs
Executes the given action within the context of this user. -
runAs
public abstract <T> T runAs(PrivilegedExceptionAction<T> action) throws IOException, InterruptedException Executes the given action within the context of this user.- Throws:
IOException
InterruptedException
-
getToken
public org.apache.hadoop.security.token.Token<?> getToken(String kind, String service) throws IOException Returns the Token of the specified kind associated with this user, or null if the Token is not present.- Parameters:
kind
- the kind of tokenservice
- service on which the token is supposed to be used- Returns:
- the token of the specified kind.
- Throws:
IOException
-
getTokens
public Collection<org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.TokenIdentifier>> getTokens()Returns all the tokens stored in the user's credentials. -
addToken
public void addToken(org.apache.hadoop.security.token.Token<? extends org.apache.hadoop.security.token.TokenIdentifier> token) Adds the given Token to the user's credentials.- Parameters:
token
- the token to add
-
isLoginFromKeytab
Returns true if user credentials are obtained from keytab. -
equals
-
hashCode
-
toString
-
getCurrent
Returns theUser
instance within current execution context.- Throws:
IOException
-
runAsLoginUser
Executes the given action as the login user- Throws:
IOException
-
create
Wraps an underlyingUserGroupInformation
instance.- Parameters:
ugi
- The base Hadoop user
-
createUserForTesting
public static User createUserForTesting(org.apache.hadoop.conf.Configuration conf, String name, String[] groups) Generates a newUser
instance specifically for use in test code.- Parameters:
name
- the full usernamegroups
- the group names to which the test user will belong- Returns:
- a new
User
instance
-
login
public static void login(org.apache.hadoop.conf.Configuration conf, String fileConfKey, String principalConfKey, String localhost) throws IOException Log in the current process using the given configuration keys for the credential file and login principal.This is only applicable when running on secure Hadoop -- see org.apache.hadoop.security.SecurityUtil#login(Configuration,String,String,String). On regular Hadoop (without security features), this will safely be ignored.
- Parameters:
conf
- The configuration data to usefileConfKey
- Property key used to configure path to the credential fileprincipalConfKey
- Property key used to configure login principallocalhost
- Current hostname to use in any credentials- Throws:
IOException
- underlying exception from SecurityUtil.login() call
-
login
Login with the given keytab and principal.- Parameters:
keytabLocation
- path of keytabpricipalName
- login principal- Throws:
IOException
- underlying exception from UserGroupInformation.loginUserFromKeytab
-
isSecurityEnabled
Returns whether or not Kerberos authentication is configured for Hadoop. For non-secure Hadoop, this always returnsfalse
. For secure Hadoop, it will return the value fromUserGroupInformation.isSecurityEnabled()
. -
isHBaseSecurityEnabled
Returns whether or not secure authentication is enabled for HBase. Note that HBase security requires HDFS security to provide any guarantees, so it is recommended that secure HBase should run on secure HDFS. -
shouldLoginFromKeytab
In secure environment, if a user specified his keytab and principal, a hbase client will try to login with them. Otherwise, hbase client will try to obtain ticket(through kinit) from system.- Parameters:
conf
- configuration file- Returns:
- true if keytab and principal are configured
-