Skip to content

Commit ec6415f

Browse files
Add SSL bundle support to Apache Kafka auto-configuration
Closes gh-37629 Co-authored-by: Scott Frederick <sfrederick@vmware.com>
1 parent af2e363 commit ec6415f

File tree

8 files changed

+325
-56
lines changed

8 files changed

+325
-56
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAnnotationDrivenConfiguration.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2424
import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading;
2525
import org.springframework.boot.autoconfigure.thread.Threading;
26+
import org.springframework.boot.ssl.SslBundles;
2627
import org.springframework.context.annotation.Bean;
2728
import org.springframework.context.annotation.Configuration;
2829
import org.springframework.core.task.SimpleAsyncTaskExecutor;
@@ -53,6 +54,8 @@
5354
* @author Eddú Meléndez
5455
* @author Thomas Kåsene
5556
* @author Moritz Halbritter
57+
* @author Andy Wilkinson
58+
* @author Scott Frederick
5659
*/
5760
@Configuration(proxyBeanMethods = false)
5861
@ConditionalOnClass(EnableKafka.class)
@@ -149,10 +152,11 @@ private ConcurrentKafkaListenerContainerFactoryConfigurer configurer() {
149152
ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
150153
ConcurrentKafkaListenerContainerFactoryConfigurer configurer,
151154
ObjectProvider<ConsumerFactory<Object, Object>> kafkaConsumerFactory,
152-
ObjectProvider<ContainerCustomizer<Object, Object, ConcurrentMessageListenerContainer<Object, Object>>> kafkaContainerCustomizer) {
155+
ObjectProvider<ContainerCustomizer<Object, Object, ConcurrentMessageListenerContainer<Object, Object>>> kafkaContainerCustomizer,
156+
ObjectProvider<SslBundles> sslBundles) {
153157
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
154-
configurer.configure(factory, kafkaConsumerFactory
155-
.getIfAvailable(() -> new DefaultKafkaConsumerFactory<>(this.properties.buildConsumerProperties())));
158+
configurer.configure(factory, kafkaConsumerFactory.getIfAvailable(() -> new DefaultKafkaConsumerFactory<>(
159+
this.properties.buildConsumerProperties(sslBundles.getIfAvailable()))));
156160
kafkaContainerCustomizer.ifAvailable(factory::setContainerCustomizer);
157161
return factory;
158162
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Retry.Topic;
3636
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3737
import org.springframework.boot.context.properties.PropertyMapper;
38+
import org.springframework.boot.ssl.SslBundles;
3839
import org.springframework.context.annotation.Bean;
3940
import org.springframework.context.annotation.Import;
4041
import org.springframework.kafka.core.ConsumerFactory;
@@ -64,6 +65,8 @@
6465
* @author Moritz Halbritter
6566
* @author Andy Wilkinson
6667
* @author Phillip Webb
68+
* @author Andy Wilkinson
69+
* @author Scott Frederick
6770
* @since 1.5.0
6871
*/
6972
@AutoConfiguration
@@ -107,8 +110,8 @@ public LoggingProducerListener<Object, Object> kafkaProducerListener() {
107110
@Bean
108111
@ConditionalOnMissingBean(ConsumerFactory.class)
109112
public DefaultKafkaConsumerFactory<?, ?> kafkaConsumerFactory(KafkaConnectionDetails connectionDetails,
110-
ObjectProvider<DefaultKafkaConsumerFactoryCustomizer> customizers) {
111-
Map<String, Object> properties = this.properties.buildConsumerProperties();
113+
ObjectProvider<DefaultKafkaConsumerFactoryCustomizer> customizers, ObjectProvider<SslBundles> sslBundles) {
114+
Map<String, Object> properties = this.properties.buildConsumerProperties(sslBundles.getIfAvailable());
112115
applyKafkaConnectionDetailsForConsumer(properties, connectionDetails);
113116
DefaultKafkaConsumerFactory<Object, Object> factory = new DefaultKafkaConsumerFactory<>(properties);
114117
customizers.orderedStream().forEach((customizer) -> customizer.customize(factory));
@@ -118,8 +121,8 @@ public LoggingProducerListener<Object, Object> kafkaProducerListener() {
118121
@Bean
119122
@ConditionalOnMissingBean(ProducerFactory.class)
120123
public DefaultKafkaProducerFactory<?, ?> kafkaProducerFactory(KafkaConnectionDetails connectionDetails,
121-
ObjectProvider<DefaultKafkaProducerFactoryCustomizer> customizers) {
122-
Map<String, Object> properties = this.properties.buildProducerProperties();
124+
ObjectProvider<DefaultKafkaProducerFactoryCustomizer> customizers, ObjectProvider<SslBundles> sslBundles) {
125+
Map<String, Object> properties = this.properties.buildProducerProperties(sslBundles.getIfAvailable());
123126
applyKafkaConnectionDetailsForProducer(properties, connectionDetails);
124127
DefaultKafkaProducerFactory<?, ?> factory = new DefaultKafkaProducerFactory<>(properties);
125128
String transactionIdPrefix = this.properties.getProducer().getTransactionIdPrefix();
@@ -155,8 +158,8 @@ public KafkaJaasLoginModuleInitializer kafkaJaasInitializer() throws IOException
155158

156159
@Bean
157160
@ConditionalOnMissingBean
158-
public KafkaAdmin kafkaAdmin(KafkaConnectionDetails connectionDetails) {
159-
Map<String, Object> properties = this.properties.buildAdminProperties();
161+
public KafkaAdmin kafkaAdmin(KafkaConnectionDetails connectionDetails, ObjectProvider<SslBundles> sslBundles) {
162+
Map<String, Object> properties = this.properties.buildAdminProperties(sslBundles.getIfAvailable());
160163
applyKafkaConnectionDetailsForAdmin(properties, connectionDetails);
161164
KafkaAdmin kafkaAdmin = new KafkaAdmin(properties);
162165
KafkaProperties.Admin admin = this.properties.getAdmin();

0 commit comments

Comments
 (0)