From: Antoine Vigneau Date: Sun, 11 Aug 2024 21:14:17 +0000 (+0200) Subject: SONAR-22516 Fix BBT using email configuration X-Git-Tag: 10.7.0.96327~245 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=632e1b44c4f2dae8e278e202932226d126afe6b1;p=sonarqube.git SONAR-22516 Fix BBT using email configuration --- diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java index 9948abe4f1d..f4005480631 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java @@ -321,7 +321,7 @@ public class EmailNotificationChannel extends NotificationChannel { } private void configureSecureConnection(Email email) { - if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "ssl")) { + if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "SSLTLS")) { email.setSSLOnConnect(true); email.setSSLCheckServerIdentity(true); email.setSslSmtpPort(String.valueOf(configuration.getSmtpPort())); @@ -329,12 +329,12 @@ public class EmailNotificationChannel extends NotificationChannel { // this port is not used except in EmailException message, that's why it's set with the same value than SSL port. // It prevents from getting bad message. email.setSmtpPort(configuration.getSmtpPort()); - } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "starttls")) { + } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "STARTTLS")) { email.setStartTLSEnabled(true); email.setStartTLSRequired(true); email.setSSLCheckServerIdentity(true); email.setSmtpPort(configuration.getSmtpPort()); - } else if (StringUtils.isBlank(configuration.getSecureConnection())) { + } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "NONE")) { email.setSmtpPort(configuration.getSmtpPort()); } else { throw new SonarException("Unknown type of SMTP secure connection: " + configuration.getSecureConnection()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java index bd524e9e6a2..efff8f1b796 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java @@ -378,6 +378,7 @@ public class EmailNotificationChannelTest { private void configure() { when(configuration.getSmtpHost()).thenReturn("localhost"); when(configuration.getSmtpPort()).thenReturn(smtpServer.getServer().getPort()); + when(configuration.getSecureConnection()).thenReturn("NONE"); when(configuration.getFrom()).thenReturn("server@nowhere"); when(configuration.getFromName()).thenReturn("SonarQube from NoWhere"); when(configuration.getPrefix()).thenReturn(SUBJECT_PREFIX); diff --git a/server/sonar-webserver-common/src/it/java/org/sonar/server/common/email/config/EmailConfigurationBuilder.java b/server/sonar-webserver-common/src/it/java/org/sonar/server/common/email/config/EmailConfigurationBuilder.java index ae619646223..f94ce83e7c6 100644 --- a/server/sonar-webserver-common/src/it/java/org/sonar/server/common/email/config/EmailConfigurationBuilder.java +++ b/server/sonar-webserver-common/src/it/java/org/sonar/server/common/email/config/EmailConfigurationBuilder.java @@ -35,13 +35,13 @@ public final class EmailConfigurationBuilder { private String oauthClientSecret; private String oauthTenant; - private EmailConfigurationBuilder() { - } - public static EmailConfigurationBuilder builder() { return new EmailConfigurationBuilder(); } + private EmailConfigurationBuilder() { + } + public EmailConfigurationBuilder id(String id) { this.id = id; return this; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index 4f7ea365c7b..257e36b2ed0 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -32,6 +32,7 @@ import org.sonarqube.ws.client.components.ComponentsService; import org.sonarqube.ws.client.developers.DevelopersService; import org.sonarqube.ws.client.duplications.DuplicationsService; import org.sonarqube.ws.client.editions.EditionsService; +import org.sonarqube.ws.client.emails.EmailConfigurationService; import org.sonarqube.ws.client.emails.EmailsService; import org.sonarqube.ws.client.favorites.FavoritesService; import org.sonarqube.ws.client.github.configuration.GithubConfigurationService; @@ -101,6 +102,7 @@ class DefaultWsClient implements WsClient { private final DevelopersService developersService; private final DuplicationsService duplicationsService; private final EditionsService editionsService; + private final EmailConfigurationService emailConfigurationService; private final EmailsService emailsService; private final FavoritesService favoritesService; private final GovernanceReportsService governanceReportsService; @@ -164,6 +166,7 @@ class DefaultWsClient implements WsClient { this.developersService = new DevelopersService(wsConnector); this.duplicationsService = new DuplicationsService(wsConnector); this.editionsService = new EditionsService(wsConnector); + this.emailConfigurationService = new EmailConfigurationService(wsConnector); this.emailsService = new EmailsService(wsConnector); this.favoritesService = new FavoritesService(wsConnector); this.governanceReportsService = new GovernanceReportsService(wsConnector); @@ -279,6 +282,11 @@ class DefaultWsClient implements WsClient { return editionsService; } + @Override + public EmailConfigurationService emailConfiguration() { + return emailConfigurationService; + } + @Override public EmailsService emails() { return emailsService; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index 53cd28e86ab..64117e79d9f 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -32,6 +32,7 @@ import org.sonarqube.ws.client.components.ComponentsService; import org.sonarqube.ws.client.developers.DevelopersService; import org.sonarqube.ws.client.duplications.DuplicationsService; import org.sonarqube.ws.client.editions.EditionsService; +import org.sonarqube.ws.client.emails.EmailConfigurationService; import org.sonarqube.ws.client.emails.EmailsService; import org.sonarqube.ws.client.favorites.FavoritesService; import org.sonarqube.ws.client.github.configuration.GithubConfigurationService; @@ -124,6 +125,8 @@ public interface WsClient { EditionsService editions(); + EmailConfigurationService emailConfiguration(); + EmailsService emails(); FavoritesService favorites();