public static UserGroupInformation loginWithKerberos(
    String principal, String keytabFile) throws IOException {
    if (!UserGroupInformation.isSecurityEnabled()) {
      return null;
    }
    if (principal == null || principal.isEmpty() || keytabFile == null || keytabFile.isEmpty()) {
      throw new RuntimeException("Kerberos principal and/or keytab are null or empty");
    }
    final String serverPrincipal = SecurityUtil.getServerPrincipal(principal, "0.0.0.0");
    LOG.info("Logging in as " + serverPrincipal + " via " + keytabFile);
    return UserGroupInformation.loginUserFromKeytabAndReturnUGI(serverPrincipal, keytabFile);
  }
Login using kerberos. But does not change the current logged in user.

@param principal  - kerberos principal
@param keytabFile - keytab file
@return UGI
@throws IOException - if keytab file cannot be found
llap-common/src/java/org/apache/hadoop/hive/llap/LlapUtil.java