All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ulisesbocchio.jasyptspringboot.EnableEncryptablePropertySourcesConfiguration Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package com.ulisesbocchio.jasyptspringboot;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.config.StringPBEConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;

/**
 * 

Configuration class that registers a {@link BeanFactoryPostProcessor} that wraps all {@link PropertySource} defined in the {@link Environment} * with {@link EncryptablePropertySourceWrapper} and defines a default {@link StringEncryptor} for decrypting properties * that can be configured through the same properties it wraps.

*

The {@link StringEncryptor} bean is only defined when no other * bean of type {@link StringEncryptor} is present in the Application Context, thus allowing for custom definition if required.

*

The default {@link StringEncryptor} can be configured through the following properties:

* * * * * * * * * * * * * * * * * * * * * * * * *
KeyRequiredDefault Value
jasypt.encryptor.passwordTrue -
jasypt.encryptor.algorithmFalsePBEWithMD5AndDES
jasypt.encryptor.keyObtentionIterationsFalse1000
jasypt.encryptor.poolSizeFalse1
jasypt.encryptor.providerNameFalseSunJCE
jasypt.encryptor.saltGeneratorClassnameFalseorg.jasypt.salt.RandomSaltGenerator
jasypt.encryptor.stringOutputTypeFalsebase64
* *

For mor information about the configuration properties

* @see StringPBEConfig * * @author Ulises Bocchio */ @Configuration @Import(StringEncryptorConfiguration.class) public class EnableEncryptablePropertySourcesConfiguration implements EnvironmentAware { private static final Logger LOG = LoggerFactory.getLogger(EnableEncryptablePropertySourcesConfiguration.class); private ConfigurableEnvironment environment; @Bean public EnableEncryptablePropertySourcesPostProcessor enableEncryptablePropertySourcesPostProcessor() { boolean proxyPropertySources = environment.getProperty("jasypt.encryptor.proxyPropertySources", Boolean.TYPE, false); InterceptionMode interceptionMode = proxyPropertySources ? InterceptionMode.PROXY : InterceptionMode.WRAPPER; return new EnableEncryptablePropertySourcesPostProcessor(environment, interceptionMode); } @Override public void setEnvironment(Environment environment) { this.environment = (ConfigurableEnvironment) environment; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy