0

I'm on a Spring project and have skill level 1 with Spring. 2 days I have been reading and trying to get Jasypt encryption working with some existing code but the value that is passed is the ENC(....) value that needs to be transformed.

The one project that I'm to look at is a self ran project using a main() whereas the one I am on is a service that is called and does not run as the other.

I was last looking over this example Spring EnableEncryptableProperties with Jasypt but I noticed after awhile that it is pulling it's properties with the method call: environment.getRequiredProperty("spring.datasource.username")

The method is pulling from the System variables which I don't see how the propertied get into it. None of the properties that are in my property file are present in the System property level.

What am I missing here as to how to get the system properties updated with what is in the application.properties file?

The other project is updating the System properties and then calls SpringApplication.run(Application.class, args), which is not applicable to this other project as it is not the same type of application.

Would love some guidance. Please no smart remarks as to take a class. I'm doing what I can outside of work but being at step 4 and the project is at step 321 it's going to be awhile before I get there.

ETO
  • 6,970
  • 1
  • 20
  • 37
edjm
  • 4,830
  • 7
  • 36
  • 65
  • May want to add the relevant code to this to get some help on it. – Darren Forsythe Nov 27 '18 at 18:05
  • 1
    I'm not sure exactly what you are asking about as the title seems to be different from the actual question. Spring's [Environment](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/env/Environment.html) class not only loads the system properties but also any properties you specify via i.e. `@PropertySource({...})`. Spring Boot i.e. will automatically load `application.yml` or `application.propperties` for you in the back. You might want to [read up](https://www.baeldung.com/properties-with-spring) on property managment with Spring/Boot – Roman Vottner Nov 27 '18 at 18:23
  • Code is on a sandbox system. – edjm Nov 27 '18 at 18:52
  • Also, in regards to the Jasypt, I see examples but I'm looking for clarity on what precisely is to be set that the magic box knows to convert the ENC(..). Is the Jasypt just inspecting all properties and anything that has the ENC(...) gets handled, or is there someplace that we pass the String value that has the ENC(...) to some Jasypt method() that I'm not seeing? – edjm Nov 27 '18 at 18:54

1 Answers1

0

If you want to execute some code before actual Spring been creation, you can use implement your custom BeanFactoryPostprocessor. Here is an example with EnvironmentPostProcessor, which can be useful for your situation with encrypted properties: example

You can implement postProcessEnvironment in a next way:

  • Get all props from an environment
  • Check if a property value has 'ENC()'
  • Decrypt and set its value back

I believe that EncrytablePropertySource from jasypt-starter works in that way.

P. S. It's better to use the default approach with @EncrytablePropertySource if it is possible than reinventing a wheel with custom EnvironmentPostProcessor.

Community
  • 1
  • 1