Skip to content

Commit 3177118

Browse files
GutoVeroneziDaniel Augusto Veronezi Salvador
andauthored
Externalize TLS version on Quota's mailing (apache#4583)
Co-authored-by: Daniel Augusto Veronezi Salvador <daniel@scclouds.com.br>
1 parent eba186a commit 3177118

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.sun.mail.smtp.SMTPMessage;
6363
import com.sun.mail.smtp.SMTPSSLTransport;
6464
import com.sun.mail.smtp.SMTPTransport;
65+
import org.apache.commons.lang3.StringUtils;
6566

6667
@Component
6768
public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertManager {
@@ -114,8 +115,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
114115
String smtpUsername = configs.get(QuotaConfig.QuotaSmtpUser.key());
115116
String smtpPassword = configs.get(QuotaConfig.QuotaSmtpPassword.key());
116117
String emailSender = configs.get(QuotaConfig.QuotaSmtpSender.key());
118+
String smtpEnabledSecurityProtocols = configs.get(QuotaConfig.QuotaSmtpEnabledSecurityProtocols.key());
117119
_lockAccountEnforcement = "true".equalsIgnoreCase(configs.get(QuotaConfig.QuotaEnableEnforcement.key()));
118-
_emailQuotaAlert = new EmailQuotaAlert(smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, _smtpDebug);
120+
_emailQuotaAlert = new EmailQuotaAlert(smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpEnabledSecurityProtocols, _smtpDebug);
119121

120122
return true;
121123
}
@@ -341,7 +343,7 @@ static class EmailQuotaAlert {
341343
private final String _smtpPassword;
342344
private final String _emailSender;
343345

344-
public EmailQuotaAlert(String smtpHost, int smtpPort, boolean smtpUseAuth, final String smtpUsername, final String smtpPassword, String emailSender, boolean smtpDebug) {
346+
public EmailQuotaAlert(String smtpHost, int smtpPort, boolean smtpUseAuth, final String smtpUsername, final String smtpPassword, String emailSender, String smtpEnabledSecurityProtocols, boolean smtpDebug) {
345347
_smtpHost = smtpHost;
346348
_smtpPort = smtpPort;
347349
_smtpUseAuth = smtpUseAuth;
@@ -365,6 +367,10 @@ public EmailQuotaAlert(String smtpHost, int smtpPort, boolean smtpUseAuth, final
365367
smtpProps.put("mail.smtps.user", smtpUsername);
366368
}
367369

370+
if (StringUtils.isNotBlank(smtpEnabledSecurityProtocols)) {
371+
smtpProps.put("mail.smtp.ssl.protocols", smtpEnabledSecurityProtocols);
372+
}
373+
368374
if (!Strings.isNullOrEmpty(smtpUsername) && !Strings.isNullOrEmpty(smtpPassword)) {
369375
_smtpSession = Session.getInstance(smtpProps, new Authenticator() {
370376
@Override

framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public interface QuotaConfig {
5151
public static final ConfigKey<String> QuotaSmtpSender = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.sender", "",
5252
"Sender of quota alert email (will be in the From header of the email)", true);
5353

54+
public static final ConfigKey<String> QuotaSmtpEnabledSecurityProtocols = new ConfigKey<String>("Advanced", String.class, "quota.usage.smtp.enabledSecurityProtocols", "",
55+
"White-space separated security protocols; ex: \"TLSv1 TLSv1.1\". Supported protocols: SSLv2Hello, SSLv3, TLSv1, TLSv1.1 and TLSv1.2", true);
56+
5457
enum QuotaEmailTemplateTypes {
5558
QUOTA_LOW, QUOTA_EMPTY, QUOTA_UNLOCK_ACCOUNT, QUOTA_STATEMENT
5659
}

plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public String getConfigComponentName() {
137137
@Override
138138
public ConfigKey<?>[] getConfigKeys() {
139139
return new ConfigKey<?>[] {QuotaPluginEnabled, QuotaEnableEnforcement, QuotaCurrencySymbol, QuotaStatementPeriod, QuotaSmtpHost, QuotaSmtpPort, QuotaSmtpTimeout,
140-
QuotaSmtpUser, QuotaSmtpPassword, QuotaSmtpAuthType, QuotaSmtpSender};
140+
QuotaSmtpUser, QuotaSmtpPassword, QuotaSmtpAuthType, QuotaSmtpSender, QuotaSmtpEnabledSecurityProtocols};
141141
}
142142

143143
@Override

0 commit comments

Comments
 (0)