ulisesbocchio on master
Fix Version check in upgrade mo… Fix typo Merge pull request #233 from tk… (compare)
ulisesbocchio on master
Rename jasypt-spring-boot-start… Merge pull request #244 from fe… (compare)
ulisesbocchio on master
Fix Copy&Paste Error und docume… Merge pull request #249 from je… (compare)
@Bean
public PropertySource allPropertiesSource() throws Exception {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath*:*.properties");
PropertySourceLoader loader = new PropertiesPropertySourceLoader();
Function<Resource, PropertySource> toSource = resource -> {
try {
return loader.load(resource.getFilename(), resource).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
};
Function<List<PropertySource>, PropertySource> collector = sources -> {
CompositePropertySource ps = new CompositePropertySource("all properties");
sources.forEach(ps::addPropertySource);
return ps;
};
return Arrays.stream(resources).map(toSource).collect(Collectors.collectingAndThen(Collectors.toList(), collector));
}
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyDetector;
import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyResolver;
import com.ulisesbocchio.jasyptspringboot.annotation.EncryptablePropertySource;
import com.ulisesbocchio.jasyptspringboot.annotation.EncryptablePropertySources;
/**
@Configuration
@EncryptablePropertySources({ @EncryptablePropertySource("classpath:platform-encrypted.properties") })
public class PlatformEncryptionConfiguration {
@Bean(name = "encryptablePropertyDetector")
public EncryptablePropertyDetector encryptablePropertyDetector() {
return new MyEncryptablePropertyDetector();
}
@Bean(name="encryptablePropertyResolver")
EncryptablePropertyResolver encryptablePropertyResolver() {
return new MyEncryptablePropertyResolver();
}
private class MyEncryptablePropertyDetector implements EncryptablePropertyDetector {
@Override
public boolean isEncrypted(String value) {
if (value != null) {
return value.startsWith("3DES@");
}
return false;
}
@Override
public String unwrapEncryptedValue(String value) {
return value.substring("3DES@".length());
}
}
private class MyEncryptablePropertyResolver implements EncryptablePropertyResolver {
private final PooledPBEStringEncryptor encryptor;
public MyEncryptablePropertyResolver() {
this.encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPasswordCharArray("password".toCharArray());
config.setAlgorithm("3DES");
config.setKeyObtentionIterations("1000");
config.setPoolSize(1);
config.setProviderName("SunJCE");
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
}
@Override
public String resolvePropertyValue(String value) {
if (value != null && value.startsWith("{cipher}")) {
return encryptor.decrypt(value.substring("{cipher}".length()));
}
return value;
}
}
}
in spring.factories -> org.springframework.cloud.bootstrap.BootstrapConfiguration=\
<packg>.PlatformEncryptionConfiguration.class
Hey, guys may I ask for help?
I added com.github.ulisesbocchio:jasypt-spring-boot-starter:1.17
to Spring Boot app. I encrypted MySQL password with test
, and added this JVM arg -Djasypt.encryptor.password=test
.
I start my Spring Boot app, see following logs:
2018-10-12 12:30:05 INFO EnableEncryptablePropertiesBeanFactoryPostProcessor:48 - Post-processing PropertySource instances
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource bootstrap [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource servletConfigInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource servletContextInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource jndiProperties [org.springframework.jndi.JndiPropertySource] to EncryptablePropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource systemProperties [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource systemEnvironment [org.springframework.core.env.SystemEnvironmentPropertySource] to EncryptableMapPropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource random [org.springframework.boot.context.config.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource springCloudClientHostInfo [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2018-10-12 12:30:05 INFO EncryptablePropertySourceConverter:38 - Converting PropertySource defaultProperties [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
But when I try to resolve my MySQL pwd:
@Value("${spring.datasource.password}")
private String password;
It never decrypts it, it is resolved as ENC(...)
instead of decrypted password.
I'm very close, and I feel like I'm missing something
springProperty
.Adding
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
to this sample and adding to application.yml
management:
endpoints:
web:
exposure:
include: "*"
now go to http://localhost:8080/actuator/env
as you can see, the property spring.application.name
resolved from bootstrap.yml
Could anyone please help to resolve this issue.
I am getting below when I am Starting Springboot or doing Run As SpringBoot
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:450)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:429)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:420)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:270)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:249)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.cisco.sbg.ces.configservice.ConfigserviceApplication.main(ConfigserviceApplication.java:16)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor.<clinit>(EnableEncryptablePropertiesBeanFactoryPostProcessor.java:35)
Hi Ulises: Many thanks for responding. I appreciate it. I don't get any errors other than that the password on my datasource is the encoded password. I have checked the samples.
poc repo? Forgive me. I don't know what that is. Do you mean the Pom.xml? How do I share through this chat. I apologise for not being versed in this.
I just went back to the plain jasypt example and will have to revert if you are willing to work with me.
After a great deal of huffing and puffing , and at least two weeks, I got it to work. My comments are as follows:-
Only after following the lines that were actually commented out in your sample did I get it to work.:
new SpringApplicationBuilder()
//.environment(new StandardEncryptableEnvironment())
.sources(DBH2DemoApplication.class)
.run(args);
The .environment(new StandardEncryptableEnvironment() was the key.
I still get a warning in red as follows. Do you know what this is referring to?
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/Rob%20Wilkinson/.m2/repository/org/springframework/spring-core/5.2.9.RELEASE/spring-core-5.2.9.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Hi Ulises: I wanted to take a moment to thank you for your fine work and your patience. While you did not give me a solution you did cause me to do so more work which lead me to my solution.
I don't know what I could have been doing that would have resulted in a non-regular scenario. I had a DataSource bean in an XML file that had variables that were encoded.
I am happy to spend some time trying to put a POC on Github but it will take some time for me. Additionally it will require MySQl to fully test.
Anyway, once again thank you.