Search in sources :

Example 16 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor 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

StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 IOException (java.io.IOException)6 Properties (java.util.Properties)6 FileNotFoundException (java.io.FileNotFoundException)5 EncryptableProperties (org.jasypt.properties.EncryptableProperties)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SQLException (java.sql.SQLException)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)4 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)2 BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)2 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)2 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2