You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2024/05/02 12:01:07 UTC
(camel-quarkus) 02/02: Make Jasypt SmallRye Config integration operate only on runtime properties
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch 3.8.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 43943c906f8b922020c7af1f49011b55fc7fa9cf
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Apr 22 11:30:07 2024 +0100
Make Jasypt SmallRye Config integration operate only on runtime properties
Fixes #5946
---
.../jasypt/deployment/JasyptProcessor.java | 32 ++++++++++++++++------
.../quarkus/component/jasypt/JasyptDevUITest.java | 2 --
.../CamelJasyptConfigSourceInterceptorFactory.java | 9 +-----
.../component/jasypt/CamelJasyptRecorder.java | 17 +++++-------
.../jasypt/CamelJasyptRuntimeConfigBuilder.java | 28 +++++++++++++++++++
.../CamelJasyptSecretKeysHandlerFactory.java | 14 ++--------
....smallrye.config.ConfigSourceInterceptorFactory | 1 -
.../io.smallrye.config.SecretKeysHandlerFactory | 1 -
integration-tests/jasypt/pom.xml | 9 ------
.../jasypt/it/JasyptSecureExtensionConfigTest.java | 9 ------
.../it/JasyptSecureExtensionConfigTestProfile.java | 8 ------
11 files changed, 61 insertions(+), 69 deletions(-)
diff --git a/extensions/jasypt/deployment/src/main/java/org/apache/camel/quarkus/component/jasypt/deployment/JasyptProcessor.java b/extensions/jasypt/deployment/src/main/java/org/apache/camel/quarkus/component/jasypt/deployment/JasyptProcessor.java
index ee9595c1d6..bd87b43d00 100644
--- a/extensions/jasypt/deployment/src/main/java/org/apache/camel/quarkus/component/jasypt/deployment/JasyptProcessor.java
+++ b/extensions/jasypt/deployment/src/main/java/org/apache/camel/quarkus/component/jasypt/deployment/JasyptProcessor.java
@@ -16,16 +16,19 @@
*/
package org.apache.camel.quarkus.component.jasypt.deployment;
+import java.util.function.BooleanSupplier;
+
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.quarkus.component.jasypt.CamelJasyptBuildTimeConfig;
-import org.apache.camel.quarkus.component.jasypt.CamelJasyptConfig;
import org.apache.camel.quarkus.component.jasypt.CamelJasyptRecorder;
+import org.apache.camel.quarkus.component.jasypt.CamelJasyptRuntimeConfigBuilder;
import org.apache.camel.quarkus.component.jasypt.JasyptConfigurationCustomizer;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.RuntimeCamelContextCustomizerBuildItem;
@@ -53,21 +56,32 @@ class JasyptProcessor {
}
@Record(ExecutionTime.RUNTIME_INIT)
- @BuildStep
+ @BuildStep(onlyIf = CamelJasyptEnabled.class)
void disableCamelMainAutoConfigFromSysEnv(
CamelMainBuildItem camelMain,
- CamelJasyptConfig config,
CamelJasyptRecorder recorder) {
// Avoid camel-main overriding system / environment config values that were already resolved by SmallRye config.
// Else there's the potential for encrypted property values to be overridden with their raw ENC(..) form
- recorder.disableCamelMainAutoConfigFromSysEnv(camelMain.getInstance(), config);
+ recorder.disableCamelMainAutoConfigFromSysEnv(camelMain.getInstance());
}
@Record(ExecutionTime.RUNTIME_INIT)
- @BuildStep
- RuntimeCamelContextCustomizerBuildItem propertiesComponentRuntimeCamelContextCustomizer(
- CamelJasyptBuildTimeConfig config,
- CamelJasyptRecorder recorder) {
- return new RuntimeCamelContextCustomizerBuildItem(recorder.createPropertiesComponentCamelContextCustomizer(config));
+ @BuildStep(onlyIf = CamelJasyptEnabled.class)
+ RuntimeCamelContextCustomizerBuildItem propertiesComponentRuntimeCamelContextCustomizer(CamelJasyptRecorder recorder) {
+ return new RuntimeCamelContextCustomizerBuildItem(recorder.createPropertiesComponentCamelContextCustomizer());
+ }
+
+ @BuildStep(onlyIf = CamelJasyptEnabled.class)
+ RunTimeConfigBuilderBuildItem jasyptRuntimeConfigBuilder() {
+ return new RunTimeConfigBuilderBuildItem(CamelJasyptRuntimeConfigBuilder.class.getName());
+ }
+
+ static final class CamelJasyptEnabled implements BooleanSupplier {
+ CamelJasyptBuildTimeConfig config;
+
+ @Override
+ public boolean getAsBoolean() {
+ return config.enabled;
+ }
}
}
diff --git a/extensions/jasypt/deployment/src/test/java/org/apache/camel/quarkus/component/jasypt/JasyptDevUITest.java b/extensions/jasypt/deployment/src/test/java/org/apache/camel/quarkus/component/jasypt/JasyptDevUITest.java
index 17445d072d..cd770f4d77 100644
--- a/extensions/jasypt/deployment/src/test/java/org/apache/camel/quarkus/component/jasypt/JasyptDevUITest.java
+++ b/extensions/jasypt/deployment/src/test/java/org/apache/camel/quarkus/component/jasypt/JasyptDevUITest.java
@@ -23,14 +23,12 @@ import io.quarkus.test.QuarkusDevModeTest;
import org.apache.camel.util.ObjectHelper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-@Disabled("https://github.com/apache/camel-quarkus/issues/5946")
public class JasyptDevUITest extends DevUIJsonRPCTest {
@RegisterExtension
static final QuarkusDevModeTest CONFIG = new QuarkusDevModeTest().withEmptyApplication();
diff --git a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptConfigSourceInterceptorFactory.java b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptConfigSourceInterceptorFactory.java
index b6210f813f..8e04ad57ff 100644
--- a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptConfigSourceInterceptorFactory.java
+++ b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptConfigSourceInterceptorFactory.java
@@ -32,20 +32,13 @@ import org.jasypt.properties.PropertyValueEncryptionUtils;
* requirement for the user automatically.
*/
public class CamelJasyptConfigSourceInterceptorFactory implements ConfigSourceInterceptorFactory {
- private boolean enabled = true;
-
@Override
public ConfigSourceInterceptor getInterceptor(ConfigSourceInterceptorContext context) {
- ConfigValue enabledConfigValue = context.proceed("quarkus.camel.jasypt.enabled");
- if (enabledConfigValue != null) {
- enabled = Boolean.parseBoolean(enabledConfigValue.getValue());
- }
-
return new ConfigSourceInterceptor() {
@Override
public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
ConfigValue configValue = context.proceed(name);
- if (enabled && configValue != null) {
+ if (configValue != null) {
String value = configValue.getValue();
if (PropertyValueEncryptionUtils.isEncryptedValue(value)) {
return configValue.withValue("${camel-jasypt::%s}".formatted(value));
diff --git a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRecorder.java b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRecorder.java
index b917307f73..9e8df12d55 100644
--- a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRecorder.java
+++ b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRecorder.java
@@ -27,25 +27,22 @@ import org.apache.camel.spi.CamelContextCustomizer;
@Recorder
public class CamelJasyptRecorder {
- public void disableCamelMainAutoConfigFromSysEnv(RuntimeValue<CamelMain> camelMainRuntimeValue, CamelJasyptConfig config) {
+ public void disableCamelMainAutoConfigFromSysEnv(RuntimeValue<CamelMain> camelMainRuntimeValue) {
CamelMain main = camelMainRuntimeValue.getValue();
MainConfigurationProperties configurationProperties = main.getMainConfigurationProperties();
configurationProperties.setAutoConfigurationSystemPropertiesEnabled(false);
configurationProperties.setAutoConfigurationEnvironmentVariablesEnabled(false);
}
- public RuntimeValue<CamelContextCustomizer> createPropertiesComponentCamelContextCustomizer(
- CamelJasyptBuildTimeConfig config) {
+ public RuntimeValue<CamelContextCustomizer> createPropertiesComponentCamelContextCustomizer() {
return new RuntimeValue<>(new CamelContextCustomizer() {
@Override
public void configure(CamelContext camelContext) {
- if (config.enabled) {
- PropertiesComponent component = (PropertiesComponent) camelContext.getPropertiesComponent();
- JasyptPropertiesParser jasyptPropertiesParser = CamelJasyptPropertiesParserHolder
- .getJasyptPropertiesParser();
- jasyptPropertiesParser.setPropertiesComponent(component);
- component.setPropertiesParser(jasyptPropertiesParser);
- }
+ PropertiesComponent component = (PropertiesComponent) camelContext.getPropertiesComponent();
+ JasyptPropertiesParser jasyptPropertiesParser = CamelJasyptPropertiesParserHolder
+ .getJasyptPropertiesParser();
+ jasyptPropertiesParser.setPropertiesComponent(component);
+ component.setPropertiesParser(jasyptPropertiesParser);
}
});
}
diff --git a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRuntimeConfigBuilder.java b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRuntimeConfigBuilder.java
new file mode 100644
index 0000000000..31e13f8afa
--- /dev/null
+++ b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptRuntimeConfigBuilder.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.jasypt;
+
+import io.quarkus.runtime.configuration.ConfigBuilder;
+import io.smallrye.config.SmallRyeConfigBuilder;
+
+public class CamelJasyptRuntimeConfigBuilder implements ConfigBuilder {
+ @Override
+ public SmallRyeConfigBuilder configBuilder(SmallRyeConfigBuilder builder) {
+ return builder.withInterceptorFactories(new CamelJasyptConfigSourceInterceptorFactory())
+ .withSecretKeyHandlerFactories(new CamelJasyptSecretKeysHandlerFactory());
+ }
+}
diff --git a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptSecretKeysHandlerFactory.java b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptSecretKeysHandlerFactory.java
index 9be3557c04..163baecfce 100644
--- a/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptSecretKeysHandlerFactory.java
+++ b/extensions/jasypt/runtime/src/main/java/org/apache/camel/quarkus/component/jasypt/CamelJasyptSecretKeysHandlerFactory.java
@@ -58,22 +58,12 @@ public class CamelJasyptSecretKeysHandlerFactory implements SecretKeysHandlerFac
@Override
public SecretKeysHandler getSecretKeysHandler(ConfigSourceContext context) {
- String enabledValue = getConfigValue(context, "enabled", "true");
- if (enabledValue != null) {
- enabled = Boolean.parseBoolean(enabledValue);
- }
-
- if (enabled) {
- configureJasypt(context);
- }
+ configureJasypt(context);
return new SecretKeysHandler() {
@Override
public String decode(String secret) {
- if (enabled) {
- return parser.parseProperty("", secret, null);
- }
- return secret;
+ return parser.parseProperty("", secret, null);
}
@Override
diff --git a/extensions/jasypt/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptorFactory b/extensions/jasypt/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptorFactory
deleted file mode 100644
index c3222d1ab9..0000000000
--- a/extensions/jasypt/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptorFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.camel.quarkus.component.jasypt.CamelJasyptConfigSourceInterceptorFactory
\ No newline at end of file
diff --git a/extensions/jasypt/runtime/src/main/resources/META-INF/services/io.smallrye.config.SecretKeysHandlerFactory b/extensions/jasypt/runtime/src/main/resources/META-INF/services/io.smallrye.config.SecretKeysHandlerFactory
deleted file mode 100644
index 95200099fe..0000000000
--- a/extensions/jasypt/runtime/src/main/resources/META-INF/services/io.smallrye.config.SecretKeysHandlerFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.camel.quarkus.component.jasypt.CamelJasyptSecretKeysHandlerFactory
\ No newline at end of file
diff --git a/integration-tests/jasypt/pom.xml b/integration-tests/jasypt/pom.xml
index b740b63db0..4b8e3b5bf3 100644
--- a/integration-tests/jasypt/pom.xml
+++ b/integration-tests/jasypt/pom.xml
@@ -63,10 +63,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
- <dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-jdbc-h2</artifactId>
- </dependency>
<!-- test dependencies -->
<dependency>
@@ -79,11 +75,6 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-test-h2</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-test-support</artifactId>
diff --git a/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTest.java b/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTest.java
index b460754309..40a33f2de4 100644
--- a/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTest.java
+++ b/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTest.java
@@ -27,15 +27,6 @@ import static org.hamcrest.Matchers.is;
@QuarkusTest
@TestProfile(JasyptSecureExtensionConfigTestProfile.class)
class JasyptSecureExtensionConfigTest {
- @Test
- void secureDatabaseCredentials() throws InterruptedException {
- RestAssured.given()
- .get("/jasypt/secure/database")
- .then()
- .statusCode(200)
- .body(is("camel"));
- }
-
@DisabledIfEnvironmentVariable(named = "CI", matches = "true", disabledReason = "https://github.com/apache/camel-quarkus/issues/5675")
@Test
void secureDirectComponentTimeout() throws InterruptedException {
diff --git a/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTestProfile.java b/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTestProfile.java
index 38172767bb..bdf7093f9a 100644
--- a/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTestProfile.java
+++ b/integration-tests/jasypt/src/test/java/org/apache/camel/quarkus/component/jasypt/it/JasyptSecureExtensionConfigTestProfile.java
@@ -26,14 +26,6 @@ public class JasyptSecureExtensionConfigTestProfile implements QuarkusTestProfil
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
- // camel
- "quarkus.datasource.devservices.username",
- "ENC(ehEx3VxgoFVuReSFsgyUrw==)",
- "quarkus.datasource.username", "${camel-jasypt::${quarkus.datasource.devservices.username}}",
- // c4m31s3cr3t
- "quarkus.datasource.devservices.password",
- "ENC(ySRd4rq2bAuKEDe7wvcS37xERpu5+DgK)",
- "quarkus.datasource.password", "${camel-jasypt::${quarkus.datasource.devservices.password}}",
"camel.component.direct.timeout", "ENC(FGlWjTf42zBT4vCRCztncA==)");
}
}