Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Do we have java API for HBase access control?

Do we have java API for HBase access control?

Rising Star

I would like to grant permission to HBase table using java API. is there any java api available for HBase 1.1.2 ?

3 REPLIES 3

Re: Do we have java API for HBase access control?

Mentor

Yes there is, from reference guide http://hbase.apache.org/book/hbase.accesscontrol.configuration.html

public static void grantOnTable(final HBaseTestingUtility util, final String user,
    final TableName table, final byte[] family, final byte[] qualifier,
    final Permission.Action... actions) throws Exception {
  SecureTestUt

il.updateACLs(util, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      Configuration conf = HBaseConfiguration.create();
      Connection connection = ConnectionFactory.createConnection(conf);
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table table = connection.getTable(TableName.valueOf(tablename)) {
          AccessControlLists.ACL_TABLE_NAME);
          try {
            BlockingRpcChannel service = acl.coprocessorService(HConstants.EMPTY_START_ROW);
            AccessControlService.BlockingInterface protocol =
                AccessControlService.newBlockingStub(service);
            ProtobufUtil.grant(protocol, user, table, family, qualifier, actions);
          } finally {
            acl.close();
          }
          return null;
        }
      }
    }
  }
}
Highlighted

Re: Do we have java API for HBase access control?

Guru

Thanks Artem. This is still a little bit low level. You can use

org.apache.hadoop.hbase.security.access.AccessControlClient as a client-facing API to grant / revoke at a higher level.

Re: Do we have java API for HBase access control?

New Contributor

An alternate option would be to leverage the Ranger REST API which can be called from a Java app.

You can find information about the Ranger REST API, which allows for the creation of Security Policies for Hive, HDFS and HBase among other HDP components:

https://cwiki.apache.org/confluence/display/RANGER/REST+APIs+for+Service+Definition%2C+Service+and+P...

There are many tutorials available for invoking REST APIs from Java.

The following example provides some clear directions for working with REST APIs and JSON content in Java:

https://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

Don't have an account?
Coming from Hortonworks? Activate your account here