Encrypted database password in Play + Slick + HikariCP application

自作多情 提交于 2019-12-08 02:43:19

问题


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?


回答1:


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)
  }


来源:https://stackoverflow.com/questions/32385411/encrypted-database-password-in-play-slick-hikaricp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!