FAQ
Author: thejas
Date: Thu Oct 16 19:32:21 2014
New Revision: 1632419

URL: http://svn.apache.org/r1632419
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/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java
Modified:
     hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java

Added: hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java
URL: http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java?rev=1632419&view=auto
==============================================================================
--- hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java (added)
+++ hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestNoSaslAuth.java Thu Oct 16 19:32:21 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/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java?rev=1632419&r1=1632418&r2=1632419&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java Thu Oct 16 19:32:21 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);

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedOct 16, '14 at 7:32p
activeOct 16, '14 at 7:32p
posts1
users1
websitehive.apache.org

1 user in discussion

Thejas: 1 post

People

Translate

site design / logo © 2021 Grokbase