@@ -53,6 +53,7 @@ public class HbaseHelper {
5353 private final static String AUTHENTICATION_TYPE = "Kerberos" ;
5454 private final static String KEY_HBASE_SECURITY_AUTHENTICATION = "hbase.security.authentication" ;
5555 private final static String KEY_HBASE_SECURITY_AUTHORIZATION = "hbase.security.authorization" ;
56+ private final static String KEY_HBASE_SECURITY_AUTH_ENABLE = "hbase.security.auth.enable" ;
5657
5758 public static org .apache .hadoop .hbase .client .Connection getHbaseConnection (Map <String ,Object > hbaseConfigMap ) {
5859 Validate .isTrue (MapUtils .isNotEmpty (hbaseConfigMap ), "hbaseConfig不能为空Map结构!" );
@@ -72,6 +73,7 @@ public static org.apache.hadoop.hbase.client.Connection getHbaseConnection(Map<S
7273
7374 private static org .apache .hadoop .hbase .client .Connection getConnectionWithKerberos (Map <String ,Object > hbaseConfigMap ){
7475 try {
76+ setKerberosConf (hbaseConfigMap );
7577 UserGroupInformation ugi = getUgi (hbaseConfigMap );
7678 return ugi .doAs (new PrivilegedAction <Connection >() {
7779 @ Override
@@ -118,11 +120,25 @@ public static Configuration getConfig(Map<String,Object> hbaseConfigMap){
118120 }
119121
120122 public static boolean openKerberos (Map <String ,Object > hbaseConfigMap ){
121- if (!MapUtils .getBooleanValue (hbaseConfigMap , KEY_HBASE_SECURITY_AUTHORIZATION )){
122- return false ;
123+ if (AUTHENTICATION_TYPE .equalsIgnoreCase (MapUtils .getString (hbaseConfigMap , KEY_HBASE_SECURITY_AUTHORIZATION ))
124+ || AUTHENTICATION_TYPE .equalsIgnoreCase (MapUtils .getString (hbaseConfigMap , KEY_HBASE_SECURITY_AUTHENTICATION ))
125+ || MapUtils .getBooleanValue (hbaseConfigMap , KEY_HBASE_SECURITY_AUTH_ENABLE )){
126+ LOG .info ("open kerberos for hbase." );
127+ return true ;
123128 }
124129
125- return AUTHENTICATION_TYPE .equalsIgnoreCase (MapUtils .getString (hbaseConfigMap , KEY_HBASE_SECURITY_AUTHENTICATION ));
130+ return false ;
131+ }
132+
133+
134+ /**
135+ * 设置hbase 开启kerberos 连接必要的固定参数
136+ * @param hbaseConfigMap
137+ */
138+ public static void setKerberosConf (Map <String ,Object > hbaseConfigMap ){
139+ hbaseConfigMap .put (KEY_HBASE_SECURITY_AUTHORIZATION , AUTHENTICATION_TYPE );
140+ hbaseConfigMap .put (KEY_HBASE_SECURITY_AUTHENTICATION , AUTHENTICATION_TYPE );
141+ hbaseConfigMap .put (KEY_HBASE_SECURITY_AUTH_ENABLE , true );
126142 }
127143
128144 public static RegionLocator getRegionLocator (Connection hConnection , String userTable ){
0 commit comments