@Public
@Evolving
public final class SecurityUtil
extends java.lang.Object
| Modifier and Type | Class | Description |
|---|---|---|
protected static class |
SecurityUtil.QualifiedHostResolver |
This an alternate resolver with important properties that the standard
java resolver lacks:
1) The hostname is fully qualified.
|
static class |
SecurityUtil.TruststoreKeystore |
Helper class to contain the Truststore/Keystore paths for the ZK client connection over
SSL/TLS.
|
| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
FAILED_TO_GET_UGI_MSG_HEADER |
|
static java.lang.String |
HOSTNAME_PATTERN |
|
static org.slf4j.Logger |
LOG |
| Modifier and Type | Method | Description |
|---|---|---|
static java.lang.String |
buildDTServiceName(java.net.URI uri,
int defPort) |
create the service name for a Delegation token
|
static Text |
buildTokenService(java.net.InetSocketAddress addr) |
Construct the service key for a token
|
static Text |
buildTokenService(java.net.URI uri) |
Construct the service key for a token
|
static <T> T |
doAsCurrentUser(java.security.PrivilegedExceptionAction<T> action) |
Perform the given action as the daemon's current user.
|
static <T> T |
doAsLoginUser(java.security.PrivilegedExceptionAction<T> action) |
Perform the given action as the daemon's login user.
|
static <T> T |
doAsLoginUserOrFatal(java.security.PrivilegedAction<T> action) |
Perform the given action as the daemon's login user.
|
static UserGroupInformation.AuthenticationMethod |
getAuthenticationMethod(Configuration conf) |
|
static java.net.InetAddress |
getByName(java.lang.String hostname) |
Resolves a host subject to the security requirements determined by
hadoop.security.token.service.use_ip.
|
static java.lang.String |
getClientPrincipal(java.lang.Class<?> protocol,
Configuration conf) |
Look up the client principal for a given protocol.
|
static java.lang.Class<? extends java.security.Principal> |
getCustomAuthPrincipal(Configuration conf) |
|
static java.lang.Class<? extends RpcAuthMethod> |
getCustomRpcAuthMethod(Configuration conf) |
|
static java.lang.String |
getHostFromPrincipal(java.lang.String principalName) |
Get the host name from the principal name of format <service
>/host@realm.
|
static KerberosInfo |
getKerberosInfo(java.lang.Class<?> protocol,
Configuration conf) |
Look up the KerberosInfo for a given protocol.
|
static org.apache.hadoop.security.authentication.client.Authenticator |
getMaprAuthenticator() |
|
static java.lang.String |
getServerPrincipal(java.lang.String principalConfig,
java.lang.String hostname) |
Convert Kerberos principal name pattern to valid Kerberos principal
names.
|
static java.lang.String |
getServerPrincipal(java.lang.String principalConfig,
java.net.InetAddress addr) |
Convert Kerberos principal name pattern to valid Kerberos principal names.
|
static TokenInfo |
getTokenInfo(java.lang.Class<?> protocol,
Configuration conf) |
Look up the TokenInfo for a given protocol.
|
static java.net.InetSocketAddress |
getTokenServiceAddr(Token<?> token) |
Decode the given token's service field into an InetAddress
|
static java.util.List<ZKUtil.ZKAuthInfo> |
getZKAuthInfos(Configuration conf,
java.lang.String configKey) |
Utility method to fetch ZK auth info from the configuration.
|
protected static boolean |
isOriginalTGT(javax.security.auth.kerberos.KerberosTicket ticket) |
Check whether the server principal is the TGS's principal
|
static boolean |
isPrivilegedPort(int port) |
|
static void |
login(Configuration conf,
java.lang.String keytabFileKey,
java.lang.String userNameKey) |
Login as a principal specified in config.
|
static void |
login(Configuration conf,
java.lang.String keytabFileKey,
java.lang.String userNameKey,
java.lang.String hostname) |
Login as a principal specified in config.
|
static void |
setAuthenticationMethod(UserGroupInformation.AuthenticationMethod authenticationMethod,
Configuration conf) |
|
static void |
setConfiguration(Configuration conf) |
|
static void |
setSecurityInfoProviders(SecurityInfo... providers) |
Test setup method to register additional providers.
|
static void |
setSslConfiguration(org.apache.zookeeper.client.ZKClientConfig zkClientConfig,
SecurityUtil.TruststoreKeystore truststoreKeystore) |
Configure ZooKeeper Client with SSL/TLS connection.
|
static void |
setSslConfiguration(org.apache.zookeeper.client.ZKClientConfig zkClientConfig,
SecurityUtil.TruststoreKeystore truststoreKeystore,
org.apache.zookeeper.common.ClientX509Util x509Util) |
|
static void |
setTokenService(Token<?> token,
java.net.InetSocketAddress addr) |
Set the given token's service to the format expected by the RPC client
|
static void |
setTokenServiceUseIp(boolean flag) |
For use only by tests and initialization.
|
static void |
validateSslConfiguration(SecurityUtil.TruststoreKeystore truststoreKeystore) |
public static final org.slf4j.Logger LOG
public static final java.lang.String HOSTNAME_PATTERN
public static final java.lang.String FAILED_TO_GET_UGI_MSG_HEADER
@Public @Evolving public static void setConfiguration(Configuration conf)
@Private @VisibleForTesting public static void setTokenServiceUseIp(boolean flag)
flag - flag.protected static boolean isOriginalTGT(javax.security.auth.kerberos.KerberosTicket ticket)
ticket - the original TGT (the ticket that is obtained when a
kinit is done)@Public
@Evolving
public static java.lang.String getServerPrincipal(java.lang.String principalConfig,
java.lang.String hostname)
throws java.io.IOException
principalConfig - the Kerberos principal name conf value to converthostname - the fully-qualified domain name used for substitutionjava.io.IOException - if the client address cannot be determined@Public
@Evolving
public static java.lang.String getServerPrincipal(java.lang.String principalConfig,
java.net.InetAddress addr)
throws java.io.IOException
getServerPrincipal(String, String),
except 1) the reverse DNS lookup from addr to hostname is done only when
necessary, 2) param addr can't be null (no default behavior of using local
hostname when addr is null).principalConfig - Kerberos principal name pattern to convertaddr - InetAddress of the host used for substitutionjava.io.IOException - if the client address cannot be determined@Public @Evolving public static void login(Configuration conf, java.lang.String keytabFileKey, java.lang.String userNameKey) throws java.io.IOException
conf - conf to usekeytabFileKey - the key to look for keytab file in confuserNameKey - the key to look for user's Kerberos principal name in confjava.io.IOException - if login fails@Public @Evolving public static void login(Configuration conf, java.lang.String keytabFileKey, java.lang.String userNameKey, java.lang.String hostname) throws java.io.IOException
conf - conf to usekeytabFileKey - the key to look for keytab file in confuserNameKey - the key to look for user's Kerberos principal name in confhostname - hostname to use for substitutionjava.io.IOException - if the config doesn't specify a keytabpublic static java.lang.String buildDTServiceName(java.net.URI uri,
int defPort)
uri - of the servicedefPort - is used if the uri lacks a portbuildTokenService(InetSocketAddress)public static java.lang.String getHostFromPrincipal(java.lang.String principalName)
principalName - principal name of format as described above@Private public static void setSecurityInfoProviders(SecurityInfo... providers)
providers - a list of high priority providers to usepublic static KerberosInfo getKerberosInfo(java.lang.Class<?> protocol, Configuration conf)
protocol - the protocol class to get the information forconf - configuration objectpublic static java.lang.String getClientPrincipal(java.lang.Class<?> protocol,
Configuration conf)
protocol - the protocol class to get the information forconf - configuration objectpublic static TokenInfo getTokenInfo(java.lang.Class<?> protocol, Configuration conf)
protocol - The protocol class to get the information for.conf - Configuration objectpublic static java.net.InetSocketAddress getTokenServiceAddr(Token<?> token)
token - from which to obtain the servicepublic static void setTokenService(Token<?> token, java.net.InetSocketAddress addr)
token - a delegation tokenaddr - the socket for the rpc connectionpublic static Text buildTokenService(java.net.InetSocketAddress addr)
addr - InetSocketAddress of remote connection with a tokenpublic static Text buildTokenService(java.net.URI uri)
uri - of remote connection with a tokenpublic static <T> T doAsLoginUserOrFatal(java.security.PrivilegedAction<T> action)
T - generic type T.action - action.public static <T> T doAsLoginUser(java.security.PrivilegedExceptionAction<T> action)
throws java.io.IOException
T - Generics Type T.action - the action to performjava.io.IOException - in the event of errorpublic static <T> T doAsCurrentUser(java.security.PrivilegedExceptionAction<T> action)
throws java.io.IOException
T - generic type T.action - the action to performjava.io.IOException - in the event of error@Private
public static java.net.InetAddress getByName(java.lang.String hostname)
throws java.net.UnknownHostException
hostname - host or ip to resolvejava.net.UnknownHostException - if the host doesn't existpublic static UserGroupInformation.AuthenticationMethod getAuthenticationMethod(Configuration conf)
public static void setAuthenticationMethod(UserGroupInformation.AuthenticationMethod authenticationMethod, Configuration conf)
public static boolean isPrivilegedPort(int port)
public static java.util.List<ZKUtil.ZKAuthInfo> getZKAuthInfos(Configuration conf, java.lang.String configKey) throws java.io.IOException
conf - configuration.configKey - config key.java.io.IOException - if the Zookeeper ACLs configuration file
cannot be readZKUtil.BadAuthFormatException - if the auth format is invalidpublic static void validateSslConfiguration(SecurityUtil.TruststoreKeystore truststoreKeystore) throws javax.naming.ConfigurationException
javax.naming.ConfigurationExceptionpublic static void setSslConfiguration(org.apache.zookeeper.client.ZKClientConfig zkClientConfig,
SecurityUtil.TruststoreKeystore truststoreKeystore)
throws javax.naming.ConfigurationException
zkClientConfig - ZooKeeper Client configurationtruststoreKeystore - truststore keystore, that we use to set the SSL configurationsjavax.naming.ConfigurationException - if the SSL configs are emptypublic static void setSslConfiguration(org.apache.zookeeper.client.ZKClientConfig zkClientConfig,
SecurityUtil.TruststoreKeystore truststoreKeystore,
org.apache.zookeeper.common.ClientX509Util x509Util)
throws javax.naming.ConfigurationException
javax.naming.ConfigurationExceptionpublic static java.lang.Class<? extends java.security.Principal> getCustomAuthPrincipal(Configuration conf)
public static java.lang.Class<? extends RpcAuthMethod> getCustomRpcAuthMethod(Configuration conf)
public static org.apache.hadoop.security.authentication.client.Authenticator getMaprAuthenticator()
throws java.lang.InstantiationException,
java.lang.IllegalAccessException
java.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionCopyright © 2008–2025 Apache Software Foundation. All rights reserved.