title: Unable to connect hive in kerberos mode
body: <p>Here is the code to connect to hive in kerberos mode</p>
  
  <pre><code>import java.sql.*;
  import org.apache.hadoop.security.UserGroupInformation;
  
  public class hive2 {
    public static void main (String args[]) {
      try {
        org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
        conf.set("hadoop.security.authentication", "Kerberos");
        UserGroupInformation.setConfiguration(conf);
        UserGroupInformation.loginUserFromKeytab("hive/ambari2012.howard2012.local@HOWARD2012.LOCAL", "/etc/security/keytabs/hive.service.keytab");
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        System.out.println("getting connection");
        Connection con = DriverManager.getConnection("jdbc:hive2://ambari2012:10000/;principal=hive/ambari2012.howard2012.local@HOWARD2012.LOCAL");
        System.out.println("got connection");
        con.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  </code></pre>
  
  <p>the issue is doesnt matter what keytab I pass it's always giving the below error - </p>
  
  <pre><code>ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
  java.io.IOException: Login failure for hive/ambari2012.howard2012.local@HOWARD2012.LOCAL from keytab /etc/security/keytabs/hive.service.keytab
      at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:921)
      at hive.connect.java.hive.connect.java.App.main(App.java:21)
  Caused by: javax.security.auth.login.LoginException: Unable to obtain password from user
  </code></pre>
  
  <p>I don't think it's even trying to check if the right keytab is given to it.
  How should I ensure it's reading the correct keytab file and also if the keytab file is not present it should give unable to locate the keytab</p>
  
  <p>Please let me know if I have to copy the keytab ,krb files in my local machine</p>