最後,我通過編寫一個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