唉,网上的资料比较少,找了好久,压根不知道如入告诉 phoenix 客户端来使用 kerberos 啊。。

然后就想到了,这东西开源的应该有相关的单元测试吧。。啊哈哈哈哈哈哈,果然

https://github.com/apache/phoenix/blob/master/phoenix-core/src/test/java/org/apache/phoenix/jdbc/SecureUserConnectionsTest.java
private String joinUserAuthentication(String origUrl, String principal, File keytab) {
StringBuilder sb = new StringBuilder(64);
// Knock off the trailing terminator if one exists
if (origUrl.charAt(origUrl.length() - 1) == PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR) {
sb.append(origUrl, 0, origUrl.length() - 1);
} else {
sb.append(origUrl);
} sb.append(PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR).append(principal);
sb.append(PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR).append(keytab.getPath());
return sb.append(PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR).toString();
}

通过 url 拼接就行了!! 测试代码:

public class Main {
public static void main(String[] args) throws ClassNotFoundException, LoginException {
System.setProperty("java.security.krb5.conf", "/app/conf/krb5.conf"); Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
try (Connection connection = DriverManager.getConnection("jdbc:phoenix:node1,node2,node3:storm-miras:/app/conf/storm.headless.keytab");
PreparedStatement preparedStatement = connection.prepareStatement("select * from phoenix_krb")) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
System.out.println(resultSet.getString("content"));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

  

1243 [main] WARN  o.a.h.u.Shell - Did not find winutils.exe: java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
1408 [main] INFO o.a.p.q.ConnectionQueryServicesImpl - Trying to connect to a secure cluster with keytab:/app/conf/storm.headless.keytab
1485 [main] WARN o.a.h.u.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
1793 [main] INFO o.a.h.s.UserGroupInformation - Login successful for user storm-miras using keytab file /app/conf/storm.headless.keytab
1793 [main] INFO o.a.p.q.ConnectionQueryServicesImpl - Successfull login to secure cluster!!
1971 [main] INFO o.a.h.h.z.RecoverableZooKeeper - Process identifier=hconnection-0x1e4d3ce5 connecting to ZooKeeper ensemble=node2:2181,node3:2181
11612 [main] WARN o.a.h.h.s.DomainSocketFactory - The short-circuit local reads feature cannot be used because UNIX Domain sockets are not available on Windows.
11664 [main] INFO o.a.p.m.Metrics - Initializing metrics system: phoenix
11728 [main] WARN o.a.h.m.i.MetricsConfig - Cannot locate configuration: tried hadoop-metrics2-phoenix.properties,hadoop-metrics2.properties
11745 [main] INFO o.a.h.m.i.MetricsSystemImpl - Scheduled snapshot period at 10 second(s).
11745 [main] INFO o.a.h.m.i.MetricsSystemImpl - phoenix metrics system started
hello
world
2017-08-30 17:03:28,854 FATAL Unable to register shutdown hook because JVM is shutting down.
0: jdbc:phoenix:> select * from phoenix_krb;
+-----+----------+
| ID | CONTENT |
+-----+----------+
| 1 | hello |
| 2 | world |
+-----+----------+
2 rows selected (0.03 seconds)
0: jdbc:phoenix:>

java 连接带 kerberos 验证的 phoenix的更多相关文章

  1. 使用java连接AD域,验证账号password是否正确

    web项目中有时候客户要求我们使用ad域进行身份确认,不再另外做一套用户管理系统.事实上客户就是仅仅要一套账号能够訪问全部的OA.CRM等办公系统. 这就是第三方验证.一般有AD域,Ldap,Radi ...

  2. 使用java连接AD域,验证账号密码是否正确

    eb项目中有时候客户要求我们使用ad域进行身份确认,不再另外做一套用户管理系统.其实客户就是只要一套账号可以访问所有的OA,CRM等办公系统.这就是第三方验证.一般有AD域,Ldap,Radius,邮 ...

  3. java连接AD域

    import org.springframework.boot.autoconfigure.SpringBootApplication; import java.util.Hashtable; imp ...

  4. Java虚拟机JVM学习03 连接过程:验证、准备、解析

    Java虚拟机JVM学习03 连接过程:验证.准备.解析 类被加载后,就进入连接阶段. 连接就是将已经读入到内存的类的二进制数据合并到虚拟机的运行时环境中去. 连接阶段三个步骤:验证.准备和解析. 类 ...

  5. java连接redis使用jedis带密码

    一.引入jedis的Maven配置文件 <!-- redis连接客户端jedis --> <dependency> <groupId>redis.clients&l ...

  6. java发送带附件的邮件

    /** * java发送带附件的邮件 * 周枫 * 2013.8.10 */ package com.dsideal.Util; import javax.mail.*; import javax.m ...

  7. (转载)Java自带的GUI性能监控工具Jconsole以及JisualVM简介

    原文链接:http://blog.csdn.net/chendc201/article/details/22905503 1 Jconsole 1.1 简介以及连接 JConsole是一个基于JMX的 ...

  8. Java中的数据验证

    原文链接:https://www.cuba-platform.com/blog/2018-10-09/945 翻译:CUBA China CUBA-Platform 官网 : https://www. ...

  9. Java 自带性能监控工具:监视和管理控制台 jconsole 的使用

    1. 前言想验证你对 jvm 配的一些调优参数(比如 Xms.Xmx 等)有没有起作用吗?想不想实时监控你自定义的线程池的在实际运行时的线程个数.有没有死锁?应用出现 java.lang.OutOfM ...

随机推荐

  1. 【bzoj2384】[Ceoi2011]Match 特殊匹配条件的KMP+树状数组

    题目描述 给出两个长度分别为n.m的序列A.B,求出B的所有长度为n的连续子序列(子串),满足:序列中第i小的数在序列的Ai位置. 输入 第一行包含两个整数n, m (2≤n≤m≤1000000).  ...

  2. jquery/js iframe 元素操作

    1.判断id/ class 是否存在? <script> $(function(){ if(("#id_name").length()>0){ //如果id 存在 ...

  3. 洛谷 P1268 树的重量 解题报告

    P1268 树的重量 题目描述 树可以用来表示物种之间的进化关系.一棵"进化树"是一个带边权的树,其叶节点表示一个物种,两个叶节点之间的距离表示两个物种的差异.现在,一个重要的问题 ...

  4. BZOJ 2500 幸福的道路(race) 树上直径+平衡树

    structHeal { priority_queue<int> real; priority_queue<int> stack; void push(int x){ real ...

  5. webpack 3.8 使用 extract-text-webpack-plugin 3.0 抽取css失败:You may need an appropriate loader to handle this file type.

    webpack 3.8.1 使用 extract-text-webpack-plugin 3.0.2 抽取css时失败,报错: ERROR in ./src/static/style/localTim ...

  6. 深入研究JavaScript的事件机制

    本篇开始将回顾下Javascript的事件机制.同时会从一个最小的函数开始写到最后一个具有完整功能的,强大的事件模块.为叙述方便将响应函数/回调函数/事件Listener/事件handler都称为事件 ...

  7. fastjson对json操作

    fastjson对json字符串JSONObject和JSONArray互相转换操作示例  fastjson的方法: Fastjson API入口类是com.alibaba.fastjson.JSON ...

  8. vue-transition-fade

    <!Doctype> <html> <head> <meta charset="utf-8"> <meta name=&quo ...

  9. java获取mysql数据库表、字段、字段类型、字段注释

    最近想要写一个根据数据库表结构生成实体.mapper接口.mapping映射文件.service类的简单代码生成工具,所以查阅了一些资料,怎样获取数据库的表.表中字段.字段类型.字段注释等信息. 最后 ...

  10. input输入浮动提示

    html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...