1

I want to integrate Jasypt library with spring properties mechanism.

In example tutorial here: http://www.jasypt.org/spring31.html author assumed that user performed encryption manually and then only passed encrypted value between ENC( ) placeholders to the config file. It is not enough for me.

I want to achieve given scenario:

  1. Put this line into file with properies:

    datasource.password=DEC(mysecretpassword)
    
  2. Start application

  3. Spring Framework will encrypt password (using jasypt) and replace above line with:

    datasource.password=ENC(G6N718UuyPE5bHyWKyuLQSm02auQPUtm)
    

At further startups spring only decrypts encrypted value (e.g. using org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer) and file is not modified.

I suppose I need to create my own Spring's PropertyPlaceholderConfigurer but I don't see any possibility to modify file.

I can set custom org.springframework.util.PropertiesPersister to my PropertyPlaceholderConfigurer, okay, but I still don't know which file I need to update (in my spring @Configuration may be many properties locations, some properties can be override with value from another file etc.).

In other words: I need to inject my (de|en)cryption logic AFTER property resources resolving and merging, but BEFORE injecting values to another beans.

Thank you for advance for any advices how to solve this.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
It'sMe
  • 125
  • 1
  • 15
  • Did you try [BeanFactoryPostProcessor](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiuyoXT9ojLAhUOco4KHa5PBIMQFggcMAA&url=https%3A%2F%2Fdocs.spring.io%2Fspring%2Fdocs%2Fcurrent%2Fjavadoc-api%2Forg%2Fspringframework%2Fbeans%2Ffactory%2Fconfig%2FBeanFactoryPostProcessor.html&usg=AFQjCNHeAVk4k3q6y10UpFgyvsDQeTAc0Q&sig2=KPFxtn8CI07GmFxroWOgaQ) that allows you to execute custom logic before any bean creation. – Madhusudana Reddy Sunnapu Feb 21 '16 at 13:11

1 Answers1

0

An old problem that I solve with a solution that I found in a jira that I can't find it right now. Anyway, This is a very similar solution, In that way you "tell" the fw to load your propertiesPlaceHolder file before loading your dataSource beans.

Community
  • 1
  • 1
Hezi Schrager
  • 391
  • 6
  • 18