gaborgsomogyi commented on a change in pull request #28215:
URL: https://github.com/apache/spark/pull/28215#discussion_r415647618



##########
File path: 
external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/DB2KrbIntegrationSuite.scala
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.spark.sql.jdbc
+
+import java.security.PrivilegedExceptionAction
+import java.sql.Connection
+import javax.security.auth.login.Configuration
+
+import com.spotify.docker.client.messages.{ContainerConfig, HostConfig}
+import org.apache.hadoop.security.{SecurityUtil, UserGroupInformation}
+import 
org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS
+
+import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions
+import 
org.apache.spark.sql.execution.datasources.jdbc.connection.{DB2ConnectionProvider,
 SecureConnectionProvider}
+import org.apache.spark.tags.DockerTest
+
+@DockerTest
+class DB2KrbIntegrationSuite extends DockerKrbJDBCIntegrationSuite {
+  override protected val userName = s"db2/$dockerIp"
+  override protected val keytabFileName = "db2.keytab"
+
+  override val db = new DatabaseOnDocker {
+    override val imageName = "ibmcom/db2:11.5.0.0a"
+    override val env = Map(
+      "DB2INST1_PASSWORD" -> "rootpass",
+      "LICENSE" -> "accept",
+      "DBNAME" -> "db2"
+    )
+    override val usesIpc = false
+    override val jdbcPort = 50000
+    override val privileged = true
+    override def getJdbcUrl(ip: String, port: Int): String = 
s"jdbc:db2://$ip:$port/db2"
+    override def getJdbcProperties() = {
+      val options = new JDBCOptions(Map[String, String](
+        JDBCOptions.JDBC_URL -> getJdbcUrl(dockerIp, externalPort),
+        JDBCOptions.JDBC_TABLE_NAME -> "bar",
+        JDBCOptions.JDBC_KEYTAB -> keytabFileName,
+        JDBCOptions.JDBC_PRINCIPAL -> principal
+      ))
+      new DB2ConnectionProvider(null, options).getAdditionalProperties()
+    }
+
+    override def beforeContainerStart(
+        hostConfigBuilder: HostConfig.Builder,
+        containerConfigBuilder: ContainerConfig.Builder): Unit = {
+      copyExecutableResource("db2_krb_setup.sh", initDbDir, replaceIp)
+
+      hostConfigBuilder.appendBinds(
+        HostConfig.Bind.from(initDbDir.getAbsolutePath)
+          .to("/var/custom").readOnly(true).build()
+      )
+    }
+  }
+
+  override protected def setAuthentication(keytabFile: String, principal: 
String): Unit = {
+    val config = new SecureConnectionProvider.JDBCConfiguration(
+      Configuration.getConfiguration, "JaasClient", keytabFile, principal)
+    Configuration.setConfiguration(config)

Review comment:
       I think the solution shouldn't be complicated but it effects all other 
providers which change the configuration (not just DB2).




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to