Closed 6Niner closed 8 years ago
Are you experiencing any error? I'm not sure what you're asking. The bean rename is to overcome a limitation of Spring that doesn't allow ${pace.holders} in bean names. Since I want users to be able to define their own bean name if they want.
Hi Ulises, Let me try to describe the scenario a little better this time. I went through your brief documentation on GitHub and inferred that if I write a decryption method that returns an object of type StringEncryptor with a @Bean(name="jasyptStringEncryptor") preceeding it, the default StringEncryptor will not be initialized by jasypt-spring-boot. So I did the same but upon running the application, I saw that my custom encryptor was being overriden by jasypt's default string encryptor having the same bean name. As per my understanding the default is overridden by the custom and not the other way round. Inspite of me writing the custom method and providing certain value to fields such as the randomsaltgenerator and keyobtentioniterations, it always picked up the default values and in the logs i could see that:
Hope this explains the scenario better.
I would also like to mention that I really appreciate the work you are doing to make life easier for developers around the globe.
Thanks & Regards, Debanjan. On Apr 21, 2016 4:49 AM, "Ulises Bocchio" notifications@github.com wrote:
Are you experiencing any error? I'm not sure what you're asking. The bean rename is to overcome a limitation of Spring that doesn't allow ${pace.holders} in bean names. Since I want users to be able to define their own bean name if they want.
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/ulisesbocchio/jasypt-spring-boot/issues/23#issuecomment-212649475
checkout the demo app https://github.com/ulisesbocchio/jasypt-spring-boot/tree/master/jasypt-spring-boot-demo-custom-encryptor
That works just fine. That one renames the actual bean name in application.yml, but you can just remove the renaming in application.yml and rename the static bean as jasyptStringEncryptor
and it works just fine.
Please make sure you declare your bean static:
@Bean(name="jasyptStringEncryptor")
static public StringEncryptor stringEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword("password");
config.setAlgorithm("PBEWithMD5AndDES");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName("SunJCE");
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
return encryptor;
}
Hi Ulises, I am not using yml currently but I will surely give it a try. Thanks for your time and your prompt reply.
Thanks & Regards, Debanjan. On Apr 21, 2016 5:19 AM, "Ulises Bocchio" notifications@github.com wrote:
checkout the demo app https://github.com/ulisesbocchio/jasypt-spring-boot/tree/master/jasypt-spring-boot-demo-custom-encryptor
That works just fine. That one renames the actual bean name in application.yml, but you can just remove the renaming in application.yml and rename the static bean as jasyptStringEncryptor and it works just fine. Please make sure you declare your bean static:
@Bean(name="jasyptStringEncryptor") static public StringEncryptor stringEncryptor() { PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); SimpleStringPBEConfig config = new SimpleStringPBEConfig(); config.setPassword("password"); config.setAlgorithm("PBEWithMD5AndDES"); config.setKeyObtentionIterations("1000"); config.setPoolSize("1"); config.setProviderName("SunJCE"); config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); config.setStringOutputType("base64"); encryptor.setConfig(config); return encryptor; }
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/ulisesbocchio/jasypt-spring-boot/issues/23#issuecomment-212654905
no problem buddy, it doesn't matter whether you use yaml or not. Just make your custom encryptor bean static and that should fix it. I'm closing this, please reopen should you haven further issues Best, Uli
I am getting below error -
Caused by: com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Decryption of Properties failed, make sure encryption/decryption passwords match
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.resolvePropertyValue(DefaultPropertyResolver.java:37) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver.resolvePropertyValue(DefaultLazyPropertyResolver.java:41) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.EncryptablePropertySource.getProperty(EncryptablePropertySource.java:16) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.wrapper.EncryptableMapPropertySourceWrapper.getProperty(EncryptableMapPropertySourceWrapper.java:29) ~[jasypt-spring-boot-1.16.jar:na]
at org.springframework.boot.bind.PropertySourcesPropertyValues.getEnumerableProperty(PropertySourcesPropertyValues.java:153) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertySourcesPropertyValues.processEnumerablePropertySource(PropertySourcesPropertyValues.java:136) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertySourcesPropertyValues.processPropertySource(PropertySourcesPropertyValues.java:115) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertySourcesPropertyValues.
Hi, I am using the approach No. 2 stated by you in your documentation. The issue I am facing is that I see this in the logs: Overriding bean definition for bean 'customBean': replacing [Root bean: class [com.test.Config]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=stringEncryptor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/test/Config.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.ulisesbocchio.jasyptspringboot.configuration.StringEncryptorConfiguration; factoryMethodName=stringEncryptor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ulisesbocchio/jasyptspringboot/configuration/StringEncryptorConfiguration.class]]
and then I see this,
String Encryptor custom Bean not found with name 'customBean'. Initializing String Encryptor based on properties with name 'customBean'
Why does it override the bean with a null class bean and then say that the customBean was not found?