@Public
@Evolving
public class UserGroupInformation
extends java.lang.Object
| Modifier and Type | Class | Description |
|---|---|---|
static class |
UserGroupInformation.AuthenticationMethod |
existing types of authentications' methods
|
| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
DEFAULT_JAVA_SECURITY_AUTH_LOGIN_CONFIG |
|
static java.lang.String |
DIGEST_AUTH_MECHANISM |
|
static java.lang.String |
HADOOP_TOKEN |
Environment variable pointing to the base64 tokens.
|
static java.lang.String |
HADOOP_TOKEN_FILE_LOCATION |
Environment variable pointing to the token cache file
|
static java.lang.String |
JAVA_SECURITY_AUTH_LOGIN_CONFIG |
|
static java.lang.String |
SCRAM_AUTH_MECHANISM |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addCredentials(Credentials credentials) |
Add the given Credentials to this user.
|
boolean |
addToken(Text alias,
Token<? extends TokenIdentifier> token) |
Add a named token to this UGI
|
boolean |
addToken(Token<? extends TokenIdentifier> token) |
Add a token to this UGI
|
boolean |
addTokenIdentifier(TokenIdentifier tokenId) |
Add a TokenIdentifier to this UGI.
|
void |
checkTGTAndReloginFromKeytab() |
Re-login a user from keytab if TGT is expired or is close to expiry.
|
static UserGroupInformation |
createProxyUser(java.lang.String user,
UserGroupInformation realUser) |
Create a proxy user using username of the effective user and the ugi of the
real user.
|
static UserGroupInformation |
createProxyUserForTesting(java.lang.String user,
UserGroupInformation realUser,
java.lang.String[] userGroups) |
Create a proxy user UGI for testing HDFS and MapReduce
|
static UserGroupInformation |
createRemoteUser(java.lang.String user) |
Create a user from a login name.
|
static UserGroupInformation |
createRemoteUser(java.lang.String user,
SaslRpcServer.AuthMethod authMethod) |
Create a user from a login name.
|
static UserGroupInformation |
createUserForTesting(java.lang.String user,
java.lang.String[] userGroups) |
Create a UGI for testing HDFS and MapReduce
|
<T> T |
doAs(java.security.PrivilegedAction<T> action) |
Run the given action as the user.
|
<T> T |
doAs(java.security.PrivilegedExceptionAction<T> action) |
Run the given action as the user, potentially throwing an exception.
|
boolean |
equals(java.lang.Object o) |
Compare the subjects to see if they are equal to each other.
|
void |
forceReloginFromKeytab() |
Force re-Login a user in from a keytab file irrespective of the last login
time.
|
void |
forceReloginFromTicketCache() |
Force re-Login a user in from the ticket cache irrespective of the last
login time.
|
UserGroupInformation.AuthenticationMethod |
getAuthenticationMethod() |
Get the authentication method from the subject
|
static UserGroupInformation |
getBestUGI(java.lang.String ticketCachePath,
java.lang.String user) |
Find the most appropriate UserGroupInformation to use
|
Credentials |
getCredentials() |
Obtain the tokens in credentials form associated with this user.
|
static UserGroupInformation |
getCurrentUser() |
Return the current user, including any doAs in the current stack.
|
java.lang.String[] |
getGroupNames() |
Get the group names for this user.
|
java.util.List<java.lang.String> |
getGroups() |
Deprecated.
Use
getGroupsSet() instead. |
java.util.Set<java.lang.String> |
getGroupsSet() |
Get the groups names for the user as a Set.
|
static UserGroupInformation |
getLoginUser() |
Get the currently logged in user.
|
java.lang.String |
getPrimaryGroupName() |
|
UserGroupInformation.AuthenticationMethod |
getRealAuthenticationMethod() |
Get the authentication method from the real user's subject.
|
static UserGroupInformation.AuthenticationMethod |
getRealAuthenticationMethod(UserGroupInformation ugi) |
Returns the authentication method of a ugi.
|
UserGroupInformation |
getRealUser() |
get RealUser (vs.
|
static UserGroupInformation |
getRealUserOrSelf(UserGroupInformation user) |
If this is a proxy user, get the real user.
|
java.util.List<RpcAuthMethod> |
getRpcAuthMethodList() |
|
java.lang.String |
getShortUserName() |
Get the user's login name.
|
javax.security.auth.Subject |
getSubject() |
Get the underlying subject from this ugi.
|
java.util.Set<TokenIdentifier> |
getTokenIdentifiers() |
Get the set of TokenIdentifiers belonging to this UGI
|
java.util.Collection<Token<? extends TokenIdentifier>> |
getTokens() |
Obtain the collection of tokens associated with this user.
|
static UserGroupInformation.AuthenticationMethod |
getUGIAuthenticationMethod() |
Returns authenticationMethod obtained by inspecting JAAS configuration.
|
static UserGroupInformation |
getUGIFromSubject(javax.security.auth.Subject subject) |
Create a UserGroupInformation from a Subject with Kerberos principal.
|
static UserGroupInformation |
getUGIFromTicketCache(java.lang.String ticketCache,
java.lang.String user) |
Create a UserGroupInformation from a Kerberos ticket cache.
|
java.lang.String |
getUserName() |
Get the user's full principal name.
|
int |
hashCode() |
Return the hash of the subject.
|
boolean |
hasKerberosCredentials() |
checks if logged in using kerberos
|
boolean |
isFromKeytab() |
Is this user logged in from a keytab file managed by the UGI?
|
static boolean |
isInitialized() |
|
static boolean |
isLoginKeytabBased() |
Did the login happen via keytab.
|
boolean |
isLoginSuccess() |
This method checks for a successful Kerberos login
and returns true by default if it is not using Kerberos.
|
static boolean |
isLoginTicketBased() |
Did the login happen via ticket cache.
|
static boolean |
isSecurityEnabled() |
Determine if UserGroupInformation is using Kerberos to determine
user identities or is relying on simple authentication
|
static void |
logAllUserInfo(UserGroupInformation ugi) |
Log all (current, real, login) UGI and token info into UGI debug log.
|
static void |
logAllUserInfo(org.slf4j.Logger log,
UserGroupInformation ugi) |
Log all (current, real, login) UGI and token info into specified log.
|
static void |
loginUserFromKeytab(java.lang.String user,
java.lang.String path) |
Log a user in from a keytab file.
|
static UserGroupInformation |
loginUserFromKeytabAndReturnUGI(java.lang.String user,
java.lang.String path) |
Log a user in from a keytab file.
|
static void |
loginUserFromSubject(javax.security.auth.Subject subject) |
Log in a user using the given subject
|
void |
logoutUserFromKeytab() |
Log the current user out who previously logged in using keytab.
|
static void |
logUserInfo(org.slf4j.Logger log,
java.lang.String caption,
UserGroupInformation ugi) |
Log current UGI and token information into specified log.
|
static void |
main(java.lang.String[] args) |
A test method to print out the current user's UGI.
|
static void |
reattachMetrics() |
Reattach the class's metrics to a new metric system.
|
void |
reloginFromKeytab() |
Re-Login a user in from a keytab file.
|
void |
reloginFromTicketCache() |
Re-Login a user in from the ticket cache.
|
static void |
reset() |
|
void |
setAuthenticationMethod(SaslRpcServer.AuthMethod authMethod) |
Sets the authentication method in the subject
|
void |
setAuthenticationMethod(UserGroupInformation.AuthenticationMethod authMethod) |
Sets the authentication method in the subject
|
static void |
setConfiguration(Configuration conf) |
Set the static configuration for UGI.
|
static void |
setLoginUser(UserGroupInformation ugi) |
|
static void |
setShouldRenewImmediatelyForTests(boolean immediate) |
For the purposes of unit tests, we want to test login
from keytab and don't want to wait until the renew
window (controlled by TICKET_RENEW_WINDOW).
|
boolean |
shouldRelogin() |
|
java.lang.String |
toString() |
Return the username.
|
static java.lang.String |
trimLoginMethod(java.lang.String userName) |
remove the login method that is followed by a space from the username
e.g.
|
public static final java.lang.String HADOOP_TOKEN_FILE_LOCATION
public static final java.lang.String HADOOP_TOKEN
public static final java.lang.String JAVA_SECURITY_AUTH_LOGIN_CONFIG
public static final java.lang.String DEFAULT_JAVA_SECURITY_AUTH_LOGIN_CONFIG
public static final java.lang.String SCRAM_AUTH_MECHANISM
public static final java.lang.String DIGEST_AUTH_MECHANISM
@VisibleForTesting public static void setShouldRenewImmediatelyForTests(boolean immediate)
immediate - true if we should login without waiting for ticket windowpublic static void reattachMetrics()
public static boolean isInitialized()
public static UserGroupInformation.AuthenticationMethod getUGIAuthenticationMethod()
@Public @Evolving public static void setConfiguration(Configuration conf)
conf - the configuration to use@Private @VisibleForTesting public static void reset()
public static boolean isSecurityEnabled()
public boolean isLoginSuccess()
public boolean hasKerberosCredentials()
public java.util.List<RpcAuthMethod> getRpcAuthMethodList()
@Public @Evolving public static UserGroupInformation getCurrentUser() throws java.io.IOException
java.io.IOException - if login failspublic static UserGroupInformation getBestUGI(java.lang.String ticketCachePath, java.lang.String user) throws java.io.IOException
ticketCachePath - The Kerberos ticket cache path, or NULL
if none is specfieduser - The user name, or NULL if none is specified.java.io.IOException - raised on errors performing I/O.@Public @Evolving public static UserGroupInformation getUGIFromTicketCache(java.lang.String ticketCache, java.lang.String user) throws java.io.IOException
user - The principal name to load from the ticket
cacheticketCache - the path to the ticket cache filejava.io.IOException - if the kerberos login failspublic static UserGroupInformation getUGIFromSubject(javax.security.auth.Subject subject) throws java.io.IOException
subject - The KerberosPrincipal to use in UGI.
The creator of subject is responsible for
renewing credentials.java.io.IOException - raised on errors performing I/O.KerberosAuthException - if the kerberos login fails@Public @Evolving public static UserGroupInformation getLoginUser() throws java.io.IOException
java.io.IOException - if login failspublic static java.lang.String trimLoginMethod(java.lang.String userName)
userName - userName.@Public
@Evolving
public static void loginUserFromSubject(javax.security.auth.Subject subject)
throws java.io.IOException
subject - the subject to use when logging in a user, or null to
create a new subject.
If subject is not null, the creator of subject is responsible for renewing
credentials.java.io.IOException - if login fails@Private @Unstable @VisibleForTesting public static void setLoginUser(UserGroupInformation ugi)
public boolean isFromKeytab()
@Private @Unstable public boolean shouldRelogin()
@Public
@Evolving
public static void loginUserFromKeytab(java.lang.String user,
java.lang.String path)
throws java.io.IOException
user - the principal name to load from the keytabpath - the path to the keytab filejava.io.IOException - raised on errors performing I/O.KerberosAuthException - if it's a kerberos login exception.@Public
@Evolving
public void logoutUserFromKeytab()
throws java.io.IOException
loginUserFromKeytab(String, String).java.io.IOException - raised on errors performing I/O.KerberosAuthException - if a failure occurred in logout,
or if the user did not log in by invoking loginUserFromKeyTab() before.public void checkTGTAndReloginFromKeytab()
throws java.io.IOException
java.io.IOException - raised on errors performing I/O.KerberosAuthException - if it's a kerberos login exception.@Public
@Evolving
public void reloginFromKeytab()
throws java.io.IOException
loginUserFromKeytab(String, String) had
happened already.
The Subject field of this UserGroupInformation object is updated to have
the new credentials.java.io.IOException - raised on errors performing I/O.KerberosAuthException - on a failure@Public
@Evolving
public void forceReloginFromKeytab()
throws java.io.IOException
loginUserFromKeytab(String, String) had happened already. The
Subject field of this UserGroupInformation object is updated to have the
new credentials.java.io.IOException - raised on errors performing I/O.KerberosAuthException - on a failure@Public
@Evolving
public void forceReloginFromTicketCache()
throws java.io.IOException,
javax.security.auth.login.LoginException
java.io.IOException - raised on errors performing I/O.KerberosAuthException - on a failurejavax.security.auth.login.LoginException@Public
@Evolving
public void reloginFromTicketCache()
throws java.io.IOException,
javax.security.auth.login.LoginException
java.io.IOException - raised on errors performing I/O.KerberosAuthException - on a failurejavax.security.auth.login.LoginExceptionpublic static UserGroupInformation loginUserFromKeytabAndReturnUGI(java.lang.String user, java.lang.String path) throws java.io.IOException
user - the principal name to load from the keytabpath - the path to the keytab filejava.io.IOException - if the keytab file can't be read@Public
@Evolving
public static boolean isLoginKeytabBased()
throws java.io.IOException
java.io.IOException - raised on errors performing I/O.public static boolean isLoginTicketBased()
throws java.io.IOException
java.io.IOException - raised on errors performing I/O.@Public @Evolving public static UserGroupInformation createRemoteUser(java.lang.String user)
user - the full user principal name, must not be empty or null@Public @Evolving public static UserGroupInformation createRemoteUser(java.lang.String user, SaslRpcServer.AuthMethod authMethod)
user - the full user principal name, must not be empty or nullauthMethod - authMethod.@Public @Evolving public static UserGroupInformation createProxyUser(java.lang.String user, UserGroupInformation realUser)
user - user.realUser - realUser.@Public @Evolving public UserGroupInformation getRealUser()
public static UserGroupInformation getRealUserOrSelf(UserGroupInformation user)
user - the user to check@Public @Evolving public static UserGroupInformation createUserForTesting(java.lang.String user, java.lang.String[] userGroups)
user - the full user principal nameuserGroups - the names of the groups that the user belongs topublic static UserGroupInformation createProxyUserForTesting(java.lang.String user, UserGroupInformation realUser, java.lang.String[] userGroups)
user - the full user principal name for effective userrealUser - UGI of the real useruserGroups - the names of the groups that the user belongs topublic java.lang.String getShortUserName()
public java.lang.String getPrimaryGroupName()
throws java.io.IOException
java.io.IOException@Public @Evolving public java.lang.String getUserName()
public boolean addTokenIdentifier(TokenIdentifier tokenId)
tokenId - tokenIdentifier to be addedpublic java.util.Set<TokenIdentifier> getTokenIdentifiers()
public boolean addToken(Token<? extends TokenIdentifier> token)
token - Token to be addedpublic boolean addToken(Text alias, Token<? extends TokenIdentifier> token)
alias - Name of the tokentoken - Token to be addedpublic java.util.Collection<Token<? extends TokenIdentifier>> getTokens()
public Credentials getCredentials()
public void addCredentials(Credentials credentials)
credentials - of tokens and secretspublic java.lang.String[] getGroupNames()
getGroupsSet() is less
expensive alternative when checking for a contained element.@Deprecated public java.util.List<java.lang.String> getGroups()
getGroupsSet() instead.getGroupsSet() is less
expensive alternative when checking for a contained element.public java.util.Set<java.lang.String> getGroupsSet()
public java.lang.String toString()
toString in class java.lang.Objectpublic void setAuthenticationMethod(UserGroupInformation.AuthenticationMethod authMethod)
authMethod - authMethod.public void setAuthenticationMethod(SaslRpcServer.AuthMethod authMethod)
authMethod - authMethod.public UserGroupInformation.AuthenticationMethod getAuthenticationMethod()
public UserGroupInformation.AuthenticationMethod getRealAuthenticationMethod()
public static UserGroupInformation.AuthenticationMethod getRealAuthenticationMethod(UserGroupInformation ugi)
ugi - ugi.public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic javax.security.auth.Subject getSubject()
@Public @Evolving public <T> T doAs(java.security.PrivilegedAction<T> action)
T - the return type of the run methodaction - the method to execute@Public
@Evolving
public <T> T doAs(java.security.PrivilegedExceptionAction<T> action)
throws java.io.IOException,
java.lang.InterruptedException
T - the return type of the run methodaction - the method to executejava.io.IOException - if the action throws an IOExceptionjava.lang.Error - if the action throws an Errorjava.lang.RuntimeException - if the action throws a RuntimeExceptionjava.lang.InterruptedException - if the action throws an InterruptedExceptionjava.lang.reflect.UndeclaredThrowableException - if the action throws something else@LimitedPrivate({"HDFS","KMS"})
@Unstable
public static void logUserInfo(org.slf4j.Logger log,
java.lang.String caption,
UserGroupInformation ugi)
ugi - - UGIlog - log.caption - caption.@LimitedPrivate({"HDFS","KMS"})
@Unstable
public static void logAllUserInfo(org.slf4j.Logger log,
UserGroupInformation ugi)
throws java.io.IOException
ugi - - UGIlog - - log.java.io.IOException - raised on errors performing I/O.public static void logAllUserInfo(UserGroupInformation ugi) throws java.io.IOException
ugi - - UGIjava.io.IOException - raised on errors performing I/O.public static void main(java.lang.String[] args)
throws java.lang.Exception
args - if there are two arguments, read the user from the keytab
and print it out.java.lang.Exception - Exception.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.