code: public static void initCredentials(JobConf jobConf) {
          Settings settings = HadoopSettingsManager.loadFrom(jobConf);
          InitializationUtils.setUserProviderIfNotSet(settings, HadoopUserProvider.class, LOG);
          UserProvider userProvider = UserProvider.create(settings);
  
          if (userProvider.isEsKerberosEnabled()) {
              User user = userProvider.getUser();
              ClusterInfo clusterInfo = settings.getClusterInfoOrNull();
              RestClient bootstrap = new RestClient(settings);
              try {
                  // first get ES main action info if it's missing
                  if (clusterInfo == null) {
                      clusterInfo = bootstrap.mainInfo();
                  }
                  // Add the token to the job
                  TokenUtil.addTokenForJobConf(bootstrap, clusterInfo.getClusterName(), user, jobConf);
              } catch (EsHadoopException ex) {
                  throw new EsHadoopIllegalArgumentException(String.format("Cannot detect ES version - "
                          + "typically this happens if the network/Elasticsearch cluster is not accessible or when targeting "
                          + "a WAN/Cloud instance without the proper setting '%s'", ConfigurationOptions.ES_NODES_WAN_ONLY), ex);
              } finally {
                  bootstrap.close();
              }
          } else {
              if (LOG.isDebugEnabled()) {
                  LOG.debug("Ignoring Elasticsearch credentials since Kerberos Auth is not enabled.");
              }
          }
      }
docs: Given the settings contained within the job conf, retrieve an authentication token from either the currently logged in
  user or from the Elasticsearch cluster and add it to the job's credential set.
  @param jobConf containing the settings to connect to Elasticsearch, as well as for storing the authentication token