org.apache.hadoop.hbase.security.token.TokenUtil Java Examples
The following examples show how to use
org.apache.hadoop.hbase.security.token.TokenUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableMapReduceUtil.java From hbase with Apache License 2.0 | 6 votes |
public static void initCredentials(JobConf job) throws IOException { UserProvider userProvider = UserProvider.instantiate(job); if (userProvider.isHadoopSecurityEnabled()) { // propagate delegation related props from launcher job to MR job if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { job.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } } if (userProvider.isHBaseSecurityEnabled()) { Connection conn = ConnectionFactory.createConnection(job); try { // login the server principal (if using secure Hadoop) User user = userProvider.getCurrent(); TokenUtil.addTokenForJob(conn, job, user); } catch (InterruptedException ie) { LOG.error("Interrupted obtaining user authentication token", ie); Thread.currentThread().interrupt(); } finally { conn.close(); } } }
Example #2
Source File: TableMapReduceUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * Obtain an authentication token, for the specified cluster, on behalf of the current user * and add it to the credentials for the given map reduce job. * * @param job The job that requires the permission. * @param conf The configuration to use in connecting to the peer cluster * @throws IOException When the authentication token cannot be obtained. */ public static void initCredentialsForCluster(Job job, Configuration conf) throws IOException { UserProvider userProvider = UserProvider.instantiate(job.getConfiguration()); if (userProvider.isHBaseSecurityEnabled()) { try { Connection peerConn = ConnectionFactory.createConnection(conf); try { TokenUtil.addTokenForJob(peerConn, userProvider.getCurrent(), job); } finally { peerConn.close(); } } catch (InterruptedException e) { LOG.info("Interrupted obtaining user authentication token"); Thread.interrupted(); } } }
Example #3
Source File: TableMapReduceUtil.java From hbase with Apache License 2.0 | 5 votes |
public static void initCredentials(Job job) throws IOException { UserProvider userProvider = UserProvider.instantiate(job.getConfiguration()); if (userProvider.isHadoopSecurityEnabled()) { // propagate delegation related props from launcher job to MR job if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { job.getConfiguration().set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } } if (userProvider.isHBaseSecurityEnabled()) { try { // init credentials for remote cluster String quorumAddress = job.getConfiguration().get(TableOutputFormat.QUORUM_ADDRESS); User user = userProvider.getCurrent(); if (quorumAddress != null) { Configuration peerConf = HBaseConfiguration.createClusterConf(job.getConfiguration(), quorumAddress, TableOutputFormat.OUTPUT_CONF_PREFIX); Connection peerConn = ConnectionFactory.createConnection(peerConf); try { TokenUtil.addTokenForJob(peerConn, user, job); } finally { peerConn.close(); } } Connection conn = ConnectionFactory.createConnection(job.getConfiguration()); try { TokenUtil.addTokenForJob(conn, user, job); } finally { conn.close(); } } catch (InterruptedException ie) { LOG.info("Interrupted obtaining user authentication token"); Thread.currentThread().interrupt(); } } }
Example #4
Source File: PingHBaseCLI.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException { String hbaseTable = args[0]; System.out.println("Hello friend."); Configuration hconf = HBaseConnection.getCurrentHBaseConfiguration(); if (User.isHBaseSecurityEnabled(hconf)) { try { System.out.println("--------------Getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName()); TokenUtil.obtainAndCacheToken(hconf, UserGroupInformation.getCurrentUser()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.out.println("--------------Error while getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName()); } } Scan scan = new Scan(); int limit = 20; Connection conn = null; Table table = null; ResultScanner scanner = null; try { conn = ConnectionFactory.createConnection(hconf); table = conn.getTable(TableName.valueOf(hbaseTable)); scanner = table.getScanner(scan); int count = 0; for (Result r : scanner) { byte[] rowkey = r.getRow(); System.out.println(Bytes.toStringBinary(rowkey)); count++; if (count == limit) break; } } finally { IOUtils.closeQuietly(scanner); IOUtils.closeQuietly(table); IOUtils.closeQuietly(conn); } }
Example #5
Source File: PingHBaseCLI.java From kylin with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException { String hbaseTable = args[0]; System.out.println("Hello friend."); Configuration hconf = HBaseConnection.getCurrentHBaseConfiguration(); if (User.isHBaseSecurityEnabled(hconf)) { try { System.out.println("--------------Getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName()); TokenUtil.obtainAndCacheToken(hconf, UserGroupInformation.getCurrentUser()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.out.println("--------------Error while getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName()); } } Scan scan = new Scan(); int limit = 20; Connection conn = null; Table table = null; ResultScanner scanner = null; try { conn = ConnectionFactory.createConnection(hconf); table = conn.getTable(TableName.valueOf(hbaseTable)); scanner = table.getScanner(scan); int count = 0; for (Result r : scanner) { byte[] rowkey = r.getRow(); System.out.println(Bytes.toStringBinary(rowkey)); count++; if (count == limit) break; } } finally { IOUtils.closeQuietly(scanner); IOUtils.closeQuietly(table); IOUtils.closeQuietly(conn); } }
Example #6
Source File: PingHBaseCLI.java From Kylin with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException { String metadataUrl = args[0]; String hbaseTable = args[1]; System.out.println("Hello friend."); Configuration hconf = HadoopUtil.newHBaseConfiguration(metadataUrl); if (User.isHBaseSecurityEnabled(hconf)) { try { System.out.println("--------------Getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName()); TokenUtil.obtainAndCacheToken(hconf, UserGroupInformation.getCurrentUser()); } catch (InterruptedException e) { System.out.println("--------------Error while getting kerberos credential for user " + UserGroupInformation.getCurrentUser().getUserName()); } } Scan scan = new Scan(); int limit = 20; HConnection conn = null; HTableInterface table = null; ResultScanner scanner = null; try { conn = HConnectionManager.createConnection(hconf); table = conn.getTable(hbaseTable); scanner = table.getScanner(scan); int count = 0; for (Result r : scanner) { byte[] rowkey = r.getRow(); System.out.println(Bytes.toStringBinary(rowkey)); count++; if (count == limit) break; } } finally { if (scanner != null) { scanner.close(); } if (table != null) { table.close(); } if (conn != null) { conn.close(); } } }