private static void login(Configuration conf, String keytabFileKey, String userNameKey,
    String hostname, String loginContextProperty, String loginContextName) throws IOException {
    if (!isSecureZooKeeper(conf)) {
      return;
    }

    // User has specified a jaas.conf, keep this one as the good one.
    // HBASE_OPTS="-Djava.security.auth.login.config=jaas.conf"
    if (System.getProperty("java.security.auth.login.config") != null) {
      return;
    }

    // No keytab specified, no auth
    String keytabFilename = conf.get(keytabFileKey);
    if (keytabFilename == null) {
      LOG.warn("no keytab specified for: {}", keytabFileKey);
      return;
    }

    String principalConfig = conf.get(userNameKey, System.getProperty("user.name"));
    String principalName = SecurityUtil.getServerPrincipal(principalConfig, hostname);

    // Initialize the "jaas.conf" for keyTab/principal,
    // If keyTab is not specified use the Ticket Cache.
    // and set the zookeeper login context name.
    JaasConfiguration jaasConf =
      new JaasConfiguration(loginContextName, principalName, keytabFilename);
    javax.security.auth.login.Configuration.setConfiguration(jaasConf);
    System.setProperty(loginContextProperty, loginContextName);
  }
Log in the current process using the given configuration keys for the credential file and login
principal.
<p>
<strong>This is only applicable when running on secure hbase</strong> On regular HBase (without
security features), this will safely be ignored.
</p>
@param conf                 The configuration data to use
@param keytabFileKey        Property key used to configure the path to the credential file
@param userNameKey          Property key used to configure the login principal
@param hostname             Current hostname to use in any credentials
@param loginContextProperty property name to expose the entry name
@param loginContextName     jaas entry name
@throws IOException underlying exception from SecurityUtil.login() call
hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAuthentication.java