GH-2882: Schema registry SSL config propagation

Fixes: https://github.com/spring-cloud/spring-cloud-stream/issues/2882

When providing schema registry SSL truststore and keystore properties
as classpath URL's under Kafka binder configuration, the transformations
of them into corresponding filesystem URL's are not currenlty propagated
into producerProperties and consumerProperties under binder configuration.
This is ncessary for certain serializer/deserializer to work.
See the related GH issue for more context on this.
This commit is contained in:
Soby Chacko
2024-02-01 13:35:45 -05:00
parent 959c372c4b
commit 3f9162b8b4
2 changed files with 31 additions and 1 deletions

View File

@@ -205,6 +205,12 @@ public class KafkaBinderConfigurationProperties {
final String fileSystemLocation = moveCertToFileSystem(storeLocation, this.certificateStoreDirectory);
// Overriding the value with absolute filesystem path.
this.configuration.put(storeProperty, fileSystemLocation);
// Provide schema-registry properties as producer and consumer properties
// for potential usage by specific serializers/deserializers downstream
if (storeProperty.startsWith("schema.registry")) {
this.producerProperties.put(storeProperty, fileSystemLocation);
this.consumerProperties.put(storeProperty, fileSystemLocation);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -197,6 +197,30 @@ class KafkaBinderConfigurationPropertiesTest {
Paths.get(Files.currentFolder().toString(), "target", "testclient.truststore").toString());
assertThat(configuration.get("schema.registry.ssl.keystore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.keystore").toString());
final Map<String, String> producerProperties = kafkaBinderConfigurationProperties.getProducerProperties();
assertThat(producerProperties.get("schema.registry.ssl.truststore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.truststore").toString());
assertThat(producerProperties.get("schema.registry.ssl.keystore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.keystore").toString());
final Map<String, String> consumerProperties = kafkaBinderConfigurationProperties.getConsumerProperties();
assertThat(consumerProperties.get("schema.registry.ssl.truststore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.truststore").toString());
assertThat(consumerProperties.get("schema.registry.ssl.keystore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.keystore").toString());
final Map<String, Object> mergedProducerConfiguration = kafkaBinderConfigurationProperties.mergedProducerConfiguration();
assertThat(mergedProducerConfiguration.get("schema.registry.ssl.truststore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.truststore").toString());
assertThat(mergedProducerConfiguration.get("schema.registry.ssl.keystore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.keystore").toString());
final Map<String, Object> mergedConsumerConfiguration = kafkaBinderConfigurationProperties.mergedConsumerConfiguration();
assertThat(mergedConsumerConfiguration.get("schema.registry.ssl.truststore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.truststore").toString());
assertThat(mergedConsumerConfiguration.get("schema.registry.ssl.keystore.location")).isEqualTo(
Paths.get(Files.currentFolder().toString(), "target", "testclient.keystore").toString());
}
private void createContextWithCertFileHandler(HttpServer server, String path) {