唉,网上的资料比较少,找了好久,压根不知道如入告诉 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. HL7 2.6 解析(XML)

    用途:检验化验(LIS)实验室设备数据交换解析. using System; using System.Collections.Generic; using System.Text; using Sy ...

  2. ob_flush()和flush()的区别

    最近写定时任务,遇到ob_flush()和flush()混淆的问题... ob_flush/flush在手册中的描述, 都是刷新输出缓冲区, 并且还需要配套使用, 所以会导致很多人迷惑- 其实, 他们 ...

  3. rpc通信模型

    1.client_stub是为了屏蔽客户端调用远程主机的对象,而在本地的一个对象存根,存根负责接受本地方法调用,并将其序列化,然后通过网络发送给服务端.

  4. hibernate多表查询

    一对多进行查询(用懒加载的模式) 查找区域所对应的街道: Dao: public Qu selQu(String dno){ Session session=HibernateSessionFacto ...

  5. LeetCode--Factorial Trailing Zeroes(注意)

    Given an integer n, return the number of trailing zeroes in n!. 问题描述:给出一个正整数n,计算n!结构后面有几个0.要求:在多项式时间 ...

  6. Numpy array学习笔记

  7. 2018-2-6考试(COCI2014/2015 Contest#5)

    T1:FUNGHI(1s,32M,50pts)得分:50 题意:给你8个数组成一个环,要你求出其中连续的4个数,让它们的和最大 题解:暴力求出每一连续4个数之和,比较一下就好 标签:模拟 C++ Co ...

  8. EditPlus直接连接Linux服务器编辑文本文件

    填写好:描述,ip地址,用户名,密码, 然后点下面的高级选项: 然后返回上一个页面,继续 确定 OK: 然后,在主界面左侧点倒三角: 就可以选择我们之前配置的远程服务器地址,弹出提示框 点确定, 就连 ...

  9. codeforces 1077F1

    题目:https://codeforces.com/contest/1077/problem/F1 题意: 你有n幅画,第i幅画的好看程度为ai,再给你两个数字k,x 表示你要从中选出刚好x幅画,并且 ...

  10. rman异机恢复,全部恢复和增量恢复

    1.首先准备工作:hostname 192.168.222.11 ol7.localdomain ol7建立相关目录:mkdir -p /u01/app/oracle/oradata/DB11G/mk ...