diff --git hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java index c0eff23..64370c8 100644 --- hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java +++ hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java @@ -475,17 +475,35 @@ private void addHBaseResources(Configuration jobConf, private void addHBaseDelegationToken(Configuration conf) throws IOException { if (User.isHBaseSecurityEnabled(conf)) { - HConnection conn = HConnectionManager.createConnection(conf); try { User curUser = User.getCurrent(); + Token authToken = getAuthToken(conf, curUser); Job job = new Job(conf); - TokenUtil.addTokenForJob(conn, curUser, job); + if (authToken == null) { + curUser.obtainAuthTokenForJob(conf,job); + } else { + job.getCredentials().addToken(authToken.getService(), authToken); + } } catch (InterruptedException e) { throw new IOException("Error while obtaining hbase delegation token", e); } - finally { - conn.close(); - } + } + } + + /** + * Get the authentication token of the user for the cluster specified in the configuration + * @return null if the user does not have the token, otherwise the auth token for the cluster. + */ + private static Token getAuthToken(Configuration conf, User user) + throws IOException, InterruptedException { + ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "mr-init-credentials", null); + try { + String clusterId = ZKClusterId.readClusterIdZNode(zkw); + return new AuthenticationTokenSelector().selectToken(new Text(clusterId), user.getUGI().getTokens()); + } catch (KeeperException e) { + throw new IOException(e); + } finally { + zkw.close(); } } diff --git pom.xml pom.xml index dd68fd5..668b28e 100644 --- pom.xml +++ pom.xml @@ -123,8 +123,8 @@ 1.2.1 2.6.0 ${basedir}/${hive.path.to.root}/testutils/hadoop - 0.98.9-hadoop1 - 0.98.9-hadoop2 + 0.98.3-hadoop1 + 0.98.3-hadoop2 4.4 4.4