Before getting into the code, it is important to generate necessary files. If a key tab is not available follow the steps below to create one. In the example below, a key tab for the user jj and realm EXAMPLE.COM is created. The below commands should be run on one of the nodes in the cluster.
Once the files have been obtained, please move them to the following directory.
For testing, it is recommended to change 'hbase.client.retries.number' property in hbase-site.xml. By default it is 35. This is quite high when running some tests.
The First thing that needs to be done is to create and load the HBase configuration.
// Setting up the HBase configuration
Configuration configuration = new Configuration();
Next point to the krb5.conf file and setup the kerberos principal and keytab.
// Point to the krb5.conf file.
// Override these values by setting -DkerberosPrincipal and/or -DkerberosKeytab
String principal = System.getProperty("kerberosPrincipal", "jj@EXAMPLE.COM");
String keytabLocation = System.getProperty("kerberosKeytab", "src/main/resources/jj.keytab");
Now login with the principal and keytab defined above.