code: public static Credentials obtainToken(Configuration hConf, Credentials credentials) {
      if (!User.isHBaseSecurityEnabled(hConf)) {
        return credentials;
      }
  
      try {
        Class c = Class.forName("org.apache.hadoop.hbase.security.token.TokenUtil");
        Method method = c.getMethod("obtainToken", Configuration.class);
  
        Token<? extends TokenIdentifier> token = castToken(method.invoke(null, hConf));
        credentials.addToken(token.getService(), token);
  
        return credentials;
  
      } catch (Exception e) {
        LOG.error("Failed to get secure token for HBase.", e);
        throw Throwables.propagate(e);
      }
    }
docs: Gets a HBase delegation token and stores it in the given Credentials.
  
  @return the same Credentials instance as the one given in parameter.