You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2014/10/16 21:32:45 UTC
svn commit: r1632420 - in /hive/branches/branch-0.14:
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java
jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
Author: thejas
Date: Thu Oct 16 19:32:45 2014
New Revision: 1632420
URL: http://svn.apache.org/r1632420
Log:
HIVE-6715 : Hive JDBC should include username into open session request for non-sasl connection (Prasad Mujumdar, reviewed by Vaibhav Gumashta, Thejas Nair)
Added:
hive/branches/branch-0.14/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java
Modified:
hive/branches/branch-0.14/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
Added: hive/branches/branch-0.14/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.14/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java?rev=1632420&view=auto
==============================================================================
--- hive/branches/branch-0.14/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java (added)
+++ hive/branches/branch-0.14/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java Thu Oct 16 19:32:45 2014
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.apache.hive.jdbc.miniHS2.MiniHS2;
+import org.apache.hive.service.cli.HiveSQLException;
+import org.apache.hive.service.cli.session.HiveSessionHook;
+import org.apache.hive.service.cli.session.HiveSessionHookContext;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestNoSaslAuth {
+ private static MiniHS2 miniHS2 = null;
+ private static String sessionUserName = "";
+
+ public static class NoSaslSessionHook implements HiveSessionHook {
+ public static boolean checkUser = false;
+
+ @Override
+ public void run(HiveSessionHookContext sessionHookContext)
+ throws HiveSQLException {
+ if (checkUser) {
+ Assert.assertEquals(sessionHookContext.getSessionUser(), sessionUserName);
+ }
+ }
+ }
+
+ private Connection hs2Conn = null;
+
+ @BeforeClass
+ public static void beforeTest() throws Exception {
+ Class.forName(MiniHS2.getJdbcDriverName());
+ HiveConf conf = new HiveConf();
+ conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
+ conf.setBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS, false);
+ conf.setVar(ConfVars.HIVE_SERVER2_SESSION_HOOK,
+ NoSaslSessionHook.class.getName());
+ conf.setVar(ConfVars.HIVE_SERVER2_AUTHENTICATION, "NOSASL");
+ miniHS2 = new MiniHS2(conf);
+ Map<String, String> overlayProps = new HashMap<String, String>();
+ miniHS2.start(overlayProps);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // enable the hook check after the server startup,
+ NoSaslSessionHook.checkUser = true;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ hs2Conn.close();
+ NoSaslSessionHook.checkUser = false;
+ }
+
+ @AfterClass
+ public static void afterTest() throws Exception {
+ if (miniHS2.isStarted())
+ miniHS2.stop();
+ }
+
+ /**
+ * Initiate a non-sasl connection. The session hook will verfiy the user name
+ * set correctly
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testConnection() throws Exception {
+ sessionUserName = "user1";
+ hs2Conn = DriverManager.getConnection(
+ miniHS2.getJdbcURL() + ";auth=noSasl", sessionUserName, "foo");
+ }
+}
Modified: hive/branches/branch-0.14/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.14/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java?rev=1632420&r1=1632419&r2=1632420&view=diff
==============================================================================
--- hive/branches/branch-0.14/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java (original)
+++ hive/branches/branch-0.14/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java Thu Oct 16 19:32:45 2014
@@ -443,6 +443,12 @@ public class HiveConnection implements j
}
openReq.setConfiguration(openConf);
+ // Store the user name in the open request in case no non-sasl authentication
+ if (JdbcConnectionParams.AUTH_SIMPLE.equals(sessConfMap.get(JdbcConnectionParams.AUTH_TYPE))) {
+ openReq.setUsername(sessConfMap.get(JdbcConnectionParams.AUTH_USER));
+ openReq.setPassword(sessConfMap.get(JdbcConnectionParams.AUTH_PASSWD));
+ }
+
try {
TOpenSessionResp openResp = client.OpenSession(openReq);