diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-07-27 20:17:41 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-07-28 06:06:01 +0400 |
commit | c5dfbf80a5befb9464b9b43c3120a8000ca13d55 (patch) | |
tree | 638edaa9a18d8c65c58efddba11005830ad6a147 /plugins/sonar-email-notifications-plugin/src | |
parent | be80df44403a22e2e7dd852f5870533a95c0e1f7 (diff) | |
download | sonarqube-c5dfbf80a5befb9464b9b43c3120a8000ca13d55.tar.gz sonarqube-c5dfbf80a5befb9464b9b43c3120a8000ca13d55.zip |
SONAR-2600,SONAR-2601 Replace STARTTLS by SSL and describe all SMTP settings
Diffstat (limited to 'plugins/sonar-email-notifications-plugin/src')
3 files changed, 16 insertions, 9 deletions
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java index 907d9bf599c..90014fe62cd 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java +++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java @@ -34,8 +34,8 @@ public class EmailConfiguration implements ServerExtension { public static final String SMTP_HOST_DEFAULT = ""; public static final String SMTP_PORT = "email.smtp_port.secured"; public static final String SMTP_PORT_DEFAULT = "25"; - public static final String SMTP_USE_TLS = "email.smtp_use_tls.secured"; - public static final boolean SMTP_USE_TLS_DEFAULT = false; + public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured"; + public static final String SMTP_SECURE_CONNECTION_DEFAULT = ""; public static final String SMTP_USERNAME = "email.smtp_username.secured"; public static final String SMTP_USERNAME_DEFAULT = ""; public static final String SMTP_PASSWORD = "email.smtp_password.secured"; @@ -59,8 +59,8 @@ public class EmailConfiguration implements ServerExtension { return configuration.getString(SMTP_PORT, SMTP_PORT_DEFAULT); } - public boolean isUseTLS() { - return configuration.getBoolean(SMTP_USE_TLS, SMTP_USE_TLS_DEFAULT); + public String getSecureConnection() { + return configuration.getString(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT); } public String getSmtpUsername() { diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java index 74fb59d5d0e..1942d0fa215 100644 --- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java +++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java @@ -31,6 +31,7 @@ import org.sonar.api.database.model.User; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; import org.sonar.api.security.UserFinder; +import org.sonar.api.utils.SonarException; import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.plugins.emailnotifications.api.EmailTemplate; @@ -95,7 +96,7 @@ public class EmailNotificationChannel extends NotificationChannel { public void deliver(Notification notification, String username) { User user = userFinder.findByLogin(username); if (StringUtils.isBlank(user.getEmail())) { - LOG.warn("Email not defined for user: " + username); + LOG.info("Email not defined for user: " + username); return; } EmailMessage emailMessage = format(notification); @@ -121,7 +122,7 @@ public class EmailNotificationChannel extends NotificationChannel { */ void deliver(EmailMessage emailMessage) { if (StringUtils.isBlank(configuration.getSmtpHost())) { - LOG.warn("SMTP host was not configured - email will not be sent"); + LOG.info("SMTP host was not configured - email will not be sent"); return; } try { @@ -164,8 +165,14 @@ public class EmailNotificationChannel extends NotificationChannel { email.setMsg(emailMessage.getMessage()); // Send email.setHostName(configuration.getSmtpHost()); - email.setSmtpPort(Integer.parseInt(configuration.getSmtpPort())); - email.setTLS(configuration.isUseTLS()); + if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "SSL")) { + email.setSSL(true); + email.setSslSmtpPort(configuration.getSmtpPort()); + } else if (StringUtils.isBlank(configuration.getSecureConnection())) { + email.setSmtpPort(Integer.parseInt(configuration.getSmtpPort())); + } else { + throw new SonarException("Unknown type of SMTP secure connection: " + configuration.getSecureConnection()); + } if (StringUtils.isNotBlank(configuration.getSmtpUsername()) || StringUtils.isNotBlank(configuration.getSmtpPassword())) { email.setAuthentication(configuration.getSmtpUsername(), configuration.getSmtpPassword()); } diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java index 92c3ab5c1df..afd53264af3 100644 --- a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java +++ b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java @@ -44,7 +44,7 @@ public class EmailConfigurationTest { assertThat(emailConfiguration.getSmtpPort(), is("25")); assertThat(emailConfiguration.getSmtpUsername(), is("")); assertThat(emailConfiguration.getSmtpPassword(), is("")); - assertThat(emailConfiguration.isUseTLS(), is(false)); + assertThat(emailConfiguration.getSecureConnection(), is("")); assertThat(emailConfiguration.getFrom(), is("noreply@nowhere")); assertThat(emailConfiguration.getPrefix(), is("[SONAR]")); assertThat(emailConfiguration.getServerBaseURL(), is(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE)); |