Skip to content

Commit

Permalink
add utils for reflection and deal with IBM JDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadoop committed Dec 23, 2024
1 parent 35bcaa0 commit 7be5ca0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
import org.apache.amoro.shade.guava32.com.google.common.hash.Hashing;
import org.apache.amoro.shade.guava32.com.google.common.io.ByteStreams;
import org.apache.amoro.utils.ReflectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -413,9 +414,11 @@ private void constructKerberosUgi() throws Exception {
String keyTabFile = saveConfInPath(confPath, KEY_TAB_FILE_NAME, krbKeyTab);
System.clearProperty(HADOOP_USER_PROPERTY);
System.setProperty(KRB5_CONF_PROPERTY, krbConfFile);
Class<?> classRef = Class.forName("sun.security.krb5.Config");
Method method = classRef.getDeclaredMethod("refresh");
method.invoke(null);
if (System.getProperty("java.vendor").contains("IBM")) {
ReflectionUtils.invoke("com.ibm.security.krb5.internal.Config","refresh");
} else {
ReflectionUtils.invoke("sun.security.krb5.Config","refresh");
}
UserGroupInformation.setConfiguration(getConfiguration());
KerberosName.resetDefaultRealm();
this.ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(krbPrincipal, keyTabFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.apache.amoro.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class ReflectionUtils {

private final static Map<String,Class> CLASS_MAP = new HashMap<>();

public static Object invoke(String className, String methodName) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
Class<?> classRef = CLASS_MAP.computeIfAbsent(className, key-> {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
});
Method method = classRef.getDeclaredMethod(methodName);
return method.invoke(null);
}
}

0 comments on commit 7be5ca0

Please sign in to comment.