1919package com .dtstack .flink .sql .sink .hbase ;
2020
2121import org .apache .hadoop .conf .Configuration ;
22+ import org .apache .hadoop .security .HadoopKerberosName ;
2223import org .apache .hadoop .security .UserGroupInformation ;
24+ import org .apache .hadoop .security .authentication .util .KerberosName ;
2325import org .slf4j .Logger ;
2426import org .slf4j .LoggerFactory ;
27+ import sun .security .krb5 .Config ;
28+ import sun .security .krb5 .KrbException ;
2529
2630import java .io .IOException ;
2731
@@ -54,7 +58,11 @@ public class HbaseConfigUtils {
5458 public static final String KEY_JAVA_SECURITY_KRB5_CONF = "java.security.krb5.conf" ;
5559 public static final String KEY_ZOOKEEPER_SASL_CLIENT = "zookeeper.sasl.client" ;
5660
57- public static UserGroupInformation loginAndReturnUGI (Configuration conf , String principal , String keytab ) throws IOException {
61+ public static final String KEY_HADOOP_SECURITY_AUTHENTICATION = "hadoop.security.authentication" ;
62+ public static final String KEY_HADOOP_SECURITY_AUTH_TO_LOCAL = "hadoop.security.auth_to_local" ;
63+ public static final String KEY_HADOOP_SECURITY_AUTHORIZATION = "hadoop.security.authorization" ;
64+
65+ public static UserGroupInformation loginAndReturnUGI (Configuration conf , String principal , String keytab ) throws IOException , KrbException {
5866 LOG .info ("loginAndReturnUGI principal {}" ,principal );
5967 LOG .info ("loginAndReturnUGI keytab {}" ,keytab );
6068 if (conf == null ) {
@@ -69,7 +77,13 @@ public static UserGroupInformation loginAndReturnUGI(Configuration conf, String
6977 throw new IllegalArgumentException ("keytab can not be null" );
7078 }
7179
72- conf .set ("hadoop.security.authentication" , "Kerberos" );
80+ conf .set (KEY_HADOOP_SECURITY_AUTHENTICATION , "Kerberos" );
81+ //conf.set("hadoop.security.auth_to_local", "DEFAULT");
82+ conf .set (KEY_HADOOP_SECURITY_AUTH_TO_LOCAL , "RULE:[1:$1] RULE:[2:$1]" );
83+ conf .set (KEY_HADOOP_SECURITY_AUTHORIZATION , "true" );
84+
85+ Config .refresh ();
86+ KerberosName .resetDefaultRealm ();
7387 UserGroupInformation .setConfiguration (conf );
7488
7589 return UserGroupInformation .loginUserFromKeytabAndReturnUGI (principal , keytab );
0 commit comments