diff --git a/module/spring-boot-artemis/src/main/java/org/springframework/boot/artemis/autoconfigure/ArtemisEmbeddedConfigurationFactory.java b/module/spring-boot-artemis/src/main/java/org/springframework/boot/artemis/autoconfigure/ArtemisEmbeddedConfigurationFactory.java index 4041e9177b87..6b77cbb18261 100644 --- a/module/spring-boot-artemis/src/main/java/org/springframework/boot/artemis/autoconfigure/ArtemisEmbeddedConfigurationFactory.java +++ b/module/spring-boot-artemis/src/main/java/org/springframework/boot/artemis/autoconfigure/ArtemisEmbeddedConfigurationFactory.java @@ -16,8 +16,6 @@ package org.springframework.boot.artemis.autoconfigure; -import java.io.File; - import org.apache.activemq.artemis.api.core.QueueConfiguration; import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; @@ -31,6 +29,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.boot.system.ApplicationTemp; + /** * Configuration used to create the embedded Artemis server. * @@ -84,8 +84,7 @@ private String getDataDir() { if (this.properties.getDataDirectory() != null) { return this.properties.getDataDirectory(); } - String tempDirectory = System.getProperty("java.io.tmpdir"); - return new File(tempDirectory, "artemis-data").getAbsolutePath(); + return new ApplicationTemp().getDir("artemis-data").getAbsolutePath(); } } diff --git a/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailProperties.java b/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailProperties.java index 4024232ac83d..de62fda00cf1 100644 --- a/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailProperties.java +++ b/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailProperties.java @@ -155,6 +155,11 @@ public static class Ssl { */ private boolean enabled; + /** + * Whether to enable hostname verification. + */ + private boolean verifyHostname = true; + /** * SSL bundle name. If set, 'mail.(protocol).ssl.socketFactory' property is set to * an SSLSocketFactory obtained from the corresponding SSL bundle. @@ -172,6 +177,14 @@ public void setEnabled(boolean enabled) { this.enabled = enabled; } + public boolean isVerifyHostname() { + return this.verifyHostname; + } + + public void setVerifyHostname(boolean verifyHostname) { + this.verifyHostname = verifyHostname; + } + public @Nullable String getBundle() { return this.bundle; } diff --git a/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailSenderPropertiesConfiguration.java b/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailSenderPropertiesConfiguration.java index ae030d8f0155..2406c1449125 100644 --- a/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailSenderPropertiesConfiguration.java +++ b/module/spring-boot-mail/src/main/java/org/springframework/boot/mail/autoconfigure/MailSenderPropertiesConfiguration.java @@ -70,14 +70,19 @@ private void applyProperties(MailProperties properties, JavaMailSenderImpl sende String protocol = properties.getProtocol(); protocol = (!StringUtils.hasLength(protocol)) ? "smtp" : protocol; Ssl ssl = properties.getSsl(); - if (ssl.isEnabled()) { - javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true"); - } - if (StringUtils.hasLength(ssl.getBundle())) { - Assert.state(sslBundles != null, "'sslBundles' must not be null"); - SslBundle sslBundle = sslBundles.getBundle(ssl.getBundle()); - javaMailProperties.put("mail." + protocol + ".ssl.socketFactory", - sslBundle.createSslContext().getSocketFactory()); + if (ssl.isEnabled() || StringUtils.hasLength(ssl.getBundle())) { + if (ssl.isVerifyHostname()) { + javaMailProperties.setProperty("mail." + protocol + ".ssl.checkserveridentity", "true"); + } + if (ssl.isEnabled()) { + javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true"); + } + if (StringUtils.hasLength(ssl.getBundle())) { + Assert.state(sslBundles != null, "'sslBundles' must not be null"); + SslBundle sslBundle = sslBundles.getBundle(ssl.getBundle()); + javaMailProperties.put("mail." + protocol + ".ssl.socketFactory", + sslBundle.createSslContext().getSocketFactory()); + } } if (!javaMailProperties.isEmpty()) { sender.setJavaMailProperties(javaMailProperties); diff --git a/module/spring-boot-mail/src/test/java/org/springframework/boot/mail/autoconfigure/MailSenderAutoConfigurationTests.java b/module/spring-boot-mail/src/test/java/org/springframework/boot/mail/autoconfigure/MailSenderAutoConfigurationTests.java index 1997ffae3921..6686d9ff9750 100644 --- a/module/spring-boot-mail/src/test/java/org/springframework/boot/mail/autoconfigure/MailSenderAutoConfigurationTests.java +++ b/module/spring-boot-mail/src/test/java/org/springframework/boot/mail/autoconfigure/MailSenderAutoConfigurationTests.java @@ -266,22 +266,38 @@ void smtpSslEnabled() { .run((context) -> { assertThat(context).hasSingleBean(JavaMailSenderImpl.class); JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); - assertThat(mailSender.getJavaMailProperties()).containsEntry("mail.smtp.ssl.enable", "true"); + assertThat(mailSender.getJavaMailProperties()).containsEntry("mail.smtp.ssl.enable", "true") + .containsEntry("mail.smtp.ssl.checkserveridentity", "true"); + }); + } + + @Test + void smtpSslEnabledWithHostnameVerificationDisabled() { + this.contextRunner + .withPropertyValues("spring.mail.host:localhost", "spring.mail.ssl.enabled:true", + "spring.mail.ssl.verify-hostname:false") + .run((context) -> { + assertThat(context).hasSingleBean(JavaMailSenderImpl.class); + JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); + assertThat(mailSender.getJavaMailProperties()).containsEntry("mail.smtp.ssl.enable", "true") + .doesNotContainKey("mail.smtp.ssl.checkserveridentity"); }); } @Test @WithPackageResources("test.jks") - void smtpSslBundle() { + void smtpSslBundleWithHostnameVerificationDisabled() { this.contextRunner .withPropertyValues("spring.mail.host:localhost", "spring.mail.ssl.bundle:test-bundle", + "spring.mail.ssl.verify-hostname:false", "spring.ssl.bundle.jks.test-bundle.keystore.location:classpath:test.jks", "spring.ssl.bundle.jks.test-bundle.keystore.password:secret", "spring.ssl.bundle.jks.test-bundle.key.password:password") .run((context) -> { assertThat(context).hasSingleBean(JavaMailSenderImpl.class); JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); - assertThat(mailSender.getJavaMailProperties()).doesNotContainKey("mail.smtp.ssl.enable"); + assertThat(mailSender.getJavaMailProperties()).doesNotContainKey("mail.smtp.ssl.enable") + .doesNotContainKey("mail.smtp.ssl.checkserveridentity"); Object property = mailSender.getJavaMailProperties().get("mail.smtp.ssl.socketFactory"); assertThat(property).isInstanceOf(SSLSocketFactory.class); }); @@ -295,7 +311,8 @@ void smtpsSslEnabled() { .run((context) -> { assertThat(context).hasSingleBean(JavaMailSenderImpl.class); JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); - assertThat(mailSender.getJavaMailProperties()).containsEntry("mail.smtps.ssl.enable", "true"); + assertThat(mailSender.getJavaMailProperties()).containsEntry("mail.smtps.ssl.enable", "true") + .containsEntry("mail.smtps.ssl.checkserveridentity", "true"); }); } @@ -311,7 +328,8 @@ void smtpsSslBundle() { .run((context) -> { assertThat(context).hasSingleBean(JavaMailSenderImpl.class); JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); - assertThat(mailSender.getJavaMailProperties()).doesNotContainKey("mail.smtps.ssl.enable"); + assertThat(mailSender.getJavaMailProperties()).doesNotContainKey("mail.smtps.ssl.enable") + .containsEntry("mail.smtps.ssl.checkserveridentity", "true"); Object property = mailSender.getJavaMailProperties().get("mail.smtps.ssl.socketFactory"); assertThat(property).isInstanceOf(SSLSocketFactory.class); }); diff --git a/platform/spring-boot-dependencies/build.gradle b/platform/spring-boot-dependencies/build.gradle index 4cacc16ef3b8..4dffef741575 100644 --- a/platform/spring-boot-dependencies/build.gradle +++ b/platform/spring-boot-dependencies/build.gradle @@ -2523,7 +2523,7 @@ bom { releaseNotes("https://github.com/spring-projects/spring-amqp/releases/tag/v{version}") } } - library("Spring Batch", "6.0.4-SNAPSHOT") { + library("Spring Batch", "6.0.4") { considerSnapshots() group("org.springframework.batch") { bom("spring-batch-bom") @@ -2568,7 +2568,7 @@ bom { releaseNotes("https://github.com/spring-projects/spring-framework/releases/tag/v{version}") } } - library("Spring GraphQL", "2.0.4-SNAPSHOT") { + library("Spring GraphQL", "2.0.4") { considerSnapshots() group("org.springframework.graphql") { modules = [ @@ -2620,7 +2620,7 @@ bom { releaseNotes("https://github.com/spring-projects/spring-hateoas/releases/tag/{version}") } } - library("Spring Integration", "7.1.0-SNAPSHOT") { + library("Spring Integration", "7.1.0") { considerSnapshots() group("org.springframework.integration") { bom("spring-integration-bom")