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 | |
parent | be80df44403a22e2e7dd852f5870533a95c0e1f7 (diff) | |
download | sonarqube-c5dfbf80a5befb9464b9b43c3120a8000ca13d55.tar.gz sonarqube-c5dfbf80a5befb9464b9b43c3120a8000ca13d55.zip |
SONAR-2600,SONAR-2601 Replace STARTTLS by SSL and describe all SMTP settings
6 files changed, 41 insertions, 19 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)); diff --git a/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties index b7b6cdb319e..7ea4f825064 100644 --- a/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties +++ b/plugins/sonar-i18n-en-plugin/src/main/resources/org/sonar/i18n/core.properties @@ -665,12 +665,20 @@ rules_configuration.x_rules_have_been_deactivated={0} rules have been deactivate # #------------------------------------------------------------------------------ email_configuration.smtp_host=SMTP host +email_configuration.smtp_host.description=For example "smtp.gmail.com". Leave blank to disable email sending. email_configuration.smtp_port=SMTP port -email_configuration.use_tls=Use TLS +email_configuration.smtp_port.description=Port number to connect with SMTP server. +email_configuration.smtp_secure_connection=Use secure connection +email_configuration.smtp_secure_connection.description=Whether to use secure connection and its type. email_configuration.smtp_username=SMTP username +email_configuration.smtp_username.description=Optional - if you use authenticated SMTP, enter your username. email_configuration.smtp_password=SMTP password +email_configuration.smtp_password.description=Optional - as above, enter your password if you use authenticated SMTP. email_configuration.from_address=From address +email_configuration.from_address.description=Emails will come from this address. For example - "noreply@sonarsource.com". Note that server may ignore this setting (like does GMail). email_configuration.email_prefix=Email prefix +email_configuration.email_prefix.description=This prefix will be prepended to all outgoing email subjects. + email_configuration.test.title=Test Configuration email_configuration.test.to_address=To email_configuration.test.to_address_required=You must provide address where to send test email diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb index df4ec44b9a8..5982b704372 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb @@ -25,7 +25,7 @@ class EmailConfigurationController < ApplicationController def index @smtp_host = Property.value(configuration::SMTP_HOST, nil, configuration::SMTP_HOST_DEFAULT) @smtp_port = Property.value(configuration::SMTP_PORT, nil, configuration::SMTP_PORT_DEFAULT) - @smtp_use_tls = Property.value(configuration::SMTP_USE_TLS, nil, configuration::SMTP_USE_TLS_DEFAULT) == 'true' + @smtp_secure_connection = Property.value(configuration::SMTP_SECURE_CONNECTION, nil, configuration::SMTP_SECURE_CONNECTION) @smtp_username = Property.value(configuration::SMTP_USERNAME, nil, configuration::SMTP_USERNAME_DEFAULT) @smtp_password = Property.value(configuration::SMTP_PASSWORD, nil, configuration::SMTP_PASSWORD_DEFAULT) @email_from = Property.value(configuration::FROM, nil, configuration::FROM_DEFAULT) @@ -35,7 +35,7 @@ class EmailConfigurationController < ApplicationController def save Property.set(configuration::SMTP_HOST, params[:smtp_host]) Property.set(configuration::SMTP_PORT, params[:smtp_port]) - Property.set(configuration::SMTP_USE_TLS, params[:smtp_use_tls] == 'true') + Property.set(configuration::SMTP_SECURE_CONNECTION, params[:smtp_secure_connection]) Property.set(configuration::SMTP_USERNAME, params[:smtp_username]) Property.set(configuration::SMTP_PASSWORD, params[:smtp_password]) Property.set(configuration::FROM, params[:email_from]) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb index 07518fe44f4..302a99b6a42 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb @@ -4,31 +4,38 @@ <table class="form"> <tr> <td class="keyCell"><label for="smtp_host"><%= message('email_configuration.smtp_host') -%>:</label></td> - <td align="left"><%= text_field_tag 'smtp_host', @smtp_host %></td> + <td><%= text_field_tag 'smtp_host', @smtp_host %></td> + <td><%= message('email_configuration.smtp_host.description') -%></td> </tr> <tr> <td class="keyCell"><label for="smtp_port"><%= message('email_configuration.smtp_port') -%>:</label></td> - <td align="left"><%= text_field_tag 'smtp_port', @smtp_port %></td> + <td><%= text_field_tag 'smtp_port', @smtp_port %></td> + <td><%= message('email_configuration.smtp_port.description') -%></td> </tr> <tr> - <td class="keyCell"><label for="smtp_port"><%= message('email_configuration.use_tls') -%>:</label></td> - <td align="left"><%= check_box_tag 'smtp_use_tls', 'true', @smtp_use_tls %></td> + <td class="keyCell"><label for="smtp_secure_connection"><%= message('email_configuration.smtp_secure_connection') -%>:</label></td> + <td><%= select_tag 'smtp_secure_connection', options_for_select({'No' => '', 'SSL' => 'ssl'}, @smtp_secure_connection) %></td> + <td><%= message('email_configuration.smtp_secure_connection.description') -%></td> </tr> <tr> <td class="keyCell"><label for="smtp_username"><%= message('email_configuration.smtp_username') -%>:</label></td> - <td align="left"><%= text_field_tag 'smtp_username', @smtp_username %></td> + <td><%= text_field_tag 'smtp_username', @smtp_username %></td> + <td><%= message('email_configuration.smtp_username.description') -%></td> </tr> <tr> <td class="keyCell"><label for="smtp_password"><%= message('email_configuration.smtp_password') -%>:</label></td> - <td align="left"><%= password_field_tag 'smtp_password', @smtp_password %></td> + <td><%= password_field_tag 'smtp_password', @smtp_password %></td> + <td><%= message('email_configuration.smtp_password.description') -%></td> </tr> <tr> <td class="keyCell"><label for="email_from"><%= message('email_configuration.from_address') -%>:</label></td> <td><%= text_field_tag 'email_from', @email_from %></td> + <td><%= message('email_configuration.from_address.description') -%></td> </tr> <tr> <td class="keyCell"><label for="email_prefix"><%= message('email_configuration.email_prefix') -%>:</label></td> <td><%= text_field_tag 'email_prefix', @email_prefix %></td> + <td><%= message('email_configuration.email_prefix.description') -%></td> </tr> <tr> <td></td> @@ -52,7 +59,7 @@ </tr> <tr> <td class="keyCell"><label for="message"><%= message('email_configuration.test.message') -%>:</label></td> - <td><%= text_area_tag 'message', message('email_configuration.test.message_text') %></td> + <td><%= text_area_tag 'message', message('email_configuration.test.message_text'), {:cols => 40, :rows => 6} %></td> </tr> <tr> <td></td> |