Skip to content

Commit

Permalink
[SPARK-46562][SQL] Remove retrieval of keytabFile from `UserGroupIn…
Browse files Browse the repository at this point in the history
…formation` in `HiveAuthFactory`

### What changes were proposed in this pull request?
This pr removed the retrieval of `keytabFile` from `UserGroupInformation` in `HiveAuthFactory` because `keytabFile` no longer exists in `UserGroupInformation` after Hadoop 3.0.3. Therefore, in `HiveAuthFactory`, `keytabFile` will always be null and in `HiveAuthFactory`, `keytabFile` will only be used when it is not null.

For the specific changes in Hadoop, please refer to https://issues.apache.org/jira/browse/HADOOP-9747 | apache/hadoop@59cf758.

### Why are the changes needed?
Clean up the invalid code.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#44557 from LuciferYang/remove-keytabFile.

Authored-by: yangjie01 <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
  • Loading branch information
LuciferYang authored and dongjoon-hyun committed Jan 2, 2024
1 parent 4ab5197 commit bc7e949
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.hive.service.auth;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -85,18 +84,9 @@ public String getAuthName() {
public static final String HS2_PROXY_USER = "hive.server2.proxy.user";
public static final String HS2_CLIENT_TOKEN = "hiveserver2ClientToken";

private static Field keytabFile = null;
private static Method getKeytab = null;
static {
Class<?> clz = UserGroupInformation.class;
try {
keytabFile = clz.getDeclaredField("keytabFile");
keytabFile.setAccessible(true);
} catch (NoSuchFieldException nfe) {
LOG.debug("Cannot find private field \"keytabFile\" in class: " +
UserGroupInformation.class.getCanonicalName(), nfe);
keytabFile = null;
}

try {
getKeytab = clz.getDeclaredMethod("getKeytab");
Expand Down Expand Up @@ -347,9 +337,7 @@ public static boolean needUgiLogin(UserGroupInformation ugi, String principal, S
private static String getKeytabFromUgi() {
synchronized (UserGroupInformation.class) {
try {
if (keytabFile != null) {
return (String) keytabFile.get(null);
} else if (getKeytab != null) {
if (getKeytab != null) {
return (String) getKeytab.invoke(UserGroupInformation.getCurrentUser());
} else {
return null;
Expand Down

0 comments on commit bc7e949

Please sign in to comment.