Reply
Highlighted
Explorer
Posts: 21
Registered: ‎03-28-2017

Exception in Hive-JDBC while using Kerberos: javax.security.auth.login.LoginException

I am trying to connect to Hive thru Java-Jdbc using Kerberos authentication. But I am getting javax.security.auth.login.LoginException while trying to connect to Hive. Below is the code in the connection class:

 

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;

public class DbManager {
private static Connection hiveConnection;
// get Hive Connection
public static Connection qwtHiveConnection() throws IOException, SQLException {

    System.out.println("Preparing Hive connection1");
    Configuration conf = new Configuration();
    conf.set("hadoop.security.authentication", "Kerberos");
    UserGroupInformation.setConfiguration(conf);
    **UserGroupInformation.loginUserFromKeytab("username@HLC.ABC.QW.COM", "/home/username/username.keytab");**
    // Hive Connection
    try {
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        if(hiveConnection == null) {
            hiveConnection = DriverManager.getConnection("jdbc:hive2://abcd1dq000.hlc.abc.qw.com:10000/finance;principal=hive/_HOST@HLC.ABC.QW.COM", "usrname", "pwd");
            return hiveConnection;
        } else {
        return hiveConnection;
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (SQLException e) {
        e.printStackTrace();
        return null;
    }
}
}

The Hadoop version I see from the command 'hadoop version':

 

Hadoop 2.7.3.2.6.2.0-205
This command was run using /usr/hdp/2.6.2.0-205/hadoop/hadoop-common-2.7.3.2.6.2.0-205.jar

 

I am using the following jar files in the project:

hive-jdbc-2.2.0.jar

postgresql-9.4.1212.jar

apache-commons.jar

slf4j-api-1.7.25.jar

hadoop-commons-2.6.2.jar

guava-18.0.jar

commons-configuration-1.9.jar

commons-lang-2.6.jar

hadoop-auth-2.6.2.jar

The exception I get is:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.io.IOException: Login failure for username@DLX.IDC.GE.COM from keytab /home/username/username.keytab: javax.security.auth.login.LoginException: Unable to obtain password from user

    at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:961)
    at com.dbconnections.gphive.DbManager.getHiveConnection(DbManager.java:24)
    at com.recordcount.dao.GpHiveRecords.getHiveTableCount(GpHiveRecords.java:93)
    at com.recordcount.entry.StartCount.main(StartCount.java:13)
Caused by: javax.security.auth.login.LoginException: Unable to obtain password from user

    at com.sun.security.auth.module.Krb5LoginModule.promptForPass(Krb5LoginModule.java:897)
    at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:760)
    at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
    at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
    at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
    at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
    at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
    at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:952)
    ... 3 more

The lines related to exception in the c are marked in '*':

Could anyone let me know what is the mistake I am doing here so that I can correct it.

Announcements