static Subject getSubject() throws Exception {
    if (!secure) {
      return new Subject();
    }

    /*
     * To authenticate the DemoClient, kinit should be invoked ahead. Here we try to get the
     * Kerberos credential from the ticket cache.
     */
    LoginContext context;

    if (keyTab != null) {
      // To authenticate the HttpDoAsClient using principal and keyTab
      Set<Principal> principals = new HashSet<>();
      principals.add(new KerberosPrincipal(principal));
      Subject subject = new Subject(false, principals, new HashSet<>(), new HashSet<>());

      context = new LoginContext("", subject, null, new KerberosConfiguration(principal, keyTab));
    } else {
      /*
       * To authenticate the HttpDoAsClient, kinit should be invoked ahead. Here we try to get the
       * Kerberos credential from the ticket cache.
       */
      context = new LoginContext("", new Subject(), null, new KerberosConfiguration());
    }
    context.login();
    return context.getSubject();
  }
See the instructions under hbase-examples/README.txt
hbase-examples/src/main/java/org/apache/hadoop/hbase/thrift/HttpDoAsClient.java