Skip to content

Commit 51a9ee8

Browse files
Torres-09snicoll
authored andcommitted
Remove SslBundles from KafkaProperties
See gh-45727 Signed-off-by: Sehwan <[email protected]>
1 parent e337541 commit 51a9ee8

File tree

4 files changed

+32
-80
lines changed

4 files changed

+32
-80
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public KafkaJaasLoginModuleInitializer kafkaJaasInitializer() throws IOException
170170
@Bean
171171
@ConditionalOnMissingBean
172172
KafkaAdmin kafkaAdmin(KafkaConnectionDetails connectionDetails) {
173-
Map<String, Object> properties = this.properties.buildAdminProperties(null);
173+
Map<String, Object> properties = this.properties.buildAdminProperties();
174174
applyKafkaConnectionDetailsForAdmin(properties, connectionDetails);
175175
KafkaAdmin kafkaAdmin = new KafkaAdmin(properties);
176176
KafkaProperties.Admin admin = this.properties.getAdmin();

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

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.boot.context.properties.PropertyMapper;
3939
import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException;
4040
import org.springframework.boot.convert.DurationUnit;
41-
import org.springframework.boot.ssl.SslBundles;
4241
import org.springframework.core.io.Resource;
4342
import org.springframework.kafka.listener.ContainerProperties.AckMode;
4443
import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer;
@@ -162,15 +161,15 @@ public Retry getRetry() {
162161
return this.retry;
163162
}
164163

165-
private Map<String, Object> buildCommonProperties(SslBundles sslBundles) {
164+
private Map<String, Object> buildCommonProperties() {
166165
Map<String, Object> properties = new HashMap<>();
167166
if (this.bootstrapServers != null) {
168167
properties.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, this.bootstrapServers);
169168
}
170169
if (this.clientId != null) {
171170
properties.put(CommonClientConfigs.CLIENT_ID_CONFIG, this.clientId);
172171
}
173-
properties.putAll(this.ssl.buildProperties(sslBundles));
172+
properties.putAll(this.ssl.buildProperties());
174173
properties.putAll(this.security.buildProperties());
175174
if (!CollectionUtils.isEmpty(this.properties)) {
176175
properties.putAll(this.properties);
@@ -187,21 +186,8 @@ private Map<String, Object> buildCommonProperties(SslBundles sslBundles) {
187186
* instance
188187
*/
189188
public Map<String, Object> buildConsumerProperties() {
190-
return buildConsumerProperties(null);
191-
}
192-
193-
/**
194-
* Create an initial map of consumer properties from the state of this instance.
195-
* <p>
196-
* This allows you to add additional properties, if necessary, and override the
197-
* default {@code kafkaConsumerFactory} bean.
198-
* @param sslBundles bundles providing SSL trust material
199-
* @return the consumer properties initialized with the customizations defined on this
200-
* instance
201-
*/
202-
public Map<String, Object> buildConsumerProperties(SslBundles sslBundles) {
203-
Map<String, Object> properties = buildCommonProperties(sslBundles);
204-
properties.putAll(this.consumer.buildProperties(sslBundles));
189+
Map<String, Object> properties = buildCommonProperties();
190+
properties.putAll(this.consumer.buildProperties());
205191
return properties;
206192
}
207193

@@ -214,21 +200,8 @@ public Map<String, Object> buildConsumerProperties(SslBundles sslBundles) {
214200
* instance
215201
*/
216202
public Map<String, Object> buildProducerProperties() {
217-
return buildProducerProperties(null);
218-
}
219-
220-
/**
221-
* Create an initial map of producer properties from the state of this instance.
222-
* <p>
223-
* This allows you to add additional properties, if necessary, and override the
224-
* default {@code kafkaProducerFactory} bean.
225-
* @param sslBundles bundles providing SSL trust material
226-
* @return the producer properties initialized with the customizations defined on this
227-
* instance
228-
*/
229-
public Map<String, Object> buildProducerProperties(SslBundles sslBundles) {
230-
Map<String, Object> properties = buildCommonProperties(sslBundles);
231-
properties.putAll(this.producer.buildProperties(sslBundles));
203+
Map<String, Object> properties = buildCommonProperties();
204+
properties.putAll(this.producer.buildProperties());
232205
return properties;
233206
}
234207

@@ -237,27 +210,25 @@ public Map<String, Object> buildProducerProperties(SslBundles sslBundles) {
237210
* <p>
238211
* This allows you to add additional properties, if necessary, and override the
239212
* default {@code kafkaAdmin} bean.
240-
* @param sslBundles bundles providing SSL trust material
241213
* @return the admin properties initialized with the customizations defined on this
242214
* instance
243215
*/
244-
public Map<String, Object> buildAdminProperties(SslBundles sslBundles) {
245-
Map<String, Object> properties = buildCommonProperties(sslBundles);
246-
properties.putAll(this.admin.buildProperties(sslBundles));
216+
public Map<String, Object> buildAdminProperties() {
217+
Map<String, Object> properties = buildCommonProperties();
218+
properties.putAll(this.admin.buildProperties());
247219
return properties;
248220
}
249221

250222
/**
251223
* Create an initial map of streams properties from the state of this instance.
252224
* <p>
253225
* This allows you to add additional properties, if necessary.
254-
* @param sslBundles bundles providing SSL trust material
255226
* @return the streams properties initialized with the customizations defined on this
256227
* instance
257228
*/
258-
public Map<String, Object> buildStreamsProperties(SslBundles sslBundles) {
259-
Map<String, Object> properties = buildCommonProperties(sslBundles);
260-
properties.putAll(this.streams.buildProperties(sslBundles));
229+
public Map<String, Object> buildStreamsProperties() {
230+
Map<String, Object> properties = buildCommonProperties();
231+
properties.putAll(this.streams.buildProperties());
261232
return properties;
262233
}
263234

@@ -473,7 +444,7 @@ public Map<String, String> getProperties() {
473444
return this.properties;
474445
}
475446

476-
public Map<String, Object> buildProperties(SslBundles sslBundles) {
447+
public Map<String, Object> buildProperties() {
477448
Properties properties = new Properties();
478449
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
479450
map.from(this::getAutoCommitInterval)
@@ -501,7 +472,7 @@ public Map<String, Object> buildProperties(SslBundles sslBundles) {
501472
map.from(this::getMaxPollInterval)
502473
.asInt(Duration::toMillis)
503474
.to(properties.in(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG));
504-
return properties.with(this.ssl, this.security, this.properties, sslBundles);
475+
return properties.with(this.ssl, this.security, this.properties);
505476
}
506477

507478
}
@@ -663,7 +634,7 @@ public Map<String, String> getProperties() {
663634
return this.properties;
664635
}
665636

666-
public Map<String, Object> buildProperties(SslBundles sslBundles) {
637+
public Map<String, Object> buildProperties() {
667638
Properties properties = new Properties();
668639
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
669640
map.from(this::getAcks).to(properties.in(ProducerConfig.ACKS_CONFIG));
@@ -677,7 +648,7 @@ public Map<String, Object> buildProperties(SslBundles sslBundles) {
677648
map.from(this::getKeySerializer).to(properties.in(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG));
678649
map.from(this::getRetries).to(properties.in(ProducerConfig.RETRIES_CONFIG));
679650
map.from(this::getValueSerializer).to(properties.in(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG));
680-
return properties.with(this.ssl, this.security, this.properties, sslBundles);
651+
return properties.with(this.ssl, this.security, this.properties);
681652
}
682653

683654
}
@@ -784,11 +755,11 @@ public Map<String, String> getProperties() {
784755
return this.properties;
785756
}
786757

787-
public Map<String, Object> buildProperties(SslBundles sslBundles) {
758+
public Map<String, Object> buildProperties() {
788759
Properties properties = new Properties();
789760
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
790761
map.from(this::getClientId).to(properties.in(ProducerConfig.CLIENT_ID_CONFIG));
791-
return properties.with(this.ssl, this.security, this.properties, sslBundles);
762+
return properties.with(this.ssl, this.security, this.properties);
792763
}
793764

794765
}
@@ -918,7 +889,7 @@ public Map<String, String> getProperties() {
918889
return this.properties;
919890
}
920891

921-
public Map<String, Object> buildProperties(SslBundles sslBundles) {
892+
public Map<String, Object> buildProperties() {
922893
Properties properties = new Properties();
923894
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
924895
map.from(this::getApplicationId).to(properties.in("application.id"));
@@ -929,7 +900,7 @@ public Map<String, Object> buildProperties(SslBundles sslBundles) {
929900
map.from(this::getClientId).to(properties.in(CommonClientConfigs.CLIENT_ID_CONFIG));
930901
map.from(this::getReplicationFactor).to(properties.in("replication.factor"));
931902
map.from(this::getStateDir).to(properties.in("state.dir"));
932-
return properties.with(this.ssl, this.security, this.properties, sslBundles);
903+
return properties.with(this.ssl, this.security, this.properties);
933904
}
934905

935906
}
@@ -1423,12 +1394,7 @@ public void setProtocol(String protocol) {
14231394
this.protocol = protocol;
14241395
}
14251396

1426-
@Deprecated(since = "3.2.0", forRemoval = true)
14271397
public Map<String, Object> buildProperties() {
1428-
return buildProperties(null);
1429-
}
1430-
1431-
public Map<String, Object> buildProperties(SslBundles sslBundles) {
14321398
validate();
14331399
String bundleName = getBundle();
14341400
Properties properties = new Properties();
@@ -1794,8 +1760,8 @@ <V> java.util.function.Consumer<V> in(String key) {
17941760
return (value) -> put(key, value);
17951761
}
17961762

1797-
Properties with(Ssl ssl, Security security, Map<String, String> properties, SslBundles sslBundles) {
1798-
putAll(ssl.buildProperties(sslBundles));
1763+
Properties with(Ssl ssl, Security security, Map<String, String> properties) {
1764+
putAll(ssl.buildProperties());
17991765
putAll(security.buildProperties());
18001766
putAll(properties);
18011767
return this;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class KafkaStreamsAnnotationDrivenConfiguration {
6262
@Bean(KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME)
6363
KafkaStreamsConfiguration defaultKafkaStreamsConfig(Environment environment,
6464
KafkaConnectionDetails connectionDetails) {
65-
Map<String, Object> properties = this.properties.buildStreamsProperties(null);
65+
Map<String, Object> properties = this.properties.buildStreamsProperties();
6666
applyKafkaConnectionDetailsForStreams(properties, connectionDetails);
6767
if (this.properties.getStreams().getApplicationId() == null) {
6868
String applicationName = environment.getProperty("spring.application.name");

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.IsolationLevel;
2828
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener;
2929
import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException;
30-
import org.springframework.boot.ssl.DefaultSslBundleRegistry;
31-
import org.springframework.boot.ssl.SslBundle;
3230
import org.springframework.core.io.ClassPathResource;
3331
import org.springframework.kafka.core.CleanupConfig;
3432
import org.springframework.kafka.core.KafkaAdmin;
3533
import org.springframework.kafka.listener.ContainerProperties;
3634

3735
import static org.assertj.core.api.Assertions.assertThat;
3836
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
39-
import static org.mockito.Mockito.mock;
4037

4138
/**
4239
* Tests for {@link KafkaProperties}.
@@ -47,8 +44,6 @@
4744
*/
4845
class KafkaPropertiesTests {
4946

50-
private final SslBundle sslBundle = mock(SslBundle.class);
51-
5247
@Test
5348
void isolationLevelEnumConsistentWithKafkaVersion() {
5449
org.apache.kafka.common.IsolationLevel[] original = org.apache.kafka.common.IsolationLevel.values();
@@ -101,15 +96,6 @@ void sslPemConfigurationWithEmptyBundle() {
10196
"-----BEGINchain");
10297
}
10398

104-
@Test
105-
void sslBundleConfiguration() {
106-
KafkaProperties properties = new KafkaProperties();
107-
properties.getSsl().setBundle("myBundle");
108-
Map<String, Object> consumerProperties = properties
109-
.buildConsumerProperties(new DefaultSslBundleRegistry("myBundle", this.sslBundle));
110-
assertThat(consumerProperties).doesNotContainKey(SslConfigs.SSL_ENGINE_FACTORY_CLASS_CONFIG);
111-
}
112-
11399
@Test
114100
void sslPropertiesWhenKeyStoreLocationAndKeySetShouldThrowException() {
115101
KafkaProperties properties = new KafkaProperties();
@@ -133,35 +119,35 @@ void sslPropertiesWhenKeyStoreLocationAndBundleSetShouldThrowException() {
133119
KafkaProperties properties = new KafkaProperties();
134120
properties.getSsl().setBundle("myBundle");
135121
properties.getSsl().setKeyStoreLocation(new ClassPathResource("ksLoc"));
136-
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class).isThrownBy(
137-
() -> properties.buildConsumerProperties(new DefaultSslBundleRegistry("myBundle", this.sslBundle)));
122+
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class)
123+
.isThrownBy(properties::buildConsumerProperties);
138124
}
139125

140126
@Test
141127
void sslPropertiesWhenKeyStoreKeyAndBundleSetShouldThrowException() {
142128
KafkaProperties properties = new KafkaProperties();
143129
properties.getSsl().setBundle("myBundle");
144130
properties.getSsl().setKeyStoreKey("-----BEGIN");
145-
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class).isThrownBy(
146-
() -> properties.buildConsumerProperties(new DefaultSslBundleRegistry("myBundle", this.sslBundle)));
131+
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class)
132+
.isThrownBy(properties::buildConsumerProperties);
147133
}
148134

149135
@Test
150136
void sslPropertiesWhenTrustStoreLocationAndBundleSetShouldThrowException() {
151137
KafkaProperties properties = new KafkaProperties();
152138
properties.getSsl().setBundle("myBundle");
153139
properties.getSsl().setTrustStoreLocation(new ClassPathResource("tsLoc"));
154-
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class).isThrownBy(
155-
() -> properties.buildConsumerProperties(new DefaultSslBundleRegistry("myBundle", this.sslBundle)));
140+
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class)
141+
.isThrownBy(properties::buildConsumerProperties);
156142
}
157143

158144
@Test
159145
void sslPropertiesWhenTrustStoreCertificatesAndBundleSetShouldThrowException() {
160146
KafkaProperties properties = new KafkaProperties();
161147
properties.getSsl().setBundle("myBundle");
162148
properties.getSsl().setTrustStoreCertificates("-----BEGIN");
163-
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class).isThrownBy(
164-
() -> properties.buildConsumerProperties(new DefaultSslBundleRegistry("myBundle", this.sslBundle)));
149+
assertThatExceptionOfType(MutuallyExclusiveConfigurationPropertiesException.class)
150+
.isThrownBy(properties::buildConsumerProperties);
165151
}
166152

167153
@Test

0 commit comments

Comments
 (0)