Skip to content

Instantly share code, notes, and snippets.

@andrewstevenson
Created September 11, 2016 15:42
Show Gist options
  • Save andrewstevenson/a20ad70cdaba3fd689fe4ae74f0f27c1 to your computer and use it in GitHub Desktop.
Save andrewstevenson/a20ad70cdaba3fd689fe4ae74f0f27c1 to your computer and use it in GitHub Desktop.
override def connect(url: String, info: Properties): Connection = {
val connectionProps = Krb5SqlServer.connectionProperties(url)
val keytabFile = connectionProps(Krb5SqlServer.keytabFile)
val principal = connectionProps(Krb5SqlServer.principalKey)
val config = new Configuration()
config.addResource("/etc/hadoop/conf/hdfs-site.xml")
config.addResource("/etc/hadoop/conf/core-site.xml")
config.addResource("/etc/hadoop/conf/mapred-site.xml")
UserGroupInformation.setConfiguration(config)
UserGroupInformation
.getCurrentUser
.setAuthenticationMethod(AuthenticationMethod.KERBEROS)
UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytabFile)
.doAs(new PrivilegedAction[Connection] {
override def run(): Connection =
sqlServerDriver.connect(url, info)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment