I'm working with Impala Cloudera setup to read data from db. Below java code is provided to connect(runs on the server successfully) and get data from db with Kerberos auth.
Java code I use:
private static void init() {
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("java.security.krb5.conf", "server-path/krb5.conf");
System.setProperty("java.security.auth.login.config", "server-path/jaas.conf");
}
private static void createConnection() throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
try {
init();
Class.forName("com.cloudera.impala.jdbc4.Driver");
// Authenticating Kerberos principal
System.out.println("Principal Authentication: ");
final String user = "user";
final String keyPath = "conserver-path/user.keytab";
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab(user, keyPath);
conn = DriverManager.getConnection("jdbc:impala://ipaddress;AuthMech=1;KrbRealm=realm;KrbHostFQDN=fqdn;KrbServiceName=impala",
"user", "pwd");
System.out.println(conn);
System.out.println("=========================================================================");
String query = "select count(*) from tableName";
System.out.println("Connection :" + conn);
pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
System.out.println(rs);
System.out.println("--------------------------------------------");
while (rs != null && rs.next()) {
// System.out.println(rs.getFetchSize());
System.out.println(rs.getInt(1));
}
} catch(Exception e) {
e.printStackTrace();
} finally {
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
}
}
I have an issue while running the same from local/windows environment to connect to server/Cloudera Impala database. Have copied jaas.conf, kerb5.conf, user.keytab to the local path but program throws:
>>> Found no TGT's in LSA
java.sql.SQLException: [Simba][ImpalaJDBCDriver](500168) Error creating login context using ticket cache: Unable to obtain Princpal Name for authentication.
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createTransport(Unknown Source)
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source)
at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source)
at com.cloudera.impala.core.ImpalaJDBCConnection.establishConnection(Unknown Source)
at com.cloudera.jdbc.core.LoginTimeoutConnection.connect(Unknown Source)
at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at Com.connection.impala.TestImpala.createConnection(TestImpala.java:50)
Caused by: com.cloudera.support.exceptions.GeneralException: [Simba][ImpalaJDBCDriver](500168) Error creating login context using ticket cache: Unable to obtain Princpal Name for authentication .
... 10 more
Read few links respective to Kerberos Constrained Delegation. Could not understand what and how exactly the steps should be followed.
Help me run and get the connection succesfully from windows machine.