Search in sources :

Example 1 with EncryptionSecretKeyChecker

use of com.cloud.utils.crypt.EncryptionSecretKeyChecker in project cloudstack by apache.

the class DbProperties method wrapEncryption.

protected static Properties wrapEncryption(Properties dbProps) throws IOException {
    EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker();
    checker.check(dbProps);
    if (EncryptionSecretKeyChecker.useEncryption()) {
        return dbProps;
    } else {
        EncryptableProperties encrProps = new EncryptableProperties(EncryptionSecretKeyChecker.getEncryptor());
        encrProps.putAll(dbProps);
        return encrProps;
    }
}
Also used : EncryptableProperties(org.jasypt.properties.EncryptableProperties) EncryptionSecretKeyChecker(com.cloud.utils.crypt.EncryptionSecretKeyChecker)

Example 2 with EncryptionSecretKeyChecker

use of com.cloud.utils.crypt.EncryptionSecretKeyChecker in project cloudstack by apache.

the class DbProperties method getDbProperties.

public static synchronized Properties getDbProperties() {
    if (!loaded) {
        Properties dbProps = new Properties();
        InputStream is = null;
        try {
            File props = PropertiesUtil.findConfigFile("db.properties");
            if (props != null && props.exists()) {
                is = new FileInputStream(props);
            }
            if (is == null) {
                is = PropertiesUtil.openStreamFromURL("db.properties");
            }
            if (is == null) {
                System.err.println("Failed to find db.properties");
                log.error("Failed to find db.properties");
            }
            if (is != null) {
                dbProps.load(is);
            }
            EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker();
            checker.check(dbProps);
            if (EncryptionSecretKeyChecker.useEncryption()) {
                StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
                EncryptableProperties encrDbProps = new EncryptableProperties(encryptor);
                encrDbProps.putAll(dbProps);
                dbProps = encrDbProps;
            }
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load db.properties", e);
        } finally {
            IOUtils.closeQuietly(is);
        }
        properties = dbProps;
        loaded = true;
    }
    return properties;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptableProperties(org.jasypt.properties.EncryptableProperties) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) EncryptableProperties(org.jasypt.properties.EncryptableProperties) Properties(java.util.Properties) EncryptionSecretKeyChecker(com.cloud.utils.crypt.EncryptionSecretKeyChecker) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

EncryptionSecretKeyChecker (com.cloud.utils.crypt.EncryptionSecretKeyChecker)2 EncryptableProperties (org.jasypt.properties.EncryptableProperties)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)1