You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/02/24 06:11:19 UTC
[GitHub] [spark] maropu commented on a change in pull request #31622: [SPARK-34497][SQL] Fix built-in JDBC connection providers to restore JVM security context changes
maropu commented on a change in pull request #31622:
URL: https://github.com/apache/spark/pull/31622#discussion_r581657146
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/DB2ConnectionProvider.scala
##########
@@ -34,15 +35,22 @@ private[sql] class DB2ConnectionProvider extends SecureConnectionProvider {
override def getConnection(driver: Driver, options: Map[String, String]): Connection = {
val jdbcOptions = new JDBCOptions(options)
- setAuthenticationConfigIfNeeded(driver, jdbcOptions)
- UserGroupInformation.loginUserFromKeytabAndReturnUGI(jdbcOptions.principal, jdbcOptions.keytab)
- .doAs(
- new PrivilegedExceptionAction[Connection]() {
- override def run(): Connection = {
- DB2ConnectionProvider.super.getConnection(driver, options)
+ val parent = Configuration.getConfiguration
+ try {
+ setAuthenticationConfig(parent, driver, jdbcOptions)
+ UserGroupInformation.loginUserFromKeytabAndReturnUGI(jdbcOptions.principal,
+ jdbcOptions.keytab)
+ .doAs(
+ new PrivilegedExceptionAction[Connection]() {
+ override def run(): Connection = {
+ DB2ConnectionProvider.super.getConnection(driver, options)
+ }
}
- }
- )
+ )
+ } finally {
+ logDebug("Restoring original security configuration")
+ Configuration.setConfiguration(parent)
+ }
Review comment:
It looks like this is a boilerplate code, so could we handle this outside `getConnection`? IIUC, in the current approach, 3rd-party developers need to write the same code in a user-defined provider overriding `ConnectionProvider. getConnection`?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org