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

      if (token == null) {
        throw new IOException("No token returned for user " + user.getName());
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Obtained token " + token.getKind().toString() + " for user " + user.getName());
      }
      user.addToken(token);
    } catch (IOException | InterruptedException | RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new UndeclaredThrowableException(e,
        "Unexpected exception obtaining token for user " + user.getName());
    }
  }
Obtain an authentication token for the given user and add it to the user's credentials.
@param conn The HBase cluster connection
@param user The user for whom to obtain the token
@throws IOException          If making a remote call to the authentication service fails
@throws InterruptedException If executing as the given user is interrupted
hbase-client/src/main/java/org/apache/hadoop/hbase/security/token/ClientTokenUtil.java