Play + Slick + HikariCP应用程序中的加密数据库密码 [英] Encrypted database password in Play + Slick + HikariCP application

查看:255
本文介绍了Play + Slick + HikariCP应用程序中的加密数据库密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用play-slick_2.11-1.0.1 + HikariCP 2.4.1访问基于Play4的应用程序中的SqlServer.
application.conf中的数据库连接:

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?

推荐答案

刚刚找到了解决方案:

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

这篇关于Play + Slick + HikariCP应用程序中的加密数据库密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆