Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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");
});
}

Expand All @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions platform/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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")
Expand Down
Loading