MAPREDUCE服务 MRS-HBase服务数据读写示例安全认证(多集群互信场景):配置安全登录

时间:2024-06-29 14:11:13

配置安全登录

请根据实际情况,在hbase-example样例工程的“com.huawei.bigdata.hbase.examples”包的“TestMultipleLogin”类中修改“userName”为实际用户名,例如“developuser”。

private static void login(Configuration conf, String confDir) throwsIOException {      

        if (User.isHBaseSecurityEnabled(conf)) {
           userName = " developuser ";

           //In Windows environment
           String userdir = TestMain.class.getClassLoader().getResource(confDir).getPath() + File.separator;
           //In Linux environment
           //String userdir = System.getProperty("user.dir") + File.separator + confDir + File.separator;

           userKeytabFile = userdir + "user.keytab";
           krb5File = userdir + "krb5.conf";
  
           /*  

            * if need to connect zk, please provide jaas info about zk. of course,
            * you can do it as below:
            * System.setProperty("java.security.auth.login.config",confDirPath +
            * "jaas.conf"); but the demo can help you more : Note: if this process
            * will connect more than one zk cluster, the demo may be not proper. you
            * can contact us for more help
            */

            LoginUtil.setJaasConf(ZOOKEEPER_DEFAULT_ LOG IN_CONTEXT_NAME, userName,userKeytabFile);
            LoginUtil.login(userName, userKeytabFile, krb5File, conf);
        }
}
support.huaweicloud.com/devg3-mrs/mrs_07_080062.html