This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 6c9c7ad14678 [backport camel-4.18.x] CAMEL-25106: camel-kafka -
sslContextParameters ignores the SSL endpoint options and does not use the SSL
security protocol (#30904)
6c9c7ad14678 is described below
commit 6c9c7ad14678e37c4d71e4c0dc8fbc688f8ef7c5
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Nov 28 08:14:01 2026 +0100
[backport camel-4.18.x] CAMEL-25106: camel-kafka - sslContextParameters
ignores the SSL endpoint options and does not use the SSL security protocol
(#30904)
Backport of #27010 to camel-4.18.x.
When sslContextParameters is configured, the SSL endpoint options (such as
sslTruststoreLocation) are now applied after it, and the SSL security protocol
is used when securityProtocol is left at its default (PLAINTEXT). Explicit
protocols such as SASL_SSL are kept. The second commit removes a duplicate
addUpperCasePropertyIfNotEmpty call for the truststore type that the
cherry-pick left in the consumer path.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
.../camel/component/kafka/KafkaConfiguration.java | 87 +++++++++++++++-------
.../kafka/KafkaSslContextParametersTest.java | 79 ++++++++++++++++++++
2 files changed, 139 insertions(+), 27 deletions(-)
diff --git
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
index 51fedf7dc615..6dab46bc3118 100755
---
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
+++
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
@@ -496,17 +497,17 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
addPropertyIfNotEmpty(props, ProducerConfig.TRANSACTIONAL_ID_CONFIG,
getTransactionalId());
addPropertyIfNotEmpty(props, "schema.registry.url",
getSchemaRegistryURL());
- // SSL
+ // SSL (the sslContextParameters are applied before the other SSL
endpoint options)
+ String protocol = resolveSecurityProtocol();
if (sslContextParameters != null) {
applySslConfigurationFromContext(props, sslContextParameters);
- } else {
- applyProducerSslConfiguration(props);
}
+ applyProducerSslConfiguration(props, protocol);
- addPropertyIfNotEmpty(props,
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
+ addPropertyIfNotEmpty(props,
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, protocol);
// SASL
- if (isSasl(securityProtocol)) {
+ if (isSasl(protocol)) {
applySaslConfiguration(props);
}
@@ -528,26 +529,55 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
addPropertyIfNotEmpty(props, SaslConfigs.SASL_JAAS_CONFIG,
getSaslJaasConfig());
}
- private void applyProducerSslConfiguration(Properties props) {
- if (securityProtocol.equals(SecurityProtocol.SSL.name()) ||
securityProtocol.equals(SecurityProtocol.SASL_SSL.name())) {
- addPropertyIfNotEmpty(props,
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, getSecurityProtocol());
+ /**
+ * The security protocol to use, which is SSL when sslContextParameters
are configured and the security protocol is
+ * the default (PLAINTEXT).
+ */
+ private String resolveSecurityProtocol() {
+ if (sslContextParameters != null &&
SecurityProtocol.PLAINTEXT.name().equals(securityProtocol)) {
+ return SecurityProtocol.SSL.name();
+ }
+ return securityProtocol;
+ }
+
+ /**
+ * Adds the SSL option, unless the option is its default value and the
value has already been configured from the
+ * sslContextParameters (which are applied before the SSL endpoint
options).
+ */
+ private void addSslOption(Properties props, String key, String value,
String defaultValue, boolean upperCase) {
+ if (sslContextParameters != null && Objects.equals(value,
defaultValue) && props.containsKey(key)) {
+ return;
+ }
+ if (upperCase) {
+ addUpperCasePropertyIfNotEmpty(props, key, value);
+ } else {
+ addPropertyIfNotEmpty(props, key, value);
+ }
+ }
+
+ private void applyProducerSslConfiguration(Properties props, String
protocol) {
+ if (protocol.equals(SecurityProtocol.SSL.name()) ||
protocol.equals(SecurityProtocol.SASL_SSL.name())) {
+ addPropertyIfNotEmpty(props,
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, protocol);
addPropertyIfNotNull(props, SslConfigs.SSL_KEY_PASSWORD_CONFIG,
getSslKeyPassword());
addPropertyIfNotEmpty(props,
SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, getSslKeystoreLocation());
addPropertyIfNotEmpty(props,
SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, getSslKeystorePassword());
addPropertyIfNotEmpty(props,
SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, getSslTruststoreLocation());
addPropertyIfNotEmpty(props,
SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, getSslTruststorePassword());
- addPropertyIfNotEmpty(props,
SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, getSslEnabledProtocols());
- addUpperCasePropertyIfNotEmpty(props,
SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, getSslKeystoreType());
- addPropertyIfNotEmpty(props, SslConfigs.SSL_PROTOCOL_CONFIG,
getSslProtocol());
+ addSslOption(props, SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG,
getSslEnabledProtocols(),
+ SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS, false);
+ addSslOption(props, SslConfigs.SSL_KEYSTORE_TYPE_CONFIG,
getSslKeystoreType(), SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE,
+ true);
+ addSslOption(props, SslConfigs.SSL_PROTOCOL_CONFIG,
getSslProtocol(), SslConfigs.DEFAULT_SSL_PROTOCOL, false);
addPropertyIfNotEmpty(props, SslConfigs.SSL_PROVIDER_CONFIG,
getSslProvider());
- addUpperCasePropertyIfNotEmpty(props,
SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, getSslTruststoreType());
+ addSslOption(props, SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG,
getSslTruststoreType(),
+ SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE, true);
addPropertyIfNotEmpty(props, SslConfigs.SSL_CIPHER_SUITES_CONFIG,
getSslCipherSuites());
String algo = getSslEndpointAlgorithm();
if (algo != null && !algo.equals("none") && !algo.equals("false"))
{
addPropertyIfNotNull(props,
SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, algo);
}
- addPropertyIfNotEmpty(props,
SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, getSslKeymanagerAlgorithm());
- addPropertyIfNotEmpty(props,
SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, getSslTrustmanagerAlgorithm());
+ addSslOption(props, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG,
getSslKeymanagerAlgorithm(), "SunX509", false);
+ addSslOption(props, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG,
getSslTrustmanagerAlgorithm(), "PKIX", false);
}
}
@@ -588,18 +618,18 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
addPropertyIfNotEmpty(props, "schema.registry.url",
getSchemaRegistryURL());
addPropertyIfNotFalse(props, "specific.avro.reader",
isSpecificAvroReader());
- // SSL
+ // SSL (the sslContextParameters are applied before the other SSL
endpoint options)
+ String protocol = resolveSecurityProtocol();
if (sslContextParameters != null) {
applySslConfigurationFromContext(props, sslContextParameters);
- } else {
- applySslConsumerConfigurationFromOptions(props);
}
+ applySslConsumerConfigurationFromOptions(props, protocol);
// Security protocol
- addPropertyIfNotEmpty(props,
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
+ addPropertyIfNotEmpty(props,
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, protocol);
// SASL
- if (isSasl(securityProtocol)) {
+ if (isSasl(protocol)) {
applySaslConfiguration(props);
}
@@ -614,8 +644,8 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
|| securityProtocol.equals(SecurityProtocol.SASL_SSL.name());
}
- private void applySslConsumerConfigurationFromOptions(Properties props) {
- if (securityProtocol.equals(SecurityProtocol.SSL.name()) ||
securityProtocol.equals(SecurityProtocol.SASL_SSL.name())) {
+ private void applySslConsumerConfigurationFromOptions(Properties props,
String protocol) {
+ if (protocol.equals(SecurityProtocol.SSL.name()) ||
protocol.equals(SecurityProtocol.SASL_SSL.name())) {
addPropertyIfNotNull(props, SslConfigs.SSL_KEY_PASSWORD_CONFIG,
getSslKeyPassword());
addPropertyIfNotEmpty(props,
SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, getSslKeystoreLocation());
addPropertyIfNotEmpty(props,
SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, getSslKeystorePassword());
@@ -626,13 +656,16 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
if (algo != null && !algo.equals("none") && !algo.equals("false"))
{
addPropertyIfNotNull(props,
SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, algo);
}
- addPropertyIfNotEmpty(props,
SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, getSslKeymanagerAlgorithm());
- addPropertyIfNotEmpty(props,
SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, getSslTrustmanagerAlgorithm());
- addPropertyIfNotEmpty(props,
SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, getSslEnabledProtocols());
- addUpperCasePropertyIfNotEmpty(props,
SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, getSslKeystoreType());
- addPropertyIfNotEmpty(props, SslConfigs.SSL_PROTOCOL_CONFIG,
getSslProtocol());
+ addSslOption(props, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG,
getSslKeymanagerAlgorithm(), "SunX509", false);
+ addSslOption(props, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG,
getSslTrustmanagerAlgorithm(), "PKIX", false);
+ addSslOption(props, SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG,
getSslEnabledProtocols(),
+ SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS, false);
+ addSslOption(props, SslConfigs.SSL_KEYSTORE_TYPE_CONFIG,
getSslKeystoreType(), SslConfigs.DEFAULT_SSL_KEYSTORE_TYPE,
+ true);
+ addSslOption(props, SslConfigs.SSL_PROTOCOL_CONFIG,
getSslProtocol(), SslConfigs.DEFAULT_SSL_PROTOCOL, false);
addPropertyIfNotEmpty(props, SslConfigs.SSL_PROVIDER_CONFIG,
getSslProvider());
- addUpperCasePropertyIfNotEmpty(props,
SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, getSslTruststoreType());
+ addSslOption(props, SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG,
getSslTruststoreType(),
+ SslConfigs.DEFAULT_SSL_TRUSTSTORE_TYPE, true);
addPropertyIfNotEmpty(props, ProducerConfig.SEND_BUFFER_CONFIG,
getSendBufferBytes());
}
}
diff --git
a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSslContextParametersTest.java
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSslContextParametersTest.java
new file mode 100644
index 000000000000..8b452d30c0c2
--- /dev/null
+++
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSslContextParametersTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.component.kafka;
+
+import java.util.Properties;
+
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.common.config.SslConfigs;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class KafkaSslContextParametersTest {
+
+ private static SSLContextParameters sslContextParameters() {
+ KeyStoreParameters keyStore = new KeyStoreParameters();
+ keyStore.setResource("file:/global/trust.p12");
+ keyStore.setType("PKCS12");
+ keyStore.setPassword("global-password");
+ TrustManagersParameters trustManagers = new TrustManagersParameters();
+ trustManagers.setKeyStore(keyStore);
+ SSLContextParameters scp = new SSLContextParameters();
+ scp.setTrustManagers(trustManagers);
+ return scp;
+ }
+
+ @Test
+ public void testSslContextParametersUseSsl() {
+ KafkaConfiguration kcfg = new KafkaConfiguration();
+ kcfg.setSslContextParameters(sslContextParameters());
+
+ for (Properties props : new Properties[] {
kcfg.createProducerProperties(), kcfg.createConsumerProperties() }) {
+ assertEquals("SSL",
props.getProperty(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
+ assertEquals("/global/trust.p12",
props.getProperty(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG));
+ // the type from the sslContextParameters is not replaced by the
default of the endpoint option
+ assertEquals("PKCS12",
props.getProperty(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG));
+ }
+ }
+
+ @Test
+ public void testEndpointOptionsAppliedAfterSslContextParameters() {
+ KafkaConfiguration kcfg = new KafkaConfiguration();
+ kcfg.setSslContextParameters(sslContextParameters());
+ kcfg.setSslTruststoreLocation("/strict/endpoint-trust.p12");
+ kcfg.setSslTruststorePassword("endpoint-password");
+
+ for (Properties props : new Properties[] {
kcfg.createProducerProperties(), kcfg.createConsumerProperties() }) {
+ assertEquals("/strict/endpoint-trust.p12",
props.getProperty(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG));
+ assertEquals("endpoint-password",
props.getProperty(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG));
+ assertEquals("https",
props.getProperty(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG));
+ }
+ }
+
+ @Test
+ public void testExplicitSecurityProtocolKept() {
+ KafkaConfiguration kcfg = new KafkaConfiguration();
+ kcfg.setSslContextParameters(sslContextParameters());
+ kcfg.setSecurityProtocol("SASL_SSL");
+
+ assertEquals("SASL_SSL",
kcfg.createProducerProperties().getProperty(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
+ }
+}