This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 20d01b5 Support configuring Mail SMTP SSL trust (#1886)
20d01b5 is described below
commit 20d01b512af2bef5c351fb373239d8340a95d045
Author: 吴伟杰 <[email protected]>
AuthorDate: Wed Apr 28 22:34:44 2021 +0800
Support configuring Mail SMTP SSL trust (#1886)
---
.../elasticjob/error/handler/email/EmailJobErrorHandler.java | 8 ++++++--
.../elasticjob/error/handler/email/EmailPropertiesConstants.java | 2 ++
.../email/EmailJobErrorHandlerPropertiesValidatorTest.java | 1 +
.../elasticjob/error/handler/email/EmailJobErrorHandlerTest.java | 1 +
4 files changed, 10 insertions(+), 2 deletions(-)
diff --git
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
index 32411a9..eddfa5d 100644
---
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
+++
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandler.java
@@ -65,7 +65,8 @@ public final class EmailJobErrorHandler implements
JobErrorHandler {
boolean isDebug =
Boolean.parseBoolean(props.getProperty(EmailPropertiesConstants.IS_DEBUG,
EmailPropertiesConstants.DEFAULT_IS_DEBUG));
String username = props.getProperty(EmailPropertiesConstants.USERNAME);
String password = props.getProperty(EmailPropertiesConstants.PASSWORD);
- session = Session.getDefaultInstance(createSessionProperties(host,
port, isUseSSL, isDebug), getSessionAuthenticator(username, password));
+ String sslTrust =
props.getProperty(EmailPropertiesConstants.SSL_TRUST);
+ session = Session.getDefaultInstance(createSessionProperties(host,
port, isUseSSL, isDebug, sslTrust), getSessionAuthenticator(username,
password));
subject = props.getProperty(EmailPropertiesConstants.SUBJECT,
EmailPropertiesConstants.DEFAULT_SUBJECT);
from = props.getProperty(EmailPropertiesConstants.FROM);
to = props.getProperty(EmailPropertiesConstants.TO);
@@ -73,7 +74,7 @@ public final class EmailJobErrorHandler implements
JobErrorHandler {
bcc = props.getProperty(EmailPropertiesConstants.BCC);
}
- private Properties createSessionProperties(final String host, final int
port, final boolean isUseSSL, final boolean isDebug) {
+ private Properties createSessionProperties(final String host, final int
port, final boolean isUseSSL, final boolean isDebug, final String sslTrust) {
Properties result = new Properties();
result.put("mail.smtp.host", host);
result.put("mail.smtp.port", port);
@@ -83,6 +84,9 @@ public final class EmailJobErrorHandler implements
JobErrorHandler {
if (isUseSSL) {
result.setProperty("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
result.setProperty("mail.smtp.socketFactory.fallback",
Boolean.FALSE.toString());
+ if (!Strings.isNullOrEmpty(sslTrust)) {
+ result.setProperty("mail.smtp.ssl.trust", sslTrust);
+ }
}
return result;
}
diff --git
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java
index eff753b..fe93b3b 100644
---
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java
+++
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailPropertiesConstants.java
@@ -32,6 +32,8 @@ public final class EmailPropertiesConstants {
public static final String HOST = PREFIX + "host";
+ public static final String SSL_TRUST = PREFIX + "ssl.trust";
+
public static final String PORT = PREFIX + "port";
public static final String USERNAME = PREFIX + "username";
diff --git
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
index e9d98bf..7bd2a1e 100644
---
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
+++
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
@@ -38,6 +38,7 @@ public final class
EmailJobErrorHandlerPropertiesValidatorTest {
public void assertValidateWithNormal() {
Properties properties = new Properties();
properties.setProperty(EmailPropertiesConstants.HOST, "host");
+ properties.setProperty(EmailPropertiesConstants.SSL_TRUST, "*");
properties.setProperty(EmailPropertiesConstants.PORT, "465");
properties.setProperty(EmailPropertiesConstants.USERNAME, "username");
properties.setProperty(EmailPropertiesConstants.PASSWORD, "password");
diff --git
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
index 7ade63f..c4be29e 100644
---
a/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
+++
b/elasticjob-ecosystem/elasticjob-error-handler/elasticjob-error-handler-type/elasticjob-error-handler-email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
@@ -105,6 +105,7 @@ public final class EmailJobErrorHandlerTest {
private Properties createConfigurationProperties() {
Properties result = new Properties();
result.setProperty(EmailPropertiesConstants.HOST, "localhost");
+ result.setProperty(EmailPropertiesConstants.SSL_TRUST, "*");
result.setProperty(EmailPropertiesConstants.PORT, "465");
result.setProperty(EmailPropertiesConstants.USERNAME, "user");
result.setProperty(EmailPropertiesConstants.PASSWORD, "xxx");