Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How can I Configuring Impala Delegation for java (impala.doas.user)

avatar
Explorer

CDH 6.3.2

I use 

 

 <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>2.1.1-cdh6.3.2</version>
        </dependency>

 

I want proxy to user read_hi

 

 

final String URL = "jdbc:hive2://tidb4ser:21051/;principal=impala/tidb4ser1@JOIN.COM;impala.doas.user=read_hi";
System.setProperty("java.security.krb5.conf",krb5Path);
            Configuration conf = new Configuration();
            conf.set("hadoop.security.authentication", "Kerberos");
            UserGroupInformation.setConfiguration(conf);
            UserGroupInformation.loginUserFromKeytab(principal,keytabPath); 
Class.forName("org.apache.hive.jdbc.HiveDriver");

            Connection connection = DriverManager.getConnection(URL);  
            Statement st = connection.createStatement();
            st.execute("use hivetest");
            ResultSet rs = st.executeQuery("SELECT id,name,year FROM hivetest.chinese_par t where t.city='重庆'");

 

 

but it dosen't work.

 

I can use 

 

 

final String HIVE_URL = "jdbc:hive2://tidb4ser:11000/;principal=hive/tidb4ser1@JOIN.COM;hive.server2.proxy.user=read_hi";

 

 

 to connect Hive

 

so, How can I proxy user with impala

 

Do I need use 

<dependency>
            <groupId>com.cloudera.impala.jdbc</groupId>
            <artifactId>ImpalaJDBC41</artifactId>
            <version>2.6.20</version>
        </dependency>
1 REPLY 1

avatar
Explorer

 

            Class.forName("com.cloudera.impala.jdbc41.Driver");

            UserGroupInformation.setConfiguration(conf);
            UserGroupInformation.loginUserFromKeytab(principal,keytabPath);
            UserGroupInformation loginUser = UserGroupInformation.getLoginUser();

            loginUser.doAs((PrivilegedAction<Void>) () -> {
                try {
                    try (Connection connection = DriverManager.getConnection("jdbc:impala://tidb4ser:21051;AuthMech=1;KrbRealm=JOIN.COM;KrbHostFQDN=tidb4ser;KrbServiceName=impala;DelegationUID=read_hive")) { 
                        try (Statement statement = connection.createStatement()) {
                            statement.execute("use hivetest");
                            ResultSet resultSet = statement.executeQuery("SELECT id,name,year FROM hivetest.chinese_par t where t.city='重庆'");
                            List dataList = resultSetToList(resultSet);

                            System.out.println(JSONObject.toJSON(dataList));
                        }catch (Exception err){
                            err.printStackTrace();
                        }
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return null;
            });

 

use ImpalaJDBC41 that is OK

 

but I want use HIVE-JDBC