Package org.apache.nifi.hadoop
Class SecurityUtil
java.lang.Object
org.apache.nifi.hadoop.SecurityUtil
Provides synchronized access to UserGroupInformation to avoid multiple processors/services from
interfering with each other.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcallWithUgi(org.apache.hadoop.security.UserGroupInformation ugi, PrivilegedExceptionAction<T> action) Helper method to execute the given action as the given user.static voidcheckTGTAndRelogin(org.apache.nifi.logging.ComponentLog log, KerberosUser kerberosUser) Helper method to call checkTGTAndRelogin on a given KerberosUser that may be null.static org.apache.hadoop.security.UserGroupInformationgetUgiForKerberosUser(org.apache.hadoop.conf.Configuration config, KerberosUser kerberosUser) Authenticates aKerberosUserand acquires aUserGroupInformationinstance usingUserGroupInformation.getUGIFromSubject(Subject).static booleanisSecurityEnabled(org.apache.hadoop.conf.Configuration config) Initializes UserGroupInformation with the given Configuration and returns UserGroupInformation.isSecurityEnabled().static org.apache.hadoop.security.UserGroupInformationloginKerberos(org.apache.hadoop.conf.Configuration config, String principal, String keyTab) Initializes UserGroupInformation with the given Configuration and performs the login for the given principal and keytab.static org.apache.hadoop.security.UserGroupInformationloginSimple(org.apache.hadoop.conf.Configuration config) Initializes UserGroupInformation with the given Configuration and returns UserGroupInformation.getLoginUser().
-
Field Details
-
HADOOP_SECURITY_AUTHENTICATION
- See Also:
-
KERBEROS
- See Also:
-
-
Constructor Details
-
SecurityUtil
public SecurityUtil()
-
-
Method Details
-
loginKerberos
public static org.apache.hadoop.security.UserGroupInformation loginKerberos(org.apache.hadoop.conf.Configuration config, String principal, String keyTab) throws IOException Initializes UserGroupInformation with the given Configuration and performs the login for the given principal and keytab. All logins should happen through this class to ensure other threads are not concurrently modifying UserGroupInformation. As of Apache NiFi 1.5.0, this method usesUserGroupInformation.loginUserFromKeytab(String, String)to authenticate the givenprincipal, which sets the static variableloginUserin theUserGroupInformationinstance. callsUserGroupInformation.getLoginUser().reloginFromKeytab()statically, which can return null ifloginUseris not set, resulting in failure of the hadoop operation.- Parameters:
config- the configuration instanceprincipal- the principal to authenticate askeyTab- the keytab to authenticate with- Returns:
- the UGI for the given principal
- Throws:
IOException- if login failed
-
getUgiForKerberosUser
public static org.apache.hadoop.security.UserGroupInformation getUgiForKerberosUser(org.apache.hadoop.conf.Configuration config, KerberosUser kerberosUser) throws IOException Authenticates aKerberosUserand acquires aUserGroupInformationinstance usingUserGroupInformation.getUGIFromSubject(Subject). TheUserGroupInformationwill use the givenConfiguration.- Parameters:
config- The Configuration to apply to the acquired UserGroupInformation instancekerberosUser- The KerberosUser to authenticate- Returns:
- A UserGroupInformation instance created using the Subject of the given KerberosUser
- Throws:
IOException- if authentication fails
-
loginSimple
public static org.apache.hadoop.security.UserGroupInformation loginSimple(org.apache.hadoop.conf.Configuration config) throws IOException Initializes UserGroupInformation with the given Configuration and returns UserGroupInformation.getLoginUser(). All logins should happen through this class to ensure other threads are not concurrently modifying UserGroupInformation.- Parameters:
config- the configuration instance- Returns:
- the UGI for the given principal
- Throws:
IOException- if login failed
-
isSecurityEnabled
public static boolean isSecurityEnabled(org.apache.hadoop.conf.Configuration config) Initializes UserGroupInformation with the given Configuration and returns UserGroupInformation.isSecurityEnabled(). All checks for isSecurityEnabled() should happen through this method.- Parameters:
config- the given configuration- Returns:
- true if kerberos is enabled on the given configuration, false otherwise
-
callWithUgi
public static <T> T callWithUgi(org.apache.hadoop.security.UserGroupInformation ugi, PrivilegedExceptionAction<T> action) throws IOException Helper method to execute the given action as the given user.- Type Parameters:
T- the result type of the action- Parameters:
ugi- the useraction- the action- Returns:
- the result of the action
- Throws:
IOException- if the action was interrupted
-
checkTGTAndRelogin
public static void checkTGTAndRelogin(org.apache.nifi.logging.ComponentLog log, KerberosUser kerberosUser) Helper method to call checkTGTAndRelogin on a given KerberosUser that may be null.- Parameters:
log- the loggerkerberosUser- the kerberos user- Throws:
KerberosLoginException- if an error occurs when checkTGTAndRelogin calls login or logout
-