java:使用rest客户端连接到hbase时出现authenticationexception

piwo6bdm  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(333)

我正在尝试使用java hbase rest客户端连接hbase。但是它给出了以下错误。
hbase rest使用kerberos身份验证,因此我创建了一个kerberos票证并尝试使用这个票证进行身份验证。
代码:

public class RestExample {

    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        conf.addResource("src/main/resources/hbase-site.xml");
        conf.addResource("src/main/resources/core-site.xml");
        conf.addResource("src/main/resources/hdfs-site.xml");

        System.setProperty("java.security.krb5.conf", "src/main/resources/krb5.conf");
        System.setProperty("sun.security.krb5.debug", "true");

        UserGroupInformation.setConfiguration(conf);
        String projectDir = System.getProperty("user.dir");
        System.out.println(projectDir);
        UserGroupInformation.loginUserFromKeytab("gaurang.shah@mydomain.com", "src/main/resources/gaurang.shah.keytab");
        // vv RestExample
        Cluster cluster = new Cluster();
        cluster.add("hbase_host.mydomain.com", 17000); 

        Client client = new Client(cluster); 

        TableName tableName = TableName.valueOf("bda:aaa");

        RemoteAdmin remoteAdmin = new RemoteAdmin(client, conf);
        HTableDescriptor tableDesc = new HTableDescriptor(tableName);
        remoteAdmin.createTable(tableDesc);
    }
}

堆栈跟踪:

Exception in thread "main" java.io.IOException: org.apache.hadoop.security.authentication.client.AuthenticationException: Authentication failed, URL: http://hbase_host.mydomain.com:17000/bda:aaa/schema?user.name=gaurang.shah, status: 403, message: Forbidden
    at org.apache.hadoop.hbase.rest.client.Client.negotiate(Client.java:285)
    at org.apache.hadoop.hbase.rest.client.Client.executeURI(Client.java:239)
    at org.apache.hadoop.hbase.rest.client.Client.executePathOnly(Client.java:204)
    at org.apache.hadoop.hbase.rest.client.Client.execute(Client.java:265)
    at org.apache.hadoop.hbase.rest.client.Client.put(Client.java:557)
    at org.apache.hadoop.hbase.rest.client.Client.put(Client.java:504)
    at org.apache.hadoop.hbase.rest.client.Client.put(Client.java:474)
    at org.apache.hadoop.hbase.rest.client.RemoteAdmin.createTable(RemoteAdmin.java:294)
    at ca.cantire.RestExample.main(RestExample.java:42)
Caused by: org.apache.hadoop.security.authentication.client.AuthenticationException: Authentication failed, URL: http://hbase_host.mydomain.com:17000/bda:aaa/schema?user.name=gaurang.shah, status: 403, message: Forbidden
    at org.apache.hadoop.security.authentication.client.AuthenticatedURL.extractToken(AuthenticatedURL.java:281)
    at org.apache.hadoop.security.authentication.client.PseudoAuthenticator.authenticate(PseudoAuthenticator.java:77)
    at org.apache.hadoop.security.authentication.client.KerberosAuthenticator.authenticate(KerberosAuthenticator.java:212)

  at org.apache.hadoop.hbase.rest.client.Client.negotiate(Client.java:280)
    ... 8 more

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题