diff --git a/jasypt-spring-boot-starter/pom.xml b/jasypt-spring-boot-starter/pom.xml index 850d82d..943b5e1 100644 --- a/jasypt-spring-boot-starter/pom.xml +++ b/jasypt-spring-boot-starter/pom.xml @@ -47,5 +47,10 @@ system-rules test + + org.projectlombok + lombok + provided + diff --git a/jasypt-spring-boot-starter/src/test/java/com/ulisesbocchio/jasyptspringboot/BootstrappingJasyptConfigurationTest.java b/jasypt-spring-boot-starter/src/test/java/com/ulisesbocchio/jasyptspringboot/BootstrappingJasyptConfigurationTest.java index ad2611d..196da3a 100644 --- a/jasypt-spring-boot-starter/src/test/java/com/ulisesbocchio/jasyptspringboot/BootstrappingJasyptConfigurationTest.java +++ b/jasypt-spring-boot-starter/src/test/java/com/ulisesbocchio/jasyptspringboot/BootstrappingJasyptConfigurationTest.java @@ -6,7 +6,7 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; +import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.cloud.bootstrap.BootstrapApplicationListener; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; @@ -40,13 +40,11 @@ public void issue_notDecryptedDuringBoostrapPhase() { startWith(new BaseBootstrappingTestListener() { @Override - public void onApplicationEvent(final ApplicationEnvironmentPreparedEvent event) { - assertFalse("ENC() value is not decrypted during bootstrap phase", - event.getEnvironment().getProperty("spring.cloud.config.server.svn.password").equals("mypassword")); + public void onApplicationEvent(final ApplicationStartedEvent event) { + assertEquals("ENC() value is not decrypted during bootstrap phase", "mypassword", event.getApplicationContext().getEnvironment().getProperty("spring.cloud.config.server.svn.password")); } }, "--spring.cloud.bootstrap.enabled=true", "--jasypt.encryptor.bootstrap=false"); - // to get codacy to pass. assertNotNull(this.context.getBean(EnableEncryptablePropertiesBeanFactoryPostProcessor.class)); } @@ -57,26 +55,36 @@ public void fix_decryptedDuringBoostrapPhase() { startWith(new BaseBootstrappingTestListener() { @Override - public void onApplicationEvent(final ApplicationEnvironmentPreparedEvent event) { - assertTrue("ENC() value is decrypted during bootstrap phase", - event.getEnvironment().getProperty("spring.cloud.config.server.svn.password").equals("mypassword")); + public void onApplicationEvent(final ApplicationStartedEvent event) { + assertEquals("ENC() value is decrypted during bootstrap phase", "mypassword", event.getApplicationContext().getEnvironment().getProperty("spring.cloud.config.server.svn.password")); } }, "--spring.cloud.bootstrap.enabled=true", "--jasypt.encryptor.bootstrap=true"); - // to get codacy to pass. assertNotNull(this.context.getBean(EnableEncryptablePropertiesBeanFactoryPostProcessor.class)); } @Test public void encryptableBFPPBeanCreatedWhenBoostrapTrue() { - startWith(null, "--spring.cloud.bootstrap.enabled=true"); + startWith(new BaseBootstrappingTestListener() { + + @Override + public void onApplicationEvent(final ApplicationStartedEvent event) { + assertEquals("ENC() value is decrypted during bootstrap phase", "mypassword", event.getApplicationContext().getEnvironment().getProperty("spring.cloud.config.server.svn.password")); + } + }, "--spring.cloud.bootstrap.enabled=true"); assertNotNull("EnableEncryptablePropertiesBeanFactoryPostProcessor not created when spring.cloud.bootstrap.enabled=true", this.context.getBean(EnableEncryptablePropertiesBeanFactoryPostProcessor.class)); } @Test public void encryptableBFPPBeanCreatedWhenBoostrapFalse() { - startWith(null, "--spring.cloud.bootstrap.enabled=false"); + startWith(new BaseBootstrappingTestListener() { + + @Override + public void onApplicationEvent(final ApplicationStartedEvent event) { + assertNotEquals("ENC() value is decrypted during bootstrap phase", "mypassword", event.getApplicationContext().getEnvironment().getProperty("spring.cloud.config.server.svn.password")); + } + }, "--spring.cloud.bootstrap.enabled=false"); assertNotNull("EnableEncryptablePropertiesBeanFactoryPostProcessor not created when spring.cloud.bootstrap.enabled=false", this.context.getBean(EnableEncryptablePropertiesBeanFactoryPostProcessor.class)); } @@ -107,7 +115,7 @@ static class BootstrapConfig { } static abstract class BaseBootstrappingTestListener - implements ApplicationListener, Ordered { + implements ApplicationListener, Ordered { @Override public int getOrder() { diff --git a/jasypt-spring-boot/src/main/java/com/ulisesbocchio/jasyptspringboot/resolver/DefaultPropertyResolver.java b/jasypt-spring-boot/src/main/java/com/ulisesbocchio/jasyptspringboot/resolver/DefaultPropertyResolver.java index 8540a55..34167eb 100644 --- a/jasypt-spring-boot/src/main/java/com/ulisesbocchio/jasyptspringboot/resolver/DefaultPropertyResolver.java +++ b/jasypt-spring-boot/src/main/java/com/ulisesbocchio/jasyptspringboot/resolver/DefaultPropertyResolver.java @@ -43,7 +43,7 @@ public String resolvePropertyValue(String value) { String resolvedProperty = environment.resolveRequiredPlaceholders(unwrappedProperty); return encryptor.decrypt(resolvedProperty); } catch (EncryptionOperationNotPossibleException e) { - throw new DecryptionException("Decryption of Properties failed, make sure encryption/decryption " + + throw new DecryptionException("Unable to decrypt: " + value + ". Decryption of Properties failed, make sure encryption/decryption " + "passwords match", e); } }) diff --git a/pom.xml b/pom.xml index 3f30fb8..2448215 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ UTF-8 1.8 2.2.1.RELEASE - Finchley.RELEASE + Greenwich.SR3 1.9.3 3.7.0 1.19.0