ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.91k stars 522 forks source link

Does it work with vanilla Spring 4/5 #22

Closed chenrui333 closed 8 years ago

chenrui333 commented 8 years ago

I did not see Jasypt have official support for Spring 4/5, but when I tried to include @EnableEncryptableProperties and @EncryptablePropertySource, it does not work as expected.

ulisesbocchio commented 8 years ago

It should work, @EnableEncryptableProperties imports some configuration that registers a BeanFactoryPostProcessor to decorate property sources present in the Environment. @EncryptablePropertySource is simpler, it just enables one specific property source with jasypt capabilities. Do you have (or can create) a test app in Github where the problem manifests?

chenrui333 commented 8 years ago

@ulisesbocchio Thanks for the reply. I will upload a sample later.

But I saw the spring-boot package get used in the EnableEncryptablePropertySourcesPostProcessor.java, could it be a problem?

chenrui333 commented 8 years ago

Here is ref repo: https://github.com/chenrui333/jyspert-spring-sample

The command line to run is ./gradlew appRun

chenrui333 commented 8 years ago

jasypt-spring-boot does not work with vanilla Spring as properties source loading is different, Spring Boot used PropertySourceLoader, while vanilla Spring used PropertySourcesPlaceholderConfigurer

ulisesbocchio commented 8 years ago

Alright, let me take a look at your project...sorry for the delay

chenrui333 commented 8 years ago

Thanks.

chenrui333 commented 8 years ago

Any update?

ulisesbocchio commented 8 years ago

I'll get back to you today... sorry for the delay

ulisesbocchio commented 8 years ago

You're missing this in your TestConfig:

@Bean
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

That's mandatory if you want to enable PropertySources in general. Basically, without that bean, not even Spring's @PropertySource annotation works. In Spring Boot, there's an auto configuration for it in org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration

chenrui333 commented 8 years ago

Let me re-try it. UPDATE: Works pretty good! Thanks!

chenrui333 commented 8 years ago

Another quick question is that whether I can use gradle to setup system property that it can be picked up by Spring configuration.

ulisesbocchio commented 8 years ago

you gotta pass the system property to tomcat or whatever servlet container you're using when you run your application if you use it out of the box. Otherwise you can define your own SpringEncryptor bean and retrieve the password from wherever you want.