Skip to content

Commit

Permalink
0005082: Mail service support for encrypted passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
joshahicks committed Sep 16, 2021
1 parent b7715ed commit aafbedb
Showing 1 changed file with 13 additions and 8 deletions.
Expand Up @@ -61,15 +61,20 @@ public MailService(IParameterService parameterService, ISecurityService security
this.securityService = securityService;
}

public String decryptPassword(String password) {
if (password != null && password.startsWith(SecurityConstants.PREFIX_ENC)) {
return securityService.decrypt(password.substring(SecurityConstants.PREFIX_ENC.length()));
}
return password;
}

public String sendEmail(String subject, String text, String toRecipients) {
return sendEmail(subject, text, toRecipients, null, null);
}

public String sendEmail(String subject, String text, String toRecipients, String ccRecipients, String bccRecipients) {
String password = parameterService.getString(ParameterConstants.SMTP_PASSWORD);
if (password != null && password.startsWith(SecurityConstants.PREFIX_ENC)) {
password = securityService.decrypt(password.substring(SecurityConstants.PREFIX_ENC.length()));
}
String password = decryptPassword(parameterService.getString(ParameterConstants.SMTP_PASSWORD));

return sendEmail(subject, text, toRecipients, ccRecipients, bccRecipients, getJavaMailProperties(),
parameterService.getString(ParameterConstants.SMTP_TRANSPORT, "smtp"),
parameterService.is(ParameterConstants.SMTP_USE_AUTH, false),
Expand All @@ -84,7 +89,7 @@ public String sendEmail(String subject, String text, String toRecipients, String
return sendEmail(subject, text, toRecipients, ccRecipients, bccRecipients, getJavaMailProperties(prop),
prop.get(ParameterConstants.SMTP_TRANSPORT, "smtp"),
prop.is(ParameterConstants.SMTP_USE_AUTH, false),
prop.get(ParameterConstants.SMTP_USER), prop.get(ParameterConstants.SMTP_PASSWORD));
prop.get(ParameterConstants.SMTP_USER), decryptPassword(prop.get(ParameterConstants.SMTP_PASSWORD)));
}

protected String sendEmail(String subject, String text, String toRecipients, String ccRecipients, String bccRecipients,
Expand All @@ -108,7 +113,7 @@ protected String sendEmail(String subject, String text, String toRecipients, Str

try {
if (useAuth) {
transport.connect(user, password);
transport.connect(user, decryptPassword(password));
} else {
transport.connect();
}
Expand Down Expand Up @@ -160,8 +165,8 @@ public String testTransport(TypedProperties prop) {
Session session = Session.getInstance(getJavaMailProperties(prop));
transport = session.getTransport(prop.get(ParameterConstants.SMTP_TRANSPORT, "smtp"));
if (prop.is(ParameterConstants.SMTP_USE_AUTH, false)) {
transport.connect(prop.get(ParameterConstants.SMTP_USER),
prop.get(ParameterConstants.SMTP_PASSWORD));
transport.connect("email-smtp.us-east-1.amazonaws.com", prop.get(ParameterConstants.SMTP_USER),
decryptPassword(prop.get(ParameterConstants.SMTP_PASSWORD)));
} else {
transport.connect();
}
Expand Down

0 comments on commit aafbedb

Please sign in to comment.