This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.22.x by this push:
new 8516902f5c97 [backport camel-4.22.x] CAMEL-25106: camel-kafka -
sslContextParameters ignores the SSL endpoint options and does not use the SSL
security protocol (#30903)
8516902f5c97 is described below
commit 8516902f5c9782a0bd32c04727bca5b8cad1fcdd
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 27 06:52:03 2026 +0100
[backport camel-4.22.x] CAMEL-25106: camel-kafka - sslContextParameters
ignores the SSL endpoint options and does not use the SSL security protocol
(#30903)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
(cherry picked from commit 7057526605849e02dfc85b83ef3223abef238650)
---
.../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 839bc81df83d..67d236131f3e 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;
@@ -506,17 +507,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);
}
@@ -538,19 +539,48 @@ 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"))
{
@@ -558,8 +588,8 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
} else {
props.put(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, "");
}
- 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);
}
}
@@ -609,18 +639,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);
}
@@ -635,8 +665,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());
@@ -649,13 +679,16 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
} else {
props.put(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, "");
}
- 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);
}
}
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));
+ }
+}