Skip to content

Commit a009ea4

Browse files
committed
Merge pull request #50624 from dlwldnjs1009
* treat-empty-ssl-bundle-as-unset: Polish "Treat empty SSL bundle as unset" Treat empty SSL bundle as unset Closes gh-50624
2 parents 8288b8f + 88a7a44 commit a009ea4

8 files changed

Lines changed: 43 additions & 4 deletions

File tree

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
2525
import org.springframework.core.io.Resource;
26+
import org.springframework.util.StringUtils;
2627

2728
/**
2829
* Configuration properties for Cassandra.
@@ -236,7 +237,7 @@ public static class Ssl {
236237
private String bundle;
237238

238239
public boolean isEnabled() {
239-
return (this.enabled != null) ? this.enabled : this.bundle != null;
240+
return (this.enabled != null) ? this.enabled : StringUtils.hasText(this.bundle);
240241
}
241242

242243
public void setEnabled(boolean enabled) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121

2222
import org.springframework.boot.context.properties.ConfigurationProperties;
23+
import org.springframework.util.StringUtils;
2324

2425
/**
2526
* Configuration properties for Redis.
@@ -425,7 +426,7 @@ public static class Ssl {
425426
private String bundle;
426427

427428
public boolean isEnabled() {
428-
return (this.enabled != null) ? this.enabled : this.bundle != null;
429+
return (this.enabled != null) ? this.enabled : StringUtils.hasText(this.bundle);
429430
}
430431

431432
public void setEnabled(boolean enabled) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void applyProperties(MailProperties properties, JavaMailSenderImpl sende
6969
if (ssl.isEnabled()) {
7070
javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true");
7171
}
72-
if (ssl.getBundle() != null) {
72+
if (StringUtils.hasLength(ssl.getBundle())) {
7373
SslBundle sslBundle = sslBundles.getBundle(ssl.getBundle());
7474
javaMailProperties.put("mail." + protocol + ".ssl.socketFactory",
7575
sslBundle.createSslContext().getSocketFactory());

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.bson.UuidRepresentation;
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.util.StringUtils;
2526

2627
/**
2728
* Configuration properties for Mongo.
@@ -289,7 +290,7 @@ public static class Ssl {
289290
private String bundle;
290291

291292
public boolean isEnabled() {
292-
return (this.enabled != null) ? this.enabled : this.bundle != null;
293+
return (this.enabled != null) ? this.enabled : StringUtils.hasText(this.bundle);
293294
}
294295

295296
public void setEnabled(boolean enabled) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraPropertiesTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ void defaultValuesInManualMetadataAreConsistent() {
5858
assertThat(driverDefaults.get(TypedDriverOption.HEARTBEAT_TIMEOUT)).isEqualTo(Duration.ofSeconds(5));
5959
}
6060

61+
@Test
62+
void sslIsNotEnabledWhenBundleIsEmpty() {
63+
CassandraProperties properties = new CassandraProperties();
64+
properties.getSsl().setBundle("");
65+
assertThat(properties.getSsl().isEnabled()).isFalse();
66+
}
67+
6168
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisPropertiesTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ void lettuceDefaultsAreConsistent() {
3939
.isEqualTo(defaultClusterTopologyRefreshOptions.useDynamicRefreshSources());
4040
}
4141

42+
@Test
43+
void sslIsNotEnabledWhenBundleIsEmpty() {
44+
RedisProperties properties = new RedisProperties();
45+
properties.getSsl().setBundle("");
46+
assertThat(properties.getSsl().isEnabled()).isFalse();
47+
}
48+
4249
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,21 @@ void connectionOnStartupNotCalled() {
245245
});
246246
}
247247

248+
@Test
249+
@WithPackageResources("test.jks")
250+
void sslIsNotEnabledWhenBundleIsEmpty() {
251+
this.contextRunner
252+
.withPropertyValues("spring.mail.host:localhost", "spring.mail.ssl.bundle: ",
253+
"spring.ssl.bundle.jks.test-bundle.keystore.location:classpath:test.jks",
254+
"spring.ssl.bundle.jks.test-bundle.keystore.password:secret",
255+
"spring.ssl.bundle.jks.test-bundle.key.password:password")
256+
.run((context) -> {
257+
assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
258+
JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
259+
assertThat(mailSender.getJavaMailProperties().get("mail.smtp.ssl.socketFactory")).isNull();
260+
});
261+
}
262+
248263
@Test
249264
void smtpSslEnabled() {
250265
this.contextRunner.withPropertyValues("spring.mail.host:localhost", "spring.mail.ssl.enabled:true")

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ void defaultUuidRepresentationIsAlignedWithSpringData() {
3737
assertThat(springBootDefault).isEqualTo(springDataDefault);
3838
}
3939

40+
@Test
41+
void sslIsNotEnabledWhenBundleIsEmpty() {
42+
MongoProperties properties = new MongoProperties();
43+
properties.getSsl().setBundle("");
44+
assertThat(properties.getSsl().isEnabled()).isFalse();
45+
}
46+
4047
private UuidRepresentation springDataDefaultUuidRepresentation() {
4148
return new MongoConfigurationSupport() {
4249

0 commit comments

Comments
 (0)