Provides a way to disable DecryptEnvironmentPostProcessor.

Fixes gh-927
This commit is contained in:
spencergibb
2021-03-15 21:33:41 -04:00
parent 4995ffc88a
commit cde355e5e5
3 changed files with 21 additions and 1 deletions

View File

@@ -52,7 +52,7 @@ public class DecryptEnvironmentPostProcessor extends AbstractEnvironmentDecrypt
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (bootstrapEnabled(environment) || useLegacyProcessing(environment)) {
if (bootstrapEnabled(environment) || useLegacyProcessing(environment) || !isEnabled(environment)) {
return;
}
if (!ClassUtils.isPresent("org.springframework.security.crypto.encrypt.TextEncryptor", null)) {
@@ -71,4 +71,8 @@ public class DecryptEnvironmentPostProcessor extends AbstractEnvironmentDecrypt
}
protected Boolean isEnabled(ConfigurableEnvironment environment) {
return environment.getProperty("spring.cloud.decrypt-environment-post-processor.enabled", Boolean.class, true);
}
}

View File

@@ -47,6 +47,12 @@
"type": "java.lang.String",
"description": "Comma separated list of class names for beans to never be refreshed or rebound.",
"defaultValue": true
},
{
"name": "spring.cloud.decrypt-environment-post-processor.enabled",
"type": "java.lang.Boolean",
"description": "Enable the DecryptEnvironmentPostProcessor.",
"defaultValue": true
}
]
}

View File

@@ -98,6 +98,16 @@ public class EncryptionIntegrationTests {
then(context.getEnvironment().getProperty("foo.password")).isEqualTo("test");
}
@Test
public void decryptEnvironmentPostProcessorDisabled() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
.web(WebApplicationType.NONE).properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
"spring.cloud.decrypt-environment-post-processor.enabled=false",
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
.run();
then(context.getEnvironment().getProperty("foo.password")).startsWith("{cipher}bf2945");
}
@Test
public void symmetricConfigurationProperties() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)