最后,我通过编写一个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();
}
}
唯一的缺点是,我是不能够使用org.jasypt.util.password.StrongPasswordEncryptor - 因为没有解密方法。
有趣的问题,你也可以在[发挥Google小组](http://groups.google.com/group/play-framework)上发布这个问题,以确保你获得最大的覆盖范围。 – tmbrggmn 2012-02-09 07:17:17