code: public static void addTokenForJob(final RestClient client, ClusterName clusterName, User user, Job job) {
          Token<EsTokenIdentifier> token = getAuthToken(clusterName, user);
          if (token == null) {
              token = obtainToken(client, user);
          }
          job.getCredentials().addToken(token.getService(), token);
      }
docs: Retrieves an authentication token from the given user, obtaining a new token if necessary,
  and adds it to the credentials for the given map reduce job.
  
  @param client The Elasticsearch client
  @param clusterName the name of the cluster you are connecting to
  @param user The user for whom to obtain the token
  @param job The job instance in which the token should be stored
  @throws IOException If making a remote call fails
  @throws InterruptedException If executing as the given user is interrupted