Skip to content

Commit

Permalink
Changes to create SPNego principal
Browse files Browse the repository at this point in the history
  • Loading branch information
cmirash committed Oct 22, 2016
1 parent 7f9ec19 commit 448f91f
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import scala.collection.JavaConverters._

import org.apache.commons.logging.Log
import org.apache.hadoop.hive.conf.HiveConf
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
import org.apache.hadoop.hive.shims.Utils
import org.apache.hadoop.security.UserGroupInformation
import org.apache.hive.service.{AbstractService, Service, ServiceException}
Expand All @@ -47,6 +48,7 @@ private[hive] class SparkSQLCLIService(hiveServer: HiveServer2, sqlContext: SQLC
setSuperField(this, "sessionManager", sparkSqlSessionManager)
addService(sparkSqlSessionManager)
var sparkServiceUGI: UserGroupInformation = null
var httpUGI: UserGroupInformation = null

if (UserGroupInformation.isSecurityEnabled) {
try {
Expand All @@ -57,7 +59,24 @@ private[hive] class SparkSQLCLIService(hiveServer: HiveServer2, sqlContext: SQLC
case e @ (_: IOException | _: LoginException) =>
throw new ServiceException("Unable to login to kerberos with given principal/keytab", e)
}
}

// Also try creating a UGI object for the SPNego principal
val principal = hiveConf.getVar(ConfVars.HIVE_SERVER2_SPNEGO_PRINCIPAL)
val keyTabFile = hiveConf.getVar(ConfVars.HIVE_SERVER2_SPNEGO_KEYTAB)
if (principal.isEmpty() || keyTabFile.isEmpty()) {
getAncestorField[Log](this, 3, "LOG").info(
s"SPNego httpUGI not created, spNegoPrincipal: $principal , ketabFile: $keyTabFile")
} else {
try {
httpUGI = HiveAuthFactory.loginFromSpnegoKeytabAndReturnUGI(hiveConf)
setSuperField(this, "httpUGI", httpUGI)
getAncestorField[Log](this, 3, "LOG").info("SPNego httpUGI successfully created.")
} catch {
case e : IOException =>
getAncestorField[Log](this, 3, "LOG").warn(s"SPNego httpUGI creation failed: $e")
}
}
}

initCompositeService(hiveConf)
}
Expand Down

0 comments on commit 448f91f

Please sign in to comment.