From 60e2de212ee5a545e0c21d947841dc89d7199f49 Mon Sep 17 00:00:00 2001 From: galarragas Date: Wed, 3 Sep 2014 10:40:13 +0100 Subject: Adding support for Kerberos Authentication --- .../spyglass/hbase/HBaseInputFormatBase.java | 2 +- .../spyglass/hbase/HBaseInputFormatGranular.java | 34 +++++----------- .../java/parallelai/spyglass/hbase/HBaseTap.java | 45 +++++++++++++++++----- 3 files changed, 46 insertions(+), 35 deletions(-) (limited to 'src/main/java/parallelai') diff --git a/src/main/java/parallelai/spyglass/hbase/HBaseInputFormatBase.java b/src/main/java/parallelai/spyglass/hbase/HBaseInputFormatBase.java index 6fa7fce..618bd51 100644 --- a/src/main/java/parallelai/spyglass/hbase/HBaseInputFormatBase.java +++ b/src/main/java/parallelai/spyglass/hbase/HBaseInputFormatBase.java @@ -78,7 +78,7 @@ public abstract class HBaseInputFormatBase implements InputFormat { this.tableName = tableName; } + + private void obtainToken(JobConf conf) { + if (User.isHBaseSecurityEnabled(conf)) { + String user = conf.getUser(); + LOG.info("obtaining HBase token for: {}", user); + try { + UserGroupInformation currentUser = UserGroupInformation.getCurrentUser(); + user = currentUser.getUserName(); + Credentials credentials = conf.getCredentials(); + for (Token t : currentUser.getTokens()) { + LOG.debug("Token {} is available", t); + //there must be HBASE_AUTH_TOKEN exists, if not bad thing will happen, it's must be generated when job submission. + if ("HBASE_AUTH_TOKEN".equalsIgnoreCase(t.getKind().toString())) { + credentials.addToken(t.getKind(), t); + } + } + } catch (IOException e) { + throw new RuntimeException("Unable to obtain HBase auth token for " + user, e); + } + } + } + /** * Method getTableName returns the tableName of this HBaseTap object. * @@ -153,6 +174,8 @@ public class HBaseTap extends Tap { conf.set("hbase.zookeeper.quorum", quorumNames); } + + LOG.debug("sinking to table: {}", tableName); if (isReplace() && conf.get("mapred.task.partition") == null) { @@ -179,7 +202,9 @@ public class HBaseTap extends Tap { for( SinkConfig sc : sinkConfigList) { sc.configure(conf); } - + + obtainToken(conf); + super.sinkConfInit(process, conf); } @@ -277,7 +302,9 @@ public class HBaseTap extends Tap { for( SourceConfig sc : sourceConfigList) { sc.configure(conf); } - + + obtainToken(conf); + super.sourceConfInit(process, conf); } -- cgit v1.2.3