public static UserGroupInformation loginAndReturnUGI2(Configuration conf, String principal, String keytab) throws IOException, KrbException {
        LOG.info("loginAndReturnUGI principal {}",principal);
        LOG.info("loginAndReturnUGI keytab {}",keytab);
        if (conf == null) {
            throw new IllegalArgumentException("kerberos conf can not be null");
        }

        if (org.apache.commons.lang.StringUtils.isEmpty(principal)) {
            throw new IllegalArgumentException("principal can not be null");
        }

        if (org.apache.commons.lang.StringUtils.isEmpty(keytab)) {
            throw new IllegalArgumentException("keytab can not be null");
        }

        if (!new File(keytab).exists()){
            throw new IllegalArgumentIOException("keytab ["+ keytab + "] not exist");
        }

        conf.set(KEY_HADOOP_SECURITY_AUTHENTICATION, "Kerberos");
        //conf.set("hadoop.security.auth_to_local", "DEFAULT");
        conf.set(KEY_HADOOP_SECURITY_AUTH_TO_LOCAL, "RULE:[1:$1] RULE:[2:$1]");
        conf.set(KEY_HADOOP_SECURITY_AUTHORIZATION, "true");

        Config.refresh();
        KerberosName.resetDefaultRealm();
        UserGroupInformation.setConfiguration(conf);

        return UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab);
    }
The utility class of HBase connection

Date: 2019/12/24
Company: www.dtstack.com
@author maqi
hbase/hbase-side/hbase-side-core/src/main/java/com/dtstack/flink/sql/side/hbase/utils/HbaseConfigUtils.java