|
|
@ -18,8 +18,11 @@ import org.apache.hadoop.hdfs.DistributedFileSystem; |
|
|
|
import org.apache.hadoop.security.AnnotatedSecurityInfo; |
|
|
|
import org.apache.hadoop.security.AnnotatedSecurityInfo; |
|
|
|
import org.apache.hadoop.security.SecurityUtil; |
|
|
|
import org.apache.hadoop.security.SecurityUtil; |
|
|
|
import org.apache.hadoop.security.UserGroupInformation; |
|
|
|
import org.apache.hadoop.security.UserGroupInformation; |
|
|
|
|
|
|
|
import org.apache.hadoop.security.authentication.util.KerberosName; |
|
|
|
|
|
|
|
import org.apache.hadoop.security.authentication.util.KerberosUtil; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
|
|
|
|
|
|
|
@ -86,11 +89,12 @@ public class HDFSRepositoryFactory extends ConfigRepositoryFactory<HDFSConfig> { |
|
|
|
String hdfsUrl = HDFS_SCHEMA.concat(host).concat(":").concat(port); |
|
|
|
String hdfsUrl = HDFS_SCHEMA.concat(host).concat(":").concat(port); |
|
|
|
String principal = config.getPrincipal(); |
|
|
|
String principal = config.getPrincipal(); |
|
|
|
String krb5Conf = config.getKrbConf(); |
|
|
|
String krb5Conf = config.getKrbConf(); |
|
|
|
|
|
|
|
String keyTab = config.getKeyTab(); |
|
|
|
|
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] Host:{}", host); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] Host:{}", host); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] Port:{}", port); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] Port:{}", port); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] Principal:{}", principal); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] Principal:{}", principal); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] KeyTab:{}", config.getKeyTab()); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] KeyTab:{}", keyTab); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] krb5.conf:{}", krb5Conf); |
|
|
|
FineLoggerFactory.getLogger().debug("[HDFS REPOSITORY] krb5.conf:{}", krb5Conf); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -108,9 +112,16 @@ public class HDFSRepositoryFactory extends ConfigRepositoryFactory<HDFSConfig> { |
|
|
|
//类似OSGI下,类加载需要设置SecurityUtil.setSecurityInfoProviders(new AnnotatedSecurityInfo());
|
|
|
|
//类似OSGI下,类加载需要设置SecurityUtil.setSecurityInfoProviders(new AnnotatedSecurityInfo());
|
|
|
|
//refer to https://stackoverflow.com/questions/37608049/how-to-connect-with-hdfs-via-kerberos-from-osgi-bundles
|
|
|
|
//refer to https://stackoverflow.com/questions/37608049/how-to-connect-with-hdfs-via-kerberos-from-osgi-bundles
|
|
|
|
SecurityUtil.setSecurityInfoProviders(new AnnotatedSecurityInfo()); |
|
|
|
SecurityUtil.setSecurityInfoProviders(new AnnotatedSecurityInfo()); |
|
|
|
//UserGroupInformation初始化
|
|
|
|
|
|
|
|
|
|
|
|
//重置defaultRealm,hadoop2.7以前没有提供resetDefaultRealm方法,需要反射设置一下这个变量,否则无法登录
|
|
|
|
|
|
|
|
Field field = KerberosName.class.getDeclaredField("defaultRealm"); |
|
|
|
|
|
|
|
assert field != null; |
|
|
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
|
|
field.set(KerberosName.class, KerberosUtil.getDefaultRealm()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//UserGroupInformation初始化和登录验证
|
|
|
|
UserGroupInformation.setConfiguration(conf); |
|
|
|
UserGroupInformation.setConfiguration(conf); |
|
|
|
UserGroupInformation.loginUserFromKeytab(principal, config.getKeyTab()); |
|
|
|
UserGroupInformation.loginUserFromKeytab(principal, keyTab); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|