zhouyifan279 commented on a change in pull request #1053:
URL: https://github.com/apache/incubator-kyuubi/pull/1053#discussion_r704299088



##########
File path: 
kyuubi-server/src/test/scala/org/apache/kyuubi/credentials/HiveDelegationTokenProviderSuite.scala
##########
@@ -0,0 +1,208 @@
+/*
+ * 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.kyuubi.credentials
+
+import java.io.{File, FileOutputStream}
+import java.net.URLClassLoader
+import java.util.concurrent.atomic.AtomicBoolean
+import java.util.concurrent.locks.ReentrantLock
+
+import scala.collection.JavaConverters._
+import scala.concurrent.ExecutionContext.Implicits.global
+import scala.concurrent.Future
+
+import org.apache.commons.io.FileUtils
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.hive.conf.HiveConf
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars._
+import org.apache.hadoop.hive.metastore.{HiveMetaException, HiveMetaStore}
+import org.apache.hadoop.hive.thrift.{DelegationTokenIdentifier, 
HadoopThriftAuthBridge, HadoopThriftAuthBridge23}
+import org.apache.hadoop.io.Text
+import org.apache.hadoop.security.{Credentials, UserGroupInformation}
+import org.apache.thrift.TProcessor
+import org.apache.thrift.protocol.TProtocol
+import org.scalatest.concurrent.Eventually._
+import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
+
+import org.apache.kyuubi.{KerberizedTestHelper, Logging, Utils}
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.credentials.LocalMetaServer.defaultHiveConf
+
+class HiveDelegationTokenProviderSuite extends KerberizedTestHelper {
+
+  private val hadoopConfDir: File = Utils.createTempDir().toFile
+  private var hiveConf: HiveConf = _
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+
+    tryWithSecurityEnabled {
+      UserGroupInformation.loginUserFromKeytab(testPrincipal, testKeytab)
+
+      // HiveMetaStore creates a new hadoop `Configuration` object for each 
request to verify
+      // whether user can impersonate others.
+      // So we create a URLClassLoader with core-site.xml and set it as the 
thread's context
+      // classloader when creating `Configuration` object.
+      val conf = new Configuration(false)
+      conf.set("hadoop.security.authentication", "kerberos")
+      val realUser = UserGroupInformation.getCurrentUser.getShortUserName
+      conf.set(s"hadoop.proxyuser.$realUser.groups", "*")
+      conf.set(s"hadoop.proxyuser.$realUser.hosts", "*")
+
+      val xml = new File(hadoopConfDir, "core-site.xml")
+      val os = new FileOutputStream(xml)
+      try {
+        conf.writeXml(os)
+      } finally {
+        os.close()
+      }
+
+      val classloader =
+        new URLClassLoader(
+          Array(hadoopConfDir.toURI.toURL),
+          classOf[Configuration].getClassLoader)
+
+      hiveConf = LocalMetaServer.defaultHiveConf()
+      hiveConf.addResource(conf)
+      hiveConf.setVar(METASTORE_USE_THRIFT_SASL, "true")
+      hiveConf.setVar(METASTORE_KERBEROS_PRINCIPAL, testPrincipal)
+      hiveConf.setVar(METASTORE_KERBEROS_KEYTAB_FILE, testKeytab)
+      val metaServer = new LocalMetaServer(hiveConf, classloader)
+      metaServer.start()

Review comment:
       Sadly, `HiveMetaStore` does not have a stop method. Even the launched 
`TThreadPoolServer` is not assigned to any class member.

##########
File path: 
kyuubi-server/src/test/scala/org/apache/kyuubi/credentials/HiveDelegationTokenProviderSuite.scala
##########
@@ -0,0 +1,208 @@
+/*
+ * 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.kyuubi.credentials
+
+import java.io.{File, FileOutputStream}
+import java.net.URLClassLoader
+import java.util.concurrent.atomic.AtomicBoolean
+import java.util.concurrent.locks.ReentrantLock
+
+import scala.collection.JavaConverters._
+import scala.concurrent.ExecutionContext.Implicits.global
+import scala.concurrent.Future
+
+import org.apache.commons.io.FileUtils
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.hive.conf.HiveConf
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars._
+import org.apache.hadoop.hive.metastore.{HiveMetaException, HiveMetaStore}
+import org.apache.hadoop.hive.thrift.{DelegationTokenIdentifier, 
HadoopThriftAuthBridge, HadoopThriftAuthBridge23}
+import org.apache.hadoop.io.Text
+import org.apache.hadoop.security.{Credentials, UserGroupInformation}
+import org.apache.thrift.TProcessor
+import org.apache.thrift.protocol.TProtocol
+import org.scalatest.concurrent.Eventually._
+import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
+
+import org.apache.kyuubi.{KerberizedTestHelper, Logging, Utils}
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.credentials.LocalMetaServer.defaultHiveConf
+
+class HiveDelegationTokenProviderSuite extends KerberizedTestHelper {
+
+  private val hadoopConfDir: File = Utils.createTempDir().toFile
+  private var hiveConf: HiveConf = _
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+
+    tryWithSecurityEnabled {
+      UserGroupInformation.loginUserFromKeytab(testPrincipal, testKeytab)
+
+      // HiveMetaStore creates a new hadoop `Configuration` object for each 
request to verify
+      // whether user can impersonate others.
+      // So we create a URLClassLoader with core-site.xml and set it as the 
thread's context
+      // classloader when creating `Configuration` object.
+      val conf = new Configuration(false)
+      conf.set("hadoop.security.authentication", "kerberos")
+      val realUser = UserGroupInformation.getCurrentUser.getShortUserName
+      conf.set(s"hadoop.proxyuser.$realUser.groups", "*")
+      conf.set(s"hadoop.proxyuser.$realUser.hosts", "*")
+
+      val xml = new File(hadoopConfDir, "core-site.xml")
+      val os = new FileOutputStream(xml)
+      try {
+        conf.writeXml(os)
+      } finally {
+        os.close()
+      }
+
+      val classloader =
+        new URLClassLoader(
+          Array(hadoopConfDir.toURI.toURL),
+          classOf[Configuration].getClassLoader)
+
+      hiveConf = LocalMetaServer.defaultHiveConf()
+      hiveConf.addResource(conf)
+      hiveConf.setVar(METASTORE_USE_THRIFT_SASL, "true")
+      hiveConf.setVar(METASTORE_KERBEROS_PRINCIPAL, testPrincipal)
+      hiveConf.setVar(METASTORE_KERBEROS_KEYTAB_FILE, testKeytab)
+      val metaServer = new LocalMetaServer(hiveConf, classloader)
+      metaServer.start()

Review comment:
       Sadly, `HiveMetaStore` does not have a stop method. Even the started 
`TThreadPoolServer` is not assigned to any class member.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to