Search in sources :

Example 6 with EncryptableProperties

use of org.jasypt.properties.EncryptableProperties in project uPortal by Jasig.

the class PortalPropertySourcesPlaceholderConfigurer method mergeProperties.

/**
 * Override PropertiesLoaderSupport.mergeProprties in order to slip in a properly-configured
 * EncryptableProperties instance, allowing us to encrypt property values at rest.
 */
@Override
protected Properties mergeProperties() throws IOException {
    Properties rslt = null;
    /*
         * If properties file encryption is used in this deployment, the
         * encryption key will be made available to the application as an
         * environment variable called UP_JASYPT_KEY.
         */
    final String encryptionKey = System.getenv(JAYSYPT_ENCRYPTION_KEY_VARIABLE);
    if (encryptionKey != null) {
        logger.info("Jasypt support for encrypted property values ENABLED");
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(encryptionKey);
        rslt = new EncryptableProperties(encryptor);
        if (this.localOverride) {
            // Load properties from file upfront, to let local properties override.
            loadProperties(rslt);
        }
        if (this.localProperties != null) {
            for (int i = 0; i < this.localProperties.length; i++) {
                CollectionUtils.mergePropertiesIntoMap(this.localProperties[i], rslt);
            }
        }
        if (!this.localOverride) {
            // Load properties from file afterwards, to let those properties override.
            loadProperties(rslt);
        }
    /*
             * END copied from PropertiesLoaderSupport.mergeProperties()
             */
    } else {
        logger.info("Jasypt support for encrypted property values DISABLED;  " + "specify environment variable {} to use this feature", JAYSYPT_ENCRYPTION_KEY_VARIABLE);
        /*
             * The feature is not in use;  defer to the Spring-provided
             * implementation of this method.
             */
        return super.mergeProperties();
    }
    return rslt;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptableProperties(org.jasypt.properties.EncryptableProperties) EncryptableProperties(org.jasypt.properties.EncryptableProperties) Properties(java.util.Properties)

Aggregations

EncryptableProperties (org.jasypt.properties.EncryptableProperties)6 Properties (java.util.Properties)5 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 FileNotFoundException (java.io.FileNotFoundException)3 EncryptionSecretKeyChecker (com.cloud.utils.crypt.EncryptionSecretKeyChecker)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SQLException (java.sql.SQLException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)2 InputStream (java.io.InputStream)1