public static void obtainTokenForJob(final Connection conn, final JobConf job, User user)
    throws IOException, InterruptedException {
    try {
      Token<AuthenticationTokenIdentifier> token = ClientTokenUtil.obtainToken(conn, user);

      if (token == null) {
        throw new IOException("No token returned for user " + user.getName());
      }
      Text clusterId = getClusterId(token);
      if (LOG.isDebugEnabled()) {
        LOG.debug("Obtained token " + token.getKind().toString() + " for user " + user.getName()
          + " on cluster " + clusterId.toString());
      }
      job.getCredentials().addToken(clusterId, token);
    } catch (IOException ioe) {
      throw ioe;
    } catch (InterruptedException ie) {
      throw ie;
    } catch (RuntimeException re) {
      throw re;
    } catch (Exception e) {
      throw new UndeclaredThrowableException(e,
        "Unexpected exception obtaining token for user " + user.getName());
    }
  }
Obtain an authentication token on behalf of the given user and add it to the credentials for
the given map reduce job.
@param conn The HBase cluster connection
@param user The user for whom to obtain the token
@param job  The job configuration in which the token should be stored
@throws IOException          If making a remote call to the authentication service fails
@throws InterruptedException If executing as the given user is interrupted
hbase-server/src/main/java/org/apache/hadoop/hbase/security/token/TokenUtil.java