Skip to content

Instantly share code, notes, and snippets.

@saisgit
Created April 27, 2020 07:15
Show Gist options
  • Save saisgit/12ff1a9a2ffd423726997f178f0015d5 to your computer and use it in GitHub Desktop.
Save saisgit/12ff1a9a2ffd423726997f178f0015d5 to your computer and use it in GitHub Desktop.
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.security.alias.CredentialProviderFactory
/**
Function to Retrieve the password from JCEKS file in Spark with Scala
Parameters: JCEKSFILE in hadoop path(jceksfile), Password alias for the jceks(password_alias)
Returns: Password string
**/
def extractPwdFromJceks(jceksfile:String, password_alias:String):String = {
val conf:Configuration = new Configuration()
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, jceksfile)
val temp = conf.getPassword(password_alias).mkString("")
var password = ""
if (temp != null && !temp.isEmpty() && !temp.equalsIgnoreCase("")){
password = temp
}
return password
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment