Play框架[我正在使用v1.2.3]不支持存储在application.conf中的db密码加密.它存储为纯文本文件.DBPlugin读取此属性并创建连接池.
要求是加密此密码 - 例如使用Jasypt.一些企业将此作为安全措施来实施.
有人试过做这样的事吗?
由于DBPlugin在ApplicationStart上加载,因此无法破解它.这留下了编写自定义插件,onConfigurationRead为application.conf属性的db.password设置了一个新值.
有什么建议?
bas*_*sav 11
最后我通过编写Play插件来解决这个问题.编写Play插件也很容易.以下是示例代码:
package plugin;
import java.util.Properties;
import org.jasypt.util.text.StrongTextEncryptor;
import play.Play;
import play.PlayPlugin;
public class DBPasswordInject extends PlayPlugin {
@Override
public void onConfigurationRead() {
StrongTextEncryptor strongTextEncryptor = new StrongTextEncryptor();
strongTextEncryptor.setPassword("$Look##$2");// this password has been used to encrypt
String encryptedPassword = Play.configuration.getProperty("db.pass");
String decrypted = strongTextEncryptor.decrypt(encryptedPassword);
Play.configuration.setProperty("db.pass", decrypted); //override
super.onConfigurationRead();
}
}
Run Code Online (Sandbox Code Playgroud)
唯一的缺点是我无法使用org.jasypt.util.password.StrongPasswordEncryptor - 因为没有解密方法.
归档时间: |
|
查看次数: |
3103 次 |
最近记录: |