Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs update: Mixing @Bean("jasyptStringEncryptor") with jasypt-spring-boot-starter #79

Closed
netwolfuk opened this issue Apr 11, 2018 · 8 comments
Labels

Comments

@netwolfuk
Copy link

netwolfuk commented Apr 11, 2018

TL;DR
Could you make it more obvious from the docs that if you have a custom @Bean("jasyptStringEncryptor"), you can't use jasypt-spring-boot-starter, you must use jasypt-spring-boot and @EnableEncryptableProperties


Firstly. thanks for such a great library.

We are using Spring 1.5.x, so I am using jasypt-spring-boot 1.17

I had a requirement to load the password from another file, so built a custom StringEncryptor and inject the password resolver with spring. eg, I do it like this.

    @Bean("jasyptStringEncryptor")
    public static StringEncryptor stringEncryptor(
    		@Qualifier("propertiesPasswordProvider") PasswordProvider passwordProvider
    		) {
    	log.info("jasyptStringEncryptor requested");
    	return JasyptConfiguration.stringEncryptor(passwordProvider);
    }

However, if I used jasypt-spring-boot-starter, it would not use my custom encryptor, but instead would complain that I had not passed in the password with --jasypt.encryptor.password

Switching to jasypt-spring-boot and removing the autoconfigure magic, but adding @EnableEncryptableProperties worked around this issue.

The weird thing was that it would work in Eclipse in Windows, but not when the SpringBoot app was bundled as a jar and run on our Linux dev server (eg, java -jar app.jar).

I'm not sure this is a bug in 1.17, but it might help someone else if that was a little more obvious in the documentation that the two are not compatible.

Also, "wanna" is not a valid english word. It would be nice to replace all "wanna" with "want to" in your docs.

@ulisesbocchio
Copy link
Owner

alright, will take a look and see if there's a bug...in Spring. The starter jar uses the exact same config as the annotation, literally. The only difference is when they're loaded. In theory, there should be no difference since the spring.factories beans and the application-provided beans end up in the same context, and the BeanFactoryPostProcessor that loads the encryption config should be triggered after ALL bean are loaded, hence the name "post processor". But you never know...

@netwolfuk
Copy link
Author

Perhaps I was doing something wrong. When I made this little change it started working. I don't think I did anything else, but can look back through the git history if you want me to.

@netwolfuk
Copy link
Author

netwolfuk commented Apr 16, 2018

Just re-reading your comment:

the BeanFactoryPostProcessor that loads the encryption config should be triggered after ALL bean are loaded

I wonder if this is the problem for me.

I need some beans to be loaded, so that I can constructor inject the PasswordProvider, but other beans will need the @Value decrypted for them to be instantiated.

Perhaps that is more the issue, and it's a subtle chicken and egg problem.

@ulisesbocchio
Copy link
Owner

Yeah, sounds like you’re onto something there. If you pull properties on the lifecycle of your encryptor bean...

@apacheshine
Copy link

Thanks for this niubility lib firstly and thanks for netwolfuk ! I met the same trouble. use ur way then ok.
should use jaspyt-spring-boot not starter and use @EnableEncryptableProperties magic .
This magic must to be placed on the Springboot start class.

@hauntingEcho
Copy link

I'm not having this issue, using spring-boot-starter-parent version 2.1.2

@apacheshine
Copy link

Maybe, It's the bug for springboot 1.5.x.

@ulisesbocchio
Copy link
Owner

I tried both the starter and annotation ways on all demo apps and everything works fine with spring boot 2.X. Seems like an issue with spring boot 1.X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants