I'm using play-slick_2.11-1.0.1 + HikariCP 2.4.1 to access SqlServer in my Play4-based application.
The database connection in application.conf
:
slick.dbs.myDatabase = {
driver="com.typesafe.slick.driver.ms.SQLServerDriver$"
db{
url = "jdbc:sqlserver://sqlserverhost"
driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
user = "admin"
password = "ENCRYPTED_PASSWORD"
}
}
The problem is that the database password configured here must be encrypted based on our company policy.
How can I inject my decryption code to decrypt the password for the connection?
Just found a solution:
def createDecryptedDbConfig (dbConfigProvider: DatabaseConfigProvider) : DatabaseConfig[JdbcProfile] = {
val dbConfig = dbConfigProvider.get[JdbcProfile]
val decryptedConfig = dbConfig.config.
withValue("db.user", ConfigValueFactory.fromAnyRef(decrypt(dbConfig.config.getConfig("db").getString("user")))).
withValue("db.password", ConfigValueFactory.fromAnyRef(decrypt(dbConfig.config.getConfig("db").getString("password"))))
DatabaseConfig.forConfig[JdbcProfile]("", decryptedConfig)
}