Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] refactor krb5 avoid starting error in idea #3377

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.hadoop.security.authentication.util.KerberosName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.security.krb5.KrbException;

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
Expand All @@ -44,6 +43,7 @@
import java.io.UncheckedIOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
Expand Down Expand Up @@ -383,7 +383,7 @@ public UserGroupInformation getUGI() {
constructKerberosUgi();
}
LOG.info("Completed to build ugi {}", authInformation());
} catch (IOException | KrbException e) {
} catch (Exception e) {
throw new RuntimeException("Fail to init user group information", e);
}
} else {
Expand All @@ -407,13 +407,15 @@ public UserGroupInformation getUGI() {
return ugi;
}

private void constructKerberosUgi() throws IOException, KrbException {
private void constructKerberosUgi() throws Exception {
Path confPath = generateKrbConfPath();
String krbConfFile = saveConfInPath(confPath, KRB_CONF_FILE_NAME, krbConf);
String keyTabFile = saveConfInPath(confPath, KEY_TAB_FILE_NAME, krbKeyTab);
System.clearProperty(HADOOP_USER_PROPERTY);
System.setProperty(KRB5_CONF_PROPERTY, krbConfFile);
sun.security.krb5.Config.refresh();
Class<?> classRef = Class.forName("sun.security.krb5.Config");
ihadoop marked this conversation as resolved.
Show resolved Hide resolved
Method method = classRef.getDeclaredMethod("refresh");
method.invoke(null);
UserGroupInformation.setConfiguration(getConfiguration());
KerberosName.resetDefaultRealm();
this.ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(krbPrincipal, keyTabFile);
Expand Down
Loading