You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/03/03 07:07:08 UTC
[james-project] branch master updated (5a58535 -> ec7b50b)
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.
from 5a58535 JAMES-3477 Avoid unneeded message copies in ExtractMDNOriginalJMAPMessageId
new ce3c957 JAMES-3505 Make mail delivery multi-threaded
new a1595af JAMES-3506 Avoid multiple mailbox reads upon mail receival
new 92b283d JAMES-3502, add rabbitmq tls support
new 4547fd9 JAMES-3502, add rabbitmq tls support in connection factory
new 9a7bb03 JAMES-3502, update equals and hashCode methods on RabbitMQConfiguration.java
new 14a38d6 JAMES-3502, update equals and hashCode methods on RabbitMQConfiguration.SSLConfiguration
new 3c55b45 JAMES-3502, set keystore Optional.empty() as default (client cert authentication)
new 9a33b63 JAMES-3502, move exception catching to top level, use key store password for key password as well
new 12d7bd7 JAMES-3502, add ssl tests for RabbitMQConfiguration and RabbitMqConnectionFactory
new 432cdf3 JAMES-3502, add configuration key "useSslManagement"
new bda99c2 JAMES-3502, refactor, add more tests
new 790a312 JAMES-3502, add tls support in RabbitMQManagementAPI.java
new 362b6a1 JAMES-3502, update documentation for rabbitmq configuration keys.
new 86270c7 JAMES-3502, rabbitmqmanagementapi refactor
new a401e2a JAMES-3502, update RabbitMQConfiguration documentation
new dba18ad JAMES-3502, fix checkstyle
new 30817c8 JAMES-3502, add documentation in config-rabbitmq.xml
new beb20e8 JAMES-3502, add functional interface annotations
new 56800e8 JAMES-3502, update ssl.keystore documentation
new c024637 JAMES-3502, update ssl.hostname.verifier and ssl.validation.strategy documentation
new 500d6b8 JAMES-3502, remove duplicate line, refactor method name
new 9fdd4f4 JAMES-3502, use the version in root pom
new ec7b50b JAMES-3502, use the version in root pom for httpcore library
The 23 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
backends-common/rabbitmq/pom.xml | 8 +
.../backends/rabbitmq/RabbitMQConfiguration.java | 366 ++++++++++++++++++++-
.../rabbitmq/RabbitMQConnectionFactory.java | 123 ++++++-
.../backends/rabbitmq/RabbitMQManagementAPI.java | 133 +++++++-
.../rabbitmq/RabbitMQConfigurationTest.java | 135 ++++++++
.../rabbitmq/RabbitMQConnectionFactoryTest.java | 113 +++++++
.../rabbitmq/src/test/resources/empty-store | 0
.../test/resources/test-keystore-password-password | Bin 0 -> 2285 bytes
.../resources/test-truststore-password-password | Bin 0 -> 2285 bytes
.../pages/distributed/configure/rabbitmq.adoc | 31 ++
pom.xml | 5 +
.../mailets/delivery/MailboxAppender.java | 16 +-
.../mailets/remote/delivery/DeliveryRunnable.java | 43 ++-
server/protocols/jmap/pom.xml | 1 -
src/site/xdoc/server/config-rabbitmq.xml | 33 ++
15 files changed, 958 insertions(+), 49 deletions(-)
copy server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/service/CassandraMigrationService.java => backends-common/rabbitmq/src/test/resources/empty-store (100%)
create mode 100644 backends-common/rabbitmq/src/test/resources/test-keystore-password-password
create mode 100644 backends-common/rabbitmq/src/test/resources/test-truststore-password-password
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 12/23: JAMES-3502,
add tls support in RabbitMQManagementAPI.java
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 790a3125598f6c9f873e33b4de0c3415a024aeb5
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 08:17:57 2021 +0200
JAMES-3502, add tls support in RabbitMQManagementAPI.java
---
backends-common/rabbitmq/pom.xml | 5 +
.../backends/rabbitmq/RabbitMQManagementAPI.java | 112 +++++++++++++++++++--
2 files changed, 108 insertions(+), 9 deletions(-)
diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index 99a0507..0ff6f4e 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -99,6 +99,11 @@
<version>4.4.5</version>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.13</version>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
index 42406ab..8e4762d 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
@@ -19,16 +19,24 @@
package org.apache.james.backends.rabbitmq;
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.base.MoreObjects;
+import feign.Client;
import feign.Feign;
import feign.Logger;
import feign.Param;
@@ -40,6 +48,13 @@ import feign.codec.ErrorDecoder;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.ssl.TrustStrategy;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLContext;
public interface RabbitMQManagementAPI {
@@ -305,15 +320,94 @@ public interface RabbitMQManagementAPI {
static RabbitMQManagementAPI from(RabbitMQConfiguration configuration) {
RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
- return Feign.builder()
- .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new String(credentials.getPassword())))
- .logger(new Slf4jLogger(RabbitMQManagementAPI.class))
- .logLevel(Logger.Level.FULL)
- .encoder(new JacksonEncoder())
- .decoder(new JacksonDecoder())
- .retryer(new Retryer.Default())
- .errorDecoder(RETRY_500)
- .target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
+
+ RabbitMQManagementAPI rabbitMQManagementAPI = null;
+ try {
+ rabbitMQManagementAPI = Feign.builder()
+ .client(getClient(configuration))
+ .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new String(credentials.getPassword())))
+ .logger(new Slf4jLogger(RabbitMQManagementAPI.class))
+ .logLevel(Logger.Level.FULL)
+ .encoder(new JacksonEncoder())
+ .decoder(new JacksonDecoder())
+ .retryer(new Retryer.Default())
+ .errorDecoder(RETRY_500)
+ .target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
+ } catch (KeyManagementException | NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | UnrecoverableKeyException e) {
+ throw new RuntimeException(e);
+ }
+
+ return rabbitMQManagementAPI;
+ }
+
+ private static Client getClient(RabbitMQConfiguration configuration) throws KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException {
+ if (configuration.useSslManagement()) {
+ SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
+
+ setupSslValidationStrategy(sslContextBuilder, configuration);
+
+ setupClientCertificateAuthentication(sslContextBuilder, configuration);
+
+ SSLContext sslContext = sslContextBuilder.build();
+
+ return new Client.Default(sslContext.getSocketFactory(), getHostNameVerifier(configuration));
+ }
+ else {
+ return new Client.Default(null, null);
+ }
+
+ }
+
+ private static HostnameVerifier getHostNameVerifier(RabbitMQConfiguration configuration) {
+ switch (configuration.getSslConfiguration().getHostNameVerifier()) {
+ case ACCEPT_ANY_HOSTNAME:
+ return ((hostname, session) -> true);
+ default:
+ return new DefaultHostnameVerifier();
+ }
+ }
+
+ private static void setupClientCertificateAuthentication(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration configuration) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
+ Optional<RabbitMQConfiguration.SSLConfiguration.SSLKeyStore> keyStore = configuration.getSslConfiguration().getKeyStore();
+
+ if (keyStore.isPresent()) {
+ RabbitMQConfiguration.SSLConfiguration.SSLKeyStore sslKeyStore = keyStore.get();
+
+ sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(), sslKeyStore.getPassword());
+ }
+ }
+
+ private static void setupSslValidationStrategy(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration configuration) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
+ RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy strategy = configuration
+ .getSslConfiguration()
+ .getStrategy();
+
+ final TrustStrategy TRUST_ALL = (x509Certificates, authType) -> true;
+
+ switch (strategy) {
+ case DEFAULT:
+ break;
+ case IGNORE:
+ sslContextBuilder.loadTrustMaterial(TRUST_ALL);
+ break;
+ case OVERRIDE:
+ applyTrustStore(sslContextBuilder, configuration);
+ break;
+ default:
+ throw new NotImplementedException(
+ String.format("unrecognized strategy '%s'", strategy.name()));
+ }
+ }
+
+ private static SSLContextBuilder applyTrustStore(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration configuration) throws CertificateException, NoSuchAlgorithmException,
+ KeyStoreException, IOException {
+
+ RabbitMQConfiguration.SSLConfiguration.SSLTrustStore trustStore = configuration.getSslConfiguration()
+ .getTrustStore()
+ .orElseThrow(() -> new IllegalStateException("SSLTrustStore cannot to be empty"));
+
+ return sslContextBuilder
+ .loadTrustMaterial(trustStore.getFile(), trustStore.getPassword());
}
ErrorDecoder RETRY_500 = (methodKey, response) -> {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 02/23: JAMES-3506 Avoid multiple mailbox reads upon
mail receival
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit a1595afa6b66adbeee5f2e381d3e988fc0f4fcd8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sat Feb 27 14:45:31 2021 +0700
JAMES-3506 Avoid multiple mailbox reads upon mail receival
As we later read the mailbox we can save a "exist" check (~4ms)
---
.../transport/mailets/delivery/MailboxAppender.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
index 3f1e8f5..b356a25 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.MessageManager.AppendResult;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxExistsException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.model.ComposedMessageId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.server.core.MimeMessageInputStream;
@@ -37,8 +38,6 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Strings;
-import reactor.core.publisher.Mono;
-
public class MailboxAppender {
private static final Logger LOGGER = LoggerFactory.getLogger(MailboxAppender.class);
@@ -78,8 +77,7 @@ public class MailboxAppender {
}
private AppendResult appendMessageToMailbox(MimeMessage mail, MailboxSession session, MailboxPath path) throws MailboxException, MessagingException {
- createMailboxIfNotExist(session, path);
- final MessageManager mailbox = mailboxManager.getMailbox(path, session);
+ MessageManager mailbox = createMailboxIfNotExist(session, path);
if (mailbox == null) {
throw new MessagingException("Mailbox " + path + " for user " + session.getUser().asString() + " was not found on this server.");
}
@@ -89,12 +87,16 @@ public class MailboxAppender {
session);
}
- private void createMailboxIfNotExist(MailboxSession session, MailboxPath path) throws MailboxException {
- if (!Mono.from(mailboxManager.mailboxExists(path, session)).block()) {
+ private MessageManager createMailboxIfNotExist(MailboxSession session, MailboxPath path) throws MailboxException {
+ try {
+ return mailboxManager.getMailbox(path, session);
+ } catch (MailboxNotFoundException e) {
try {
mailboxManager.createMailbox(path, session);
- } catch (MailboxExistsException e) {
+ return mailboxManager.getMailbox(path, session);
+ } catch (MailboxExistsException exist) {
LOGGER.info("Mailbox {} have been created concurrently", path);
+ return mailboxManager.getMailbox(path, session);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 22/23: JAMES-3502, use the version in root pom
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 9fdd4f43e21c5fbb0e588f269e64815c5d3f96e2
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Mon Mar 1 14:55:58 2021 +0200
JAMES-3502, use the version in root pom
---
backends-common/rabbitmq/pom.xml | 1 -
1 file changed, 1 deletion(-)
diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index 87c7a74..48d49f4 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -96,7 +96,6 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 01/23: JAMES-3505 Make mail delivery multi-threaded
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit ce3c957f223ac47ce72b044069d9ebb9c1a4d925
Author: brokenshoebox <br...@gmail.com>
AuthorDate: Mon Mar 1 12:00:02 2021 +1300
JAMES-3505 Make mail delivery multi-threaded
Mail delivery is single threaded due to blocking code in
DeliveryRunnable, which prevents reactor from scheduling mails
simultaneously.
---
.../mailets/remote/delivery/DeliveryRunnable.java | 43 +++++++++++++---------
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java
index f380632..d708f2e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java
@@ -104,24 +104,31 @@ public class DeliveryRunnable implements Disposable {
}
}
- private Mono<Void> processMail(MailQueue.MailQueueItem queueItem) throws MailQueue.MailQueueException {
- Mail mail = queueItem.getMail();
-
- try {
- LOGGER.debug("will process mail {}", mail.getName());
- attemptDelivery(mail);
- queueItem.done(true);
- return Mono.empty();
- } catch (Exception e) {
- // Prevent unexpected exceptions from causing looping by removing message from outgoing.
- // DO NOT CHANGE THIS to catch Error!
- // For example, if there were an OutOfMemory condition caused because
- // something else in the server was abusing memory, we would not want to start purging the retrying spool!
- queueItem.done(false);
- return Mono.error(e);
- } finally {
- LifecycleUtil.dispose(mail);
- }
+ private Mono<Void> processMail(MailQueue.MailQueueItem queueItem) {
+ return Mono.create(sink -> {
+ Mail mail = queueItem.getMail();
+
+ try {
+ LOGGER.debug("will process mail {}", mail.getName());
+ attemptDelivery(mail);
+ queueItem.done(true);
+ sink.success();
+ } catch (Exception e) {
+ try {
+ // Prevent unexpected exceptions from causing looping by removing message from outgoing.
+ // DO NOT CHANGE THIS to catch Error!
+ // For example, if there were an OutOfMemory condition caused because
+ // something else in the server was abusing memory, we would not want to start purging the retrying spool!
+ queueItem.done(false);
+ } catch (Exception ex) {
+ sink.error(ex);
+ return;
+ }
+ sink.error(e);
+ } finally {
+ LifecycleUtil.dispose(mail);
+ }
+ });
}
@VisibleForTesting
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 13/23: JAMES-3502,
update documentation for rabbitmq configuration keys.
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 362b6a18c12e83214d97ae9d223b1f0d8256d930
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 09:05:33 2021 +0200
JAMES-3502, update documentation for rabbitmq configuration keys.
---
.../pages/distributed/configure/rabbitmq.adoc | 33 ++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
index 589460b..035049b 100644
--- a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
+++ b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
@@ -46,6 +46,39 @@ Optional integer, defaults to 50
| Configure the size of the channel pool.
Optional integer, defaults to 3
+
+
+| ssl.enabled
+| Is using ssl enabled
+Optional boolean, defaults to false
+
+| ssl.management.enabled
+| Is using ssl on management api enabled
+Optional boolean, defaults to false
+
+| ssl.validation.strategy
+| Configure the validation strategy used for rabbitmq connections. Possible values are default, ignore and override.
+Optional string, defaults to default
+
+| ssl.truststore
+| Points to the truststore used for verifying rabbitmq connection. If configured then "ssl.truststore.password" must also be configured,
+Optional string, defaults to systemwide truststore. "ssl.validation.strategy: override" must be configured if you want to use this
+
+| ssl.truststore.password
+| Configure the truststore password. If configured then "ssl.truststore" must also be configured,
+Optional string, defaults to empty string. "ssl.validation.strategy: override" must be configured if you want to use this
+
+| ssl.hostname.verifier
+| Configure host name verification. Possible options are default and accept_any_hostname
+Optional string, defaults to default
+
+| ssl.keystore
+| Points to the keystore used for verifying rabbitmq connection. If configured then "ssl.keystore.password" must also be configured,
+Optional string, defaults to empty string
+
+| ssl.keystore.password
+| Configure the keystore password. If configured then "ssl.keystore" must also be configured,
+Optional string, defaults to empty string
|===
== RabbitMQ MailQueue Configuration
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 07/23: JAMES-3502,
set keystore Optional.empty() as default (client cert
authentication)
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3c55b45dae5b5a149ba1c6b426b354e63b66be1f
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Wed Feb 24 20:52:10 2021 +0200
JAMES-3502, set keystore Optional.empty() as default (client cert authentication)
---
.../java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 96957a0..89da884 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -205,6 +205,7 @@ public class RabbitMQConfiguration {
this.sslValidationStrategy = sslValidationStrategy;
this.hostNameVerifier = hostNameVerifier;
this.sslTrustStore = sslTrustStore;
+ this.sslKeyStore = Optional.empty();
}
public ReadyToBuild sslKeyStore(Optional<SSLKeyStore> sslKeyStore) {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 18/23: JAMES-3502,
add functional interface annotations
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit beb20e870ed219b0505524cf49fce4eea5f9ef7e
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 11:54:34 2021 +0200
JAMES-3502, add functional interface annotations
---
.../java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index a5155cb..0032770 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -171,6 +171,7 @@ public class RabbitMQConfiguration {
static class Builder {
+ @FunctionalInterface
interface RequireSSLStrategyTrustStore {
RequireHostNameVerifier sslStrategy(SSLValidationStrategy strategy, Optional<SSLTrustStore> trustStore);
@@ -187,6 +188,7 @@ public class RabbitMQConfiguration {
}
}
+ @FunctionalInterface
interface RequireHostNameVerifier {
ReadyToBuild hostNameVerifier(HostNameVerifier hostNameVerifier);
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 08/23: JAMES-3502,
move exception catching to top level,
use key store password for key password as well
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 9a33b63fbd54198bc5991b52659db22e3f31779b
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Wed Feb 24 21:06:19 2021 +0200
JAMES-3502, move exception catching to top level, use key store password for key password as well
---
.../apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
index 83dee07..80528c2 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
@@ -77,13 +77,9 @@ public class RabbitMQConnectionFactory {
}
}
- private void setupSslConfiguration(ConnectionFactory connectionFactory) {
- try {
+ private void setupSslConfiguration(ConnectionFactory connectionFactory) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException, IOException {
connectionFactory.useSslProtocol(sslContext(configuration));
setupHostNameVerification(connectionFactory);
- } catch (KeyManagementException | NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | UnrecoverableKeyException e) {
- throw new RuntimeException("Cannot set SSL options to the connection factory", e);
- }
}
private SSLContext sslContext(RabbitMQConfiguration configuration) throws KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException {
@@ -105,7 +101,7 @@ public class RabbitMQConnectionFactory {
if (keyStore.isPresent()) {
SSLKeyStore sslKeyStore = keyStore.get();
- sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(), null);
+ sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(), sslKeyStore.getPassword());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 11/23: JAMES-3502, refactor, add more tests
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit bda99c2dbc983ebdc91aa03746090cab3758fa58
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 08:16:25 2021 +0200
JAMES-3502, refactor, add more tests
---
.../rabbitmq/RabbitMQConfigurationTest.java | 52 +++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
index 0d0535e..150f003 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
@@ -29,6 +29,7 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
+import java.util.Optional;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.junit.jupiter.api.Nested;
@@ -337,6 +338,55 @@ class RabbitMQConfigurationTest {
.isEqualTo(shutdownTimeout);
}
+ @Test
+ void sslConfigurationShouldHaveDefaultWhenNotSpecifiedOtherwise() throws URISyntaxException {
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .build();
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getHostNameVerifier())
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.DEFAULT);
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getStrategy())
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.DEFAULT);
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getTrustStore())
+ .isEmpty();
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getKeyStore())
+ .isEmpty();
+ }
+
+ @Test
+ void sslConfigurationShouldHaveCustomValuesIfUseInConfiguration() throws URISyntaxException {
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .sslConfiguration(
+ RabbitMQConfiguration.SSLConfiguration.builder()
+ .strategyOverride(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of("src/test/resources/test-truststore-password-password", "password"))
+ .acceptAnyHostNameVerifier()
+ .sslKeyStore(Optional.of(RabbitMQConfiguration.SSLConfiguration.SSLKeyStore.of("src/test/resources/test-keystore-password-password", "password")))
+ .build()
+ )
+ .build();
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getHostNameVerifier())
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.ACCEPT_ANY_HOSTNAME);
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getStrategy())
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.OVERRIDE);
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getTrustStore())
+ .isNotEmpty();
+
+ assertThat(rabbitMQConfiguration.getSslConfiguration().getKeyStore())
+ .isNotEmpty();
+ }
+
@Nested
class ManagementCredentialsTest {
@Test
@@ -439,7 +489,7 @@ class RabbitMQConfigurationTest {
}
@Nested
- class SSLTrustStore {
+ class SSLTrustStoreTest {
@Test
void ofShouldThrowExceptionWhenFilePathNotSupplied() {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 10/23: JAMES-3502,
add configuration key "useSslManagement"
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 432cdf3403c73f5933cf5abe0b046b273ad6a804
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 08:15:54 2021 +0200
JAMES-3502, add configuration key "useSslManagement"
---
.../backends/rabbitmq/RabbitMQConfiguration.java | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 89da884..87d5b11 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -280,6 +280,7 @@ public class RabbitMQConfiguration {
}
private static String USE_SSL = "ssl.enabled";
+ private static String USE_SSL_MANAGEMENT = "ssl.management.enabled";
private static String SSL_TRUST_STORE_PATH = "ssl.truststore";
private static String SSL_TRUST_STORE_PASSWORD = "ssl.truststore.password";
@@ -374,6 +375,7 @@ public class RabbitMQConfiguration {
private Optional<Integer> shutdownTimeoutInMs;
private Optional<Integer> networkRecoveryIntervalInMs;
private Optional<Boolean> useSsl;
+ private Optional<Boolean> useSslManagement;
private Optional<SSLConfiguration> sslConfiguration;
private Builder(URI amqpUri, URI managementUri, ManagementCredentials managementCredentials) {
@@ -388,6 +390,7 @@ public class RabbitMQConfiguration {
this.shutdownTimeoutInMs = Optional.empty();
this.networkRecoveryIntervalInMs = Optional.empty();
this.useSsl = Optional.empty();
+ this.useSslManagement = Optional.empty();
this.sslConfiguration = Optional.empty();
}
@@ -431,6 +434,11 @@ public class RabbitMQConfiguration {
return this;
}
+ public Builder useSslManagement(Boolean useSslForManagement) {
+ this.useSslManagement = Optional.of(useSslForManagement);
+ return this;
+ }
+
public Builder sslConfiguration(SSLConfiguration sslConfiguration) {
this.sslConfiguration = Optional.of(sslConfiguration);
return this;
@@ -451,6 +459,7 @@ public class RabbitMQConfiguration {
shutdownTimeoutInMs.orElse(DEFAULT_SHUTDOWN_TIMEOUT),
networkRecoveryIntervalInMs.orElse(DEFAULT_NETWORK_RECOVERY_INTERVAL),
useSsl.orElse(false),
+ useSslManagement.orElse(false),
sslConfiguration.orElse(defaultBehavior())
);
}
@@ -474,6 +483,7 @@ public class RabbitMQConfiguration {
URI managementUri = checkURI(managementUriAsString);
Boolean useSsl = configuration.getBoolean(USE_SSL, false);
+ Boolean useSslForManagement = configuration.getBoolean(USE_SSL_MANAGEMENT, false);
ManagementCredentials managementCredentials = ManagementCredentials.from(configuration);
return builder()
@@ -481,6 +491,7 @@ public class RabbitMQConfiguration {
.managementUri(managementUri)
.managementCredentials(managementCredentials)
.useSsl(useSsl)
+ .useSslManagement(useSslForManagement)
.sslConfiguration(sslTrustConfiguration(configuration))
.sslConfiguration(sslTrustConfiguration(configuration))
.build();
@@ -544,13 +555,14 @@ public class RabbitMQConfiguration {
private final int shutdownTimeoutInMs;
private final int networkRecoveryIntervalInMs;
private final Boolean useSsl;
+ private final Boolean useSslManagement;
private final SSLConfiguration sslConfiguration;
private final ManagementCredentials managementCredentials;
private RabbitMQConfiguration(URI uri, URI managementUri, ManagementCredentials managementCredentials, int maxRetries, int minDelayInMs,
- int connectionTimeoutInMs, int channelRpcTimeoutInMs, int handshakeTimeoutInMs, int shutdownTimeoutInMs, int networkRecoveryIntervalInMs, Boolean useSsl, SSLConfiguration sslConfiguration) {
+ int connectionTimeoutInMs, int channelRpcTimeoutInMs, int handshakeTimeoutInMs, int shutdownTimeoutInMs, int networkRecoveryIntervalInMs, Boolean useSsl, Boolean useSslManagement, SSLConfiguration sslConfiguration) {
this.uri = uri;
this.managementUri = managementUri;
this.managementCredentials = managementCredentials;
@@ -562,6 +574,7 @@ public class RabbitMQConfiguration {
this.shutdownTimeoutInMs = shutdownTimeoutInMs;
this.networkRecoveryIntervalInMs = networkRecoveryIntervalInMs;
this.useSsl = useSsl;
+ this.useSslManagement = useSslManagement;
this.sslConfiguration = sslConfiguration;
}
@@ -609,6 +622,10 @@ public class RabbitMQConfiguration {
return useSsl;
}
+ public Boolean useSslManagement() {
+ return useSslManagement;
+ }
+
public SSLConfiguration getSslConfiguration() {
return sslConfiguration;
}
@@ -629,6 +646,7 @@ public class RabbitMQConfiguration {
&& Objects.equals(this.networkRecoveryIntervalInMs, that.networkRecoveryIntervalInMs)
&& Objects.equals(this.managementCredentials, that.managementCredentials)
&& Objects.equals(this.useSsl, that.useSsl)
+ && Objects.equals(this.useSslManagement, that.useSslManagement)
&& Objects.equals(this.sslConfiguration, that.sslConfiguration
);
}
@@ -638,6 +656,6 @@ public class RabbitMQConfiguration {
@Override
public final int hashCode() {
return Objects.hash(uri, managementUri, maxRetries, minDelayInMs, connectionTimeoutInMs,
- channelRpcTimeoutInMs, handshakeTimeoutInMs, shutdownTimeoutInMs, networkRecoveryIntervalInMs, managementCredentials, useSsl, sslConfiguration);
+ channelRpcTimeoutInMs, handshakeTimeoutInMs, shutdownTimeoutInMs, networkRecoveryIntervalInMs, managementCredentials, useSsl, useSslManagement, sslConfiguration);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 14/23: JAMES-3502, rabbitmqmanagementapi refactor
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 86270c7282bb32f4a3dbc73919e3497f48c293df
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 09:25:05 2021 +0200
JAMES-3502, rabbitmqmanagementapi refactor
---
backends-common/rabbitmq/pom.xml | 8 ++++----
.../apache/james/backends/rabbitmq/RabbitMQManagementAPI.java | 10 ++++------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index 0ff6f4e..87c7a74 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -95,13 +95,13 @@
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpcore</artifactId>
- <version>4.4.5</version>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>4.5.13</version>
+ <artifactId>httpcore</artifactId>
+ <version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
index 8e4762d..d6b4f67 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
@@ -319,11 +319,9 @@ public interface RabbitMQManagementAPI {
}
static RabbitMQManagementAPI from(RabbitMQConfiguration configuration) {
- RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
-
- RabbitMQManagementAPI rabbitMQManagementAPI = null;
try {
- rabbitMQManagementAPI = Feign.builder()
+ RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
+ RabbitMQManagementAPI rabbitMQManagementAPI = Feign.builder()
.client(getClient(configuration))
.requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new String(credentials.getPassword())))
.logger(new Slf4jLogger(RabbitMQManagementAPI.class))
@@ -333,11 +331,11 @@ public interface RabbitMQManagementAPI {
.retryer(new Retryer.Default())
.errorDecoder(RETRY_500)
.target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
+
+ return rabbitMQManagementAPI;
} catch (KeyManagementException | NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | UnrecoverableKeyException e) {
throw new RuntimeException(e);
}
-
- return rabbitMQManagementAPI;
}
private static Client getClient(RabbitMQConfiguration configuration) throws KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 17/23: JAMES-3502,
add documentation in config-rabbitmq.xml
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 30817c851b03edb4361a551e4f2ab0c8f51b4f74
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 11:51:24 2021 +0200
JAMES-3502, add documentation in config-rabbitmq.xml
---
.../pages/distributed/configure/rabbitmq.adoc | 2 --
src/site/xdoc/server/config-rabbitmq.xml | 33 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
index 9ec2be7..33f8d9b 100644
--- a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
+++ b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
@@ -46,8 +46,6 @@ Optional integer, defaults to 50
| Configure the size of the channel pool.
Optional integer, defaults to 3
-
-
| ssl.enabled
| Is using ssl enabled
Optional boolean, defaults to false
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index b0b7e7a..d6e79b3 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -77,6 +77,39 @@
<dt><strong>channel.pool.size</strong></dt>
<dd>Configure the size of the channel pool.
Optional integer, defaults to 3</dd>
+
+ <dt><strong>ssl.enabled</strong></dt>
+ <dd>Is using ssl enabled
+ Optional boolean, defaults to false</dd>
+
+ <dt><strong>ssl.management.enabled</strong></dt>
+ <dd>Is using ssl on management api enabled
+ Optional boolean, defaults to false</dd>
+
+ <dt><strong>ssl.validation.strategy</strong></dt>
+ <dd>Configure the validation strategy used for rabbitmq connections. Possible values are default, ignore and override.
+ Optional string, defaults to default</dd>
+
+ <dt><strong>ssl.truststore</strong></dt>
+ <dd>Points to the truststore (PKCS12) used for verifying rabbitmq connection. If configured then "ssl.truststore.password" must also be configured,
+ Optional string, defaults to systemwide truststore. "ssl.validation.strategy: override" must be configured if you want to use this</dd>
+
+ <dt><strong>ssl.truststore.password</strong></dt>
+ <dd>Configure the truststore password. If configured then "ssl.truststore" must also be configured,
+ Optional string, defaults to empty string. "ssl.validation.strategy: override" must be configured if you want to use this</dd>
+
+ <dt><strong>ssl.hostname.verifier</strong></dt>
+ <dd>Configure host name verification. Possible options are default and accept_any_hostname
+ Optional string, defaults to default</dd>
+
+
+ <dt><strong>ssl.keystore</strong></dt>
+ <dd>Points to the keystore(PKCS12) used for verifying rabbitmq connection. If configured then "ssl.keystore.password" must also be configured,
+ Optional string, defaults to empty string</dd>
+
+ <dt><strong>ssl.keystore.password</strong></dt>
+ <dd>Configure the keystore password. If configured then "ssl.keystore" must also be configured,
+ Optional string, defaults to empty string</dd>
</dl>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 16/23: JAMES-3502, fix checkstyle
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit dba18ad3cbe3ea78596c67bdb62d9315159db764
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 11:44:51 2021 +0200
JAMES-3502, fix checkstyle
---
.../backends/rabbitmq/RabbitMQConfiguration.java | 10 ++-
.../rabbitmq/RabbitMQConnectionFactory.java | 89 ++++++++++++++--------
.../backends/rabbitmq/RabbitMQManagementAPI.java | 85 ++++++++++++---------
3 files changed, 116 insertions(+), 68 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 87d5b11..a5155cb 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -18,6 +18,13 @@
****************************************************************/
package org.apache.james.backends.rabbitmq;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.HostNameVerifier;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLKeyStore;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLTrustStore;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.OVERRIDE;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.defaultBehavior;
+
import java.io.File;
import java.net.URI;
import java.nio.file.Files;
@@ -32,9 +39,6 @@ import org.apache.commons.configuration2.Configuration;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.*;
-import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.*;
-
public class RabbitMQConfiguration {
public static class SSLConfiguration {
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
index 80528c2..94b162f 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
@@ -18,6 +18,11 @@
****************************************************************/
package org.apache.james.backends.rabbitmq;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.HostNameVerifier;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLKeyStore;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLTrustStore;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy;
+
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
@@ -30,18 +35,17 @@ import java.util.Optional;
import javax.inject.Inject;
import javax.net.ssl.SSLContext;
-import com.rabbitmq.client.Connection;
-import com.rabbitmq.client.ConnectionFactory;
-
import org.apache.commons.lang3.NotImplementedException;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
+
+import com.rabbitmq.client.Connection;
+import com.rabbitmq.client.ConnectionFactory;
+
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.util.retry.Retry;
-import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.*;
-
public class RabbitMQConnectionFactory {
private static final TrustStrategy TRUST_ALL = (x509Certificates, authType) -> true;
@@ -62,14 +66,21 @@ public class RabbitMQConnectionFactory {
connectionFactory.setUri(rabbitMQConfiguration.getUri());
connectionFactory.setHandshakeTimeout(rabbitMQConfiguration.getHandshakeTimeoutInMs());
connectionFactory.setShutdownTimeout(rabbitMQConfiguration.getShutdownTimeoutInMs());
- connectionFactory.setChannelRpcTimeout(rabbitMQConfiguration.getChannelRpcTimeoutInMs());
- connectionFactory.setConnectionTimeout(rabbitMQConfiguration.getConnectionTimeoutInMs());
- connectionFactory.setNetworkRecoveryInterval(rabbitMQConfiguration.getNetworkRecoveryIntervalInMs());
-
- connectionFactory.setUsername(rabbitMQConfiguration.getManagementCredentials().getUser());
- connectionFactory.setPassword(String.valueOf(rabbitMQConfiguration.getManagementCredentials().getPassword()));
-
- if (configuration.useSsl()) setupSslConfiguration(connectionFactory);
+ connectionFactory
+ .setChannelRpcTimeout(rabbitMQConfiguration.getChannelRpcTimeoutInMs());
+ connectionFactory
+ .setConnectionTimeout(rabbitMQConfiguration.getConnectionTimeoutInMs());
+ connectionFactory
+ .setNetworkRecoveryInterval(rabbitMQConfiguration.getNetworkRecoveryIntervalInMs());
+
+ connectionFactory
+ .setUsername(rabbitMQConfiguration.getManagementCredentials().getUser());
+ connectionFactory.setPassword(
+ String.valueOf(rabbitMQConfiguration.getManagementCredentials().getPassword()));
+
+ if (configuration.useSsl()) {
+ setupSslConfiguration(connectionFactory);
+ }
return connectionFactory;
} catch (Exception e) {
@@ -77,15 +88,20 @@ public class RabbitMQConnectionFactory {
}
}
- private void setupSslConfiguration(ConnectionFactory connectionFactory) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException, IOException {
- connectionFactory.useSslProtocol(sslContext(configuration));
- setupHostNameVerification(connectionFactory);
+ private void setupSslConfiguration(ConnectionFactory connectionFactory)
+ throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException,
+ KeyManagementException, KeyStoreException, IOException {
+ connectionFactory.useSslProtocol(sslContext(configuration));
+ setupHostNameVerification(connectionFactory);
}
- private SSLContext sslContext(RabbitMQConfiguration configuration) throws KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException {
+ private SSLContext sslContext(RabbitMQConfiguration configuration)
+ throws KeyManagementException, NoSuchAlgorithmException, CertificateException,
+ KeyStoreException, IOException, UnrecoverableKeyException {
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
- RabbitMQConfiguration.SSLConfiguration sslConfiguration = configuration.getSslConfiguration();
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration =
+ configuration.getSslConfiguration();
setupSslValidationStrategy(sslContextBuilder, sslConfiguration);
@@ -95,19 +111,25 @@ public class RabbitMQConnectionFactory {
}
- private void setupClientCertificateAuthentication(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration.SSLConfiguration sslConfiguration) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
+ private void setupClientCertificateAuthentication(SSLContextBuilder sslContextBuilder,
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration)
+ throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException,
+ CertificateException, IOException {
Optional<SSLKeyStore> keyStore = sslConfiguration.getKeyStore();
if (keyStore.isPresent()) {
SSLKeyStore sslKeyStore = keyStore.get();
- sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(), sslKeyStore.getPassword());
+ sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(),
+ sslKeyStore.getPassword());
}
}
- private void setupSslValidationStrategy(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration.SSLConfiguration sslConfiguration) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
+ private void setupSslValidationStrategy(SSLContextBuilder sslContextBuilder,
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration)
+ throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
SSLValidationStrategy strategy = sslConfiguration
- .getStrategy();
+ .getStrategy();
switch (strategy) {
case DEFAULT:
@@ -120,26 +142,29 @@ public class RabbitMQConnectionFactory {
break;
default:
throw new NotImplementedException(
- String.format("unrecognized strategy '%s'", strategy.name()));
+ String.format("unrecognized strategy '%s'", strategy.name()));
}
}
- private SSLContextBuilder applyTrustStore(SSLContextBuilder sslContextBuilder) throws CertificateException, NoSuchAlgorithmException,
- KeyStoreException, IOException {
+ private SSLContextBuilder applyTrustStore(SSLContextBuilder sslContextBuilder)
+ throws CertificateException, NoSuchAlgorithmException,
+ KeyStoreException, IOException {
SSLTrustStore trustStore = configuration.getSslConfiguration()
- .getTrustStore()
- .orElseThrow(() -> new IllegalStateException("SSLTrustStore cannot to be empty"));
+ .getTrustStore()
+ .orElseThrow(() -> new IllegalStateException("SSLTrustStore cannot to be empty"));
return sslContextBuilder
- .loadTrustMaterial(trustStore.getFile(), trustStore.getPassword());
+ .loadTrustMaterial(trustStore.getFile(), trustStore.getPassword());
}
private void setupHostNameVerification(ConnectionFactory connectionFactory) {
HostNameVerifier hostNameVerifier = configuration.getSslConfiguration()
- .getHostNameVerifier();
+ .getHostNameVerifier();
- if (hostNameVerifier == HostNameVerifier.DEFAULT) connectionFactory.enableHostnameVerification();
+ if (hostNameVerifier == HostNameVerifier.DEFAULT) {
+ connectionFactory.enableHostnameVerification();
+ }
}
Connection create() {
@@ -148,6 +173,8 @@ public class RabbitMQConnectionFactory {
Mono<Connection> connectionMono() {
return Mono.fromCallable(connectionFactory::newConnection)
- .retryWhen(Retry.backoff(configuration.getMaxRetries(), Duration.ofMillis(configuration.getMinDelayInMs())).scheduler(Schedulers.elastic()));
+ .retryWhen(Retry.backoff(configuration.getMaxRetries(),
+ Duration.ofMillis(configuration.getMinDelayInMs()))
+ .scheduler(Schedulers.elastic()));
}
}
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
index d6b4f67..e21860c 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQManagementAPI.java
@@ -31,6 +31,14 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLContext;
+
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.ssl.TrustStrategy;
+
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -48,13 +56,6 @@ import feign.codec.ErrorDecoder;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.http.conn.ssl.DefaultHostnameVerifier;
-import org.apache.http.ssl.SSLContextBuilder;
-import org.apache.http.ssl.TrustStrategy;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
public interface RabbitMQManagementAPI {
@@ -314,23 +315,26 @@ public interface RabbitMQManagementAPI {
@Override
public final int hashCode() {
- return Objects.hash(source, vhost, destination, destinationType, routingKey, arguments, propertiesKey);
+ return Objects.hash(source, vhost, destination, destinationType, routingKey, arguments,
+ propertiesKey);
}
}
static RabbitMQManagementAPI from(RabbitMQConfiguration configuration) {
try {
- RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
+ RabbitMQConfiguration.ManagementCredentials credentials =
+ configuration.getManagementCredentials();
RabbitMQManagementAPI rabbitMQManagementAPI = Feign.builder()
- .client(getClient(configuration))
- .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new String(credentials.getPassword())))
- .logger(new Slf4jLogger(RabbitMQManagementAPI.class))
- .logLevel(Logger.Level.FULL)
- .encoder(new JacksonEncoder())
- .decoder(new JacksonDecoder())
- .retryer(new Retryer.Default())
- .errorDecoder(RETRY_500)
- .target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
+ .client(getClient(configuration))
+ .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(),
+ new String(credentials.getPassword())))
+ .logger(new Slf4jLogger(RabbitMQManagementAPI.class))
+ .logLevel(Logger.Level.FULL)
+ .encoder(new JacksonEncoder())
+ .decoder(new JacksonDecoder())
+ .retryer(new Retryer.Default())
+ .errorDecoder(RETRY_500)
+ .target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
return rabbitMQManagementAPI;
} catch (KeyManagementException | NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | UnrecoverableKeyException e) {
@@ -338,7 +342,9 @@ public interface RabbitMQManagementAPI {
}
}
- private static Client getClient(RabbitMQConfiguration configuration) throws KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException {
+ private static Client getClient(RabbitMQConfiguration configuration)
+ throws KeyManagementException, NoSuchAlgorithmException, CertificateException,
+ KeyStoreException, IOException, UnrecoverableKeyException {
if (configuration.useSslManagement()) {
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
@@ -348,9 +354,9 @@ public interface RabbitMQManagementAPI {
SSLContext sslContext = sslContextBuilder.build();
- return new Client.Default(sslContext.getSocketFactory(), getHostNameVerifier(configuration));
- }
- else {
+ return new Client.Default(sslContext.getSocketFactory(),
+ getHostNameVerifier(configuration));
+ } else {
return new Client.Default(null, null);
}
@@ -365,20 +371,27 @@ public interface RabbitMQManagementAPI {
}
}
- private static void setupClientCertificateAuthentication(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration configuration) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
- Optional<RabbitMQConfiguration.SSLConfiguration.SSLKeyStore> keyStore = configuration.getSslConfiguration().getKeyStore();
+ private static void setupClientCertificateAuthentication(SSLContextBuilder sslContextBuilder,
+ RabbitMQConfiguration configuration)
+ throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException,
+ CertificateException, IOException {
+ Optional<RabbitMQConfiguration.SSLConfiguration.SSLKeyStore> keyStore =
+ configuration.getSslConfiguration().getKeyStore();
if (keyStore.isPresent()) {
RabbitMQConfiguration.SSLConfiguration.SSLKeyStore sslKeyStore = keyStore.get();
- sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(), sslKeyStore.getPassword());
+ sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(),
+ sslKeyStore.getPassword());
}
}
- private static void setupSslValidationStrategy(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration configuration) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
+ private static void setupSslValidationStrategy(SSLContextBuilder sslContextBuilder,
+ RabbitMQConfiguration configuration)
+ throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy strategy = configuration
- .getSslConfiguration()
- .getStrategy();
+ .getSslConfiguration()
+ .getStrategy();
final TrustStrategy TRUST_ALL = (x509Certificates, authType) -> true;
@@ -393,24 +406,28 @@ public interface RabbitMQManagementAPI {
break;
default:
throw new NotImplementedException(
- String.format("unrecognized strategy '%s'", strategy.name()));
+ String.format("unrecognized strategy '%s'", strategy.name()));
}
}
- private static SSLContextBuilder applyTrustStore(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration configuration) throws CertificateException, NoSuchAlgorithmException,
- KeyStoreException, IOException {
+ private static SSLContextBuilder applyTrustStore(SSLContextBuilder sslContextBuilder,
+ RabbitMQConfiguration configuration)
+ throws CertificateException, NoSuchAlgorithmException,
+ KeyStoreException, IOException {
- RabbitMQConfiguration.SSLConfiguration.SSLTrustStore trustStore = configuration.getSslConfiguration()
+ RabbitMQConfiguration.SSLConfiguration.SSLTrustStore trustStore =
+ configuration.getSslConfiguration()
.getTrustStore()
.orElseThrow(() -> new IllegalStateException("SSLTrustStore cannot to be empty"));
return sslContextBuilder
- .loadTrustMaterial(trustStore.getFile(), trustStore.getPassword());
+ .loadTrustMaterial(trustStore.getFile(), trustStore.getPassword());
}
ErrorDecoder RETRY_500 = (methodKey, response) -> {
if (response.status() == 500) {
- throw new RetryableException(response.status(), "Error encountered, scheduling retry", response.request().httpMethod(), new Date());
+ throw new RetryableException(response.status(), "Error encountered, scheduling retry",
+ response.request().httpMethod(), new Date());
}
throw new RuntimeException("Non recoverable exception status: " + response.status());
};
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 15/23: JAMES-3502,
update RabbitMQConfiguration documentation
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit a401e2aafd0176c93cf3c947455975779fd8a1eb
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 09:57:37 2021 +0200
JAMES-3502, update RabbitMQConfiguration documentation
---
docs/modules/servers/pages/distributed/configure/rabbitmq.adoc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
index 035049b..9ec2be7 100644
--- a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
+++ b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
@@ -61,7 +61,7 @@ Optional boolean, defaults to false
Optional string, defaults to default
| ssl.truststore
-| Points to the truststore used for verifying rabbitmq connection. If configured then "ssl.truststore.password" must also be configured,
+| Points to the truststore (PKCS12) used for verifying rabbitmq connection. If configured then "ssl.truststore.password" must also be configured,
Optional string, defaults to systemwide truststore. "ssl.validation.strategy: override" must be configured if you want to use this
| ssl.truststore.password
@@ -73,7 +73,7 @@ Optional string, defaults to empty string. "ssl.validation.strategy: override" m
Optional string, defaults to default
| ssl.keystore
-| Points to the keystore used for verifying rabbitmq connection. If configured then "ssl.keystore.password" must also be configured,
+| Points to the keystore(PKCS12) used for verifying rabbitmq connection. If configured then "ssl.keystore.password" must also be configured,
Optional string, defaults to empty string
| ssl.keystore.password
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 23/23: JAMES-3502,
use the version in root pom for httpcore library
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit ec7b50b82c5386aec6ee115a3b4c1b3018f7b4a8
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Tue Mar 2 09:16:48 2021 +0200
JAMES-3502, use the version in root pom for httpcore library
---
backends-common/rabbitmq/pom.xml | 1 -
pom.xml | 5 +++++
server/protocols/jmap/pom.xml | 1 -
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index 48d49f4..6fb173c 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -100,7 +100,6 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
- <version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
diff --git a/pom.xml b/pom.xml
index f5a7030..1cdf16b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2442,6 +2442,11 @@
<version>4.5.13</version>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>4.4.14</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j-dom</artifactId>
<version>${apache-mime4j.version}</version>
diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml
index ddb1079..5623136 100644
--- a/server/protocols/jmap/pom.xml
+++ b/server/protocols/jmap/pom.xml
@@ -82,7 +82,6 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
- <version>4.4.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 20/23: JAMES-3502,
update ssl.hostname.verifier and ssl.validation.strategy
documentation
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c024637d57a47c8b8736302f09118f453d96262e
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 12:04:59 2021 +0200
JAMES-3502, update ssl.hostname.verifier and ssl.validation.strategy documentation
---
docs/modules/servers/pages/distributed/configure/rabbitmq.adoc | 4 ++--
src/site/xdoc/server/config-rabbitmq.xml | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
index 3b29960..c064398 100644
--- a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
+++ b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
@@ -56,7 +56,7 @@ Optional boolean, defaults to false
| ssl.validation.strategy
| Configure the validation strategy used for rabbitmq connections. Possible values are default, ignore and override.
-Optional string, defaults to default
+Optional string, defaults to using systemwide ssl configuration
| ssl.truststore
| Points to the truststore (PKCS12) used for verifying rabbitmq connection. If configured then "ssl.truststore.password" must also be configured,
@@ -68,7 +68,7 @@ Optional string, defaults to empty string. "ssl.validation.strategy: override" m
| ssl.hostname.verifier
| Configure host name verification. Possible options are default and accept_any_hostname
-Optional string, defaults to default
+Optional string, defaults to subject alternative name host verifier
| ssl.keystore
| Points to the keystore(PKCS12) used for client certificate authentication. If configured then "ssl.keystore.password" must also be configured,
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index 550f4ef..f53eb76 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -88,7 +88,7 @@
<dt><strong>ssl.validation.strategy</strong></dt>
<dd>Configure the validation strategy used for rabbitmq connections. Possible values are default, ignore and override.
- Optional string, defaults to default</dd>
+ Optional string, defaults to using systemwide ssl configuration</dd>
<dt><strong>ssl.truststore</strong></dt>
<dd>Points to the truststore (PKCS12) used for verifying rabbitmq connection. If configured then "ssl.truststore.password" must also be configured,
@@ -100,7 +100,7 @@
<dt><strong>ssl.hostname.verifier</strong></dt>
<dd>Configure host name verification. Possible options are default and accept_any_hostname
- Optional string, defaults to default</dd>
+ Optional string, defaults to subject alternative name host verifier</dd>
<dt><strong>ssl.keystore</strong></dt>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 06/23: JAMES-3502,
update equals and hashCode methods on
RabbitMQConfiguration.SSLConfiguration
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 14a38d6b1c16d2e821ce253d13b4eda2c6187a9b
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Wed Feb 24 19:21:10 2021 +0200
JAMES-3502, update equals and hashCode methods on RabbitMQConfiguration.SSLConfiguration
---
.../java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 10bdca2..96957a0 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -266,6 +266,7 @@ public class RabbitMQConfiguration {
return Objects.equals(this.strategy, that.strategy)
&& Objects.equals(this.trustStore, that.trustStore)
+ && Objects.equals(this.keyStore, that.keyStore)
&& Objects.equals(this.hostNameVerifier, that.hostNameVerifier);
}
return false;
@@ -273,7 +274,7 @@ public class RabbitMQConfiguration {
@Override
public final int hashCode() {
- return Objects.hash(strategy, trustStore, hostNameVerifier);
+ return Objects.hash(strategy, trustStore, keyStore, hostNameVerifier);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 19/23: JAMES-3502, update ssl.keystore documentation
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 56800e8dc2d9396efa95e5b99f0969906afea6f6
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Thu Feb 25 11:56:07 2021 +0200
JAMES-3502, update ssl.keystore documentation
---
docs/modules/servers/pages/distributed/configure/rabbitmq.adoc | 2 +-
src/site/xdoc/server/config-rabbitmq.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
index 33f8d9b..3b29960 100644
--- a/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
+++ b/docs/modules/servers/pages/distributed/configure/rabbitmq.adoc
@@ -71,7 +71,7 @@ Optional string, defaults to empty string. "ssl.validation.strategy: override" m
Optional string, defaults to default
| ssl.keystore
-| Points to the keystore(PKCS12) used for verifying rabbitmq connection. If configured then "ssl.keystore.password" must also be configured,
+| Points to the keystore(PKCS12) used for client certificate authentication. If configured then "ssl.keystore.password" must also be configured,
Optional string, defaults to empty string
| ssl.keystore.password
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index d6e79b3..550f4ef 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -104,7 +104,7 @@
<dt><strong>ssl.keystore</strong></dt>
- <dd>Points to the keystore(PKCS12) used for verifying rabbitmq connection. If configured then "ssl.keystore.password" must also be configured,
+ <dd>Points to the keystore(PKCS12) used for client certificate authentication. If configured then "ssl.keystore.password" must also be configured,
Optional string, defaults to empty string</dd>
<dt><strong>ssl.keystore.password</strong></dt>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 21/23: JAMES-3502, remove duplicate line,
refactor method name
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 500d6b8a981c7a220a2b3c020f73a3c95215e8d3
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Mon Mar 1 14:54:17 2021 +0200
JAMES-3502, remove duplicate line, refactor method name
---
.../org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 0032770..458a768 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -498,8 +498,7 @@ public class RabbitMQConfiguration {
.managementCredentials(managementCredentials)
.useSsl(useSsl)
.useSslManagement(useSslForManagement)
- .sslConfiguration(sslTrustConfiguration(configuration))
- .sslConfiguration(sslTrustConfiguration(configuration))
+ .sslConfiguration(sslConfiguration(configuration))
.build();
}
@@ -511,7 +510,7 @@ public class RabbitMQConfiguration {
}
}
- private static SSLConfiguration sslTrustConfiguration(Configuration configuration) {
+ private static SSLConfiguration sslConfiguration(Configuration configuration) {
SSLValidationStrategy sslStrategy = Optional
.ofNullable(configuration.getString(SSL_VALIDATION_STRATEGY))
.map(SSLValidationStrategy::from)
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 09/23: JAMES-3502,
add ssl tests for RabbitMQConfiguration and
RabbitMqConnectionFactory
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 12d7bd7b4c8c2047ca02e2464ed453cbd72dda60
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Wed Feb 24 21:07:17 2021 +0200
JAMES-3502, add ssl tests for RabbitMQConfiguration and RabbitMqConnectionFactory
---
.../rabbitmq/RabbitMQConfigurationTest.java | 85 ++++++++++++++++
.../rabbitmq/RabbitMQConnectionFactoryTest.java | 113 +++++++++++++++++++++
.../rabbitmq/src/test/resources/empty-store | 0
.../test/resources/test-keystore-password-password | Bin 0 -> 2285 bytes
.../resources/test-truststore-password-password | Bin 0 -> 2285 bytes
5 files changed, 198 insertions(+)
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
index 84bb762..0d0535e 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
@@ -24,8 +24,11 @@ import static org.apache.james.backends.rabbitmq.RabbitMQFixture.DEFAULT_USER;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.io.File;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.junit.jupiter.api.Nested;
@@ -387,4 +390,86 @@ class RabbitMQConfigurationTest {
.isEqualTo(credentialWithUserAndPassword);
}
}
+
+ @Nested
+ class SSLConfigurationTest {
+
+ @Nested
+ class SSLValidationStrategyTest {
+
+ @Test
+ void fromShouldThrowExceptionWhenUnknownStrategyNameSupplied() {
+ assertThatThrownBy(() -> RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.from("random"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void fromShouldReturnWhenCorrectNamesAreUsed() {
+ assertThat(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.from("default"))
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.DEFAULT);
+
+ assertThat(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.from("override"))
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.OVERRIDE);
+
+ assertThat(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.from("ignore"))
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.IGNORE);
+ }
+
+ }
+
+ @Nested
+ class HostNameVerifierTest {
+
+ @Test
+ void fromShouldThrowExceptionWhenUnknownStrategyNameSupplied() {
+ assertThatThrownBy(() -> RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.from("random"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void fromShouldReturnWhenCorrectNamesAreUsed() {
+ assertThat(RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.from("default"))
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.DEFAULT);
+
+ assertThat(RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.from("accept_any_hostname"))
+ .isEqualTo(RabbitMQConfiguration.SSLConfiguration.HostNameVerifier.ACCEPT_ANY_HOSTNAME);
+
+ }
+
+ }
+
+ @Nested
+ class SSLTrustStore {
+
+ @Test
+ void ofShouldThrowExceptionWhenFilePathNotSupplied() {
+ assertThatThrownBy(() -> RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(null, "password"))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void ofShouldThrowExceptionWhenPasswordNotSupplied() {
+ assertThatThrownBy(() -> RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of("/path/to/file", null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void ofShouldThrowExceptionWhenFileDoesNotExist() {
+ assertThatThrownBy(() -> RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of("/does/not/exist", "password"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void ofShouldReturnWhenCorrectAttributesUsed() throws IOException {
+ File tempFile = File.createTempFile("for-james-test", "");
+ tempFile.deleteOnExit();
+
+ assertThat(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(tempFile.getAbsolutePath(), "password"))
+ .matches(sslTrustStore -> sslTrustStore.getFile().equals(tempFile))
+ .matches(sslTrustStore -> Arrays.equals(sslTrustStore.getPassword(), "password".toCharArray()));
+ }
+
+ }
+
+ }
}
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactoryTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactoryTest.java
index 052aa90..f5a7691 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactoryTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactoryTest.java
@@ -21,7 +21,10 @@ package org.apache.james.backends.rabbitmq;
import static org.apache.james.backends.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.io.IOException;
import java.net.URI;
+import java.nio.file.Paths;
+import java.util.Optional;
import org.junit.jupiter.api.Test;
@@ -38,6 +41,25 @@ class RabbitMQConnectionFactoryTest {
}
@Test
+ void creatingAFactoryShouldWorkWhenConfigurationIsValidWithSSl() {
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration = RabbitMQConfiguration.SSLConfiguration.builder()
+ .strategyOverride(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(Paths.get("src", "test", "resources", "test-truststore-password-password").toString(), "password"))
+ .defaultHostNameVerifier()
+ .sslKeyStore(Optional.of(RabbitMQConfiguration.SSLConfiguration.SSLKeyStore.of(Paths.get("src", "test", "resources", "test-keystore-password-password").toString(), "password")))
+ .build();
+
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .useSsl(true)
+ .sslConfiguration(sslConfiguration)
+ .build();
+
+ new RabbitMQConnectionFactory(rabbitMQConfiguration);
+ }
+
+ @Test
void creatingAFactoryShouldThrowWhenConfigurationIsInvalid() {
RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
.amqpUri(URI.create("badprotocol://james:james@rabbitmq_host:5672"))
@@ -64,4 +86,95 @@ class RabbitMQConnectionFactoryTest {
assertThatThrownBy(rabbitMQConnectionFactory::create)
.isInstanceOf(RuntimeException.class);
}
+
+ @Test
+ void creatingAFactoryShouldFailWhenTrustStoreFileisEmpty() {
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration = RabbitMQConfiguration.SSLConfiguration.builder()
+ .strategyOverride(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(Paths.get("src", "test", "resources", "empty-store").toString(), "password"))
+ .defaultHostNameVerifier()
+ .build();
+
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .maxRetries(1)
+ .minDelayInMs(1)
+ .useSsl(true)
+ .sslConfiguration(sslConfiguration)
+ .build();
+
+ assertThatThrownBy(() -> new RabbitMQConnectionFactory(rabbitMQConfiguration))
+ .isInstanceOf(RuntimeException.class)
+ .hasCause(new IOException("Short read of DER length"));
+ }
+
+ @Test
+ void creatingAFactoryShouldFailWhenTrustStorePasswordIsIncorrect() {
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration = RabbitMQConfiguration.SSLConfiguration.builder()
+ .strategyOverride(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(Paths.get("src", "test", "resources", "test-truststore-password-password").toString(), "wrong-password"))
+ .defaultHostNameVerifier()
+ .build();
+
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .maxRetries(1)
+ .minDelayInMs(1)
+ .useSsl(true)
+ .sslConfiguration(sslConfiguration)
+ .build();
+
+ assertThatThrownBy(() -> new RabbitMQConnectionFactory(rabbitMQConfiguration))
+ .isInstanceOf(RuntimeException.class)
+ .hasCause(new IOException("keystore password was incorrect"));
+ }
+
+ @Test
+ void creatingAFactoryShouldFailWhenKeyStoreIsEmpty() {
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration = RabbitMQConfiguration.SSLConfiguration.builder()
+ .strategyOverride(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(Paths.get("src", "test", "resources", "test-truststore-password-password").toString(), "password"))
+ .defaultHostNameVerifier()
+ .sslKeyStore(Optional.of(RabbitMQConfiguration.SSLConfiguration.SSLKeyStore.of(Paths.get("src", "test", "resources", "empty-store").toString(), "password")))
+ .build();
+
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .maxRetries(1)
+ .minDelayInMs(1)
+ .useSsl(true)
+ .sslConfiguration(sslConfiguration)
+ .build();
+
+ assertThatThrownBy(() -> new RabbitMQConnectionFactory(rabbitMQConfiguration))
+ .isInstanceOf(RuntimeException.class)
+ .hasCause(new IOException("Short read of DER length"));
+ }
+
+ @Test
+ void creatingAFactoryShouldFailWhenKeyStorePasswordIsIncorrect() {
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration = RabbitMQConfiguration.SSLConfiguration.builder()
+ .strategyOverride(RabbitMQConfiguration.SSLConfiguration.SSLTrustStore.of(Paths.get("src", "test", "resources", "test-truststore-password-password").toString(), "password"))
+ .defaultHostNameVerifier()
+ .sslKeyStore(Optional.of(RabbitMQConfiguration.SSLConfiguration.SSLKeyStore.of(Paths.get("src", "test", "resources", "test-keystore-password-password").toString(), "wrong-password")))
+ .build();
+
+ RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
+ .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
+ .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+ .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
+ .maxRetries(1)
+ .minDelayInMs(1)
+ .useSsl(true)
+ .sslConfiguration(sslConfiguration)
+ .build();
+
+ assertThatThrownBy(() -> new RabbitMQConnectionFactory(rabbitMQConfiguration))
+ .isInstanceOf(RuntimeException.class)
+ .hasCause(new IOException("keystore password was incorrect"));
+ }
+
}
diff --git a/backends-common/rabbitmq/src/test/resources/empty-store b/backends-common/rabbitmq/src/test/resources/empty-store
new file mode 100644
index 0000000..e69de29
diff --git a/backends-common/rabbitmq/src/test/resources/test-keystore-password-password b/backends-common/rabbitmq/src/test/resources/test-keystore-password-password
new file mode 100644
index 0000000..4b1e25e
Binary files /dev/null and b/backends-common/rabbitmq/src/test/resources/test-keystore-password-password differ
diff --git a/backends-common/rabbitmq/src/test/resources/test-truststore-password-password b/backends-common/rabbitmq/src/test/resources/test-truststore-password-password
new file mode 100644
index 0000000..4b1e25e
Binary files /dev/null and b/backends-common/rabbitmq/src/test/resources/test-truststore-password-password differ
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 05/23: JAMES-3502,
update equals and hashCode methods on RabbitMQConfiguration.java
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 9a7bb03f7e66504a0278d2ab3146b5fe1d155b81
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Wed Feb 24 19:19:11 2021 +0200
JAMES-3502, update equals and hashCode methods on RabbitMQConfiguration.java
---
.../org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index e2de540..10bdca2 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -625,7 +625,9 @@ public class RabbitMQConfiguration {
&& Objects.equals(this.handshakeTimeoutInMs, that.handshakeTimeoutInMs)
&& Objects.equals(this.shutdownTimeoutInMs, that.shutdownTimeoutInMs)
&& Objects.equals(this.networkRecoveryIntervalInMs, that.networkRecoveryIntervalInMs)
- && Objects.equals(this.managementCredentials, that.managementCredentials
+ && Objects.equals(this.managementCredentials, that.managementCredentials)
+ && Objects.equals(this.useSsl, that.useSsl)
+ && Objects.equals(this.sslConfiguration, that.sslConfiguration
);
}
return false;
@@ -634,6 +636,6 @@ public class RabbitMQConfiguration {
@Override
public final int hashCode() {
return Objects.hash(uri, managementUri, maxRetries, minDelayInMs, connectionTimeoutInMs,
- channelRpcTimeoutInMs, handshakeTimeoutInMs, shutdownTimeoutInMs, networkRecoveryIntervalInMs, managementCredentials);
+ channelRpcTimeoutInMs, handshakeTimeoutInMs, shutdownTimeoutInMs, networkRecoveryIntervalInMs, managementCredentials, useSsl, sslConfiguration);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 03/23: JAMES-3502, add rabbitmq tls support
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 92b283d5053caf83d1bd924cdb0137774688b4b3
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Tue Feb 23 19:26:38 2021 +0200
JAMES-3502, add rabbitmq tls support
---
.../backends/rabbitmq/RabbitMQConfiguration.java | 335 ++++++++++++++++++++-
1 file changed, 333 insertions(+), 2 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 39b3be5..e2de540 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -18,18 +18,275 @@
****************************************************************/
package org.apache.james.backends.rabbitmq;
+import java.io.File;
import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
+import java.util.stream.Stream;
import org.apache.commons.configuration2.Configuration;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.*;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.SSLValidationStrategy.*;
+
public class RabbitMQConfiguration {
+ public static class SSLConfiguration {
+
+ public enum SSLValidationStrategy {
+ DEFAULT,
+ IGNORE,
+ OVERRIDE;
+
+ static SSLValidationStrategy from(String rawValue) {
+ Preconditions.checkNotNull(rawValue);
+
+ return Stream.of(values())
+ .filter(strategy -> strategy.name().equalsIgnoreCase(rawValue))
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException(String.format("invalid strategy '%s'", rawValue)));
+
+ }
+ }
+
+ public enum HostNameVerifier {
+ DEFAULT,
+ ACCEPT_ANY_HOSTNAME;
+
+ static HostNameVerifier from(String rawValue) {
+ Preconditions.checkNotNull(rawValue);
+
+ return Stream.of(values())
+ .filter(verifier -> verifier.name().equalsIgnoreCase(rawValue))
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException(String.format("invalid HostNameVerifier '%s'", rawValue)));
+
+ }
+ }
+
+ public static class SSLKeyStore {
+
+ public static SSLKeyStore of(String filePath, String password) {
+ return new SSLKeyStore(filePath, password);
+ }
+
+ private final File file;
+ private final char[] password;
+
+ private SSLKeyStore(String filePath, String password) {
+ Preconditions.checkNotNull(filePath, "%s cannot be null when %s is specified",
+ SSL_KEY_STORE_PATH, SSL_KEY_STORE_PASSWORD);
+ Preconditions.checkNotNull(password,
+ "%s cannot be null when %s is specified",
+ SSL_KEY_STORE_PASSWORD, SSL_KEY_STORE_PATH);
+ Preconditions.checkArgument(Files.exists(Paths.get(filePath)),
+ "the file '%s' from property '%s' doesn't exist", filePath, SSL_KEY_STORE_PATH);
+
+ this.file = new File(filePath);
+ this.password = password.toCharArray();
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public char[] getPassword() {
+ return password;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof SSLKeyStore) {
+ SSLKeyStore that = (SSLKeyStore) o;
+
+ return Objects.equals(this.file, that.file)
+ && Arrays.equals(this.password, that.password);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(file, Arrays.hashCode(password));
+ }
+ }
+
+
+ public static class SSLTrustStore {
+
+ public static SSLTrustStore of(String filePath, String password) {
+ return new SSLTrustStore(filePath, password);
+ }
+
+ private final File file;
+ private final char[] password;
+
+ private SSLTrustStore(String filePath, String password) {
+ Preconditions.checkNotNull(filePath, "%s cannot be null when %s is specified",
+ SSL_TRUST_STORE_PATH, SSL_TRUST_STORE_PASSWORD);
+ Preconditions.checkNotNull(password,
+ "%s cannot be null when %s is specified",
+ SSL_TRUST_STORE_PASSWORD, SSL_TRUST_STORE_PATH);
+ Preconditions.checkArgument(Files.exists(Paths.get(filePath)),
+ "the file '%s' from property '%s' doesn't exist", filePath, SSL_TRUST_STORE_PATH);
+
+ this.file = new File(filePath);
+ this.password = password.toCharArray();
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public char[] getPassword() {
+ return password;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof SSLTrustStore) {
+ SSLTrustStore that = (SSLTrustStore) o;
+
+ return Objects.equals(this.file, that.file)
+ && Arrays.equals(this.password, that.password);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(file, Arrays.hashCode(password));
+ }
+ }
+
+ static class Builder {
+
+ interface RequireSSLStrategyTrustStore {
+ RequireHostNameVerifier sslStrategy(SSLValidationStrategy strategy, Optional<SSLTrustStore> trustStore);
+
+ default RequireHostNameVerifier strategyIgnore() {
+ return sslStrategy(SSLValidationStrategy.IGNORE, Optional.empty());
+ }
+
+ default RequireHostNameVerifier strategyOverride(SSLTrustStore trustStore) {
+ return sslStrategy(OVERRIDE, Optional.of(trustStore));
+ }
+
+ default RequireHostNameVerifier strategyDefault() {
+ return sslStrategy(SSLValidationStrategy.DEFAULT, Optional.empty());
+ }
+ }
+
+ interface RequireHostNameVerifier {
+ ReadyToBuild hostNameVerifier(HostNameVerifier hostNameVerifier);
+
+ default ReadyToBuild acceptAnyHostNameVerifier() {
+ return hostNameVerifier(HostNameVerifier.ACCEPT_ANY_HOSTNAME);
+ }
+
+ default ReadyToBuild defaultHostNameVerifier() {
+ return hostNameVerifier(HostNameVerifier.DEFAULT);
+ }
+ }
+
+ static class ReadyToBuild {
+ private final SSLValidationStrategy sslValidationStrategy;
+ private final HostNameVerifier hostNameVerifier;
+ private Optional<SSLTrustStore> sslTrustStore;
+ private Optional<SSLKeyStore> sslKeyStore;
+
+ private ReadyToBuild(SSLValidationStrategy sslValidationStrategy, HostNameVerifier hostNameVerifier, Optional<SSLTrustStore> sslTrustStore) {
+ this.sslValidationStrategy = sslValidationStrategy;
+ this.hostNameVerifier = hostNameVerifier;
+ this.sslTrustStore = sslTrustStore;
+ }
+
+ public ReadyToBuild sslKeyStore(Optional<SSLKeyStore> sslKeyStore) {
+ this.sslKeyStore = sslKeyStore;
+ return this;
+ }
+
+ public SSLConfiguration build() {
+ return new SSLConfiguration(sslValidationStrategy, hostNameVerifier, sslTrustStore, sslKeyStore);
+ }
+ }
+ }
+
+ static SSLConfiguration defaultBehavior() {
+ return new SSLConfiguration(SSLValidationStrategy.DEFAULT, HostNameVerifier.DEFAULT, Optional.empty(), Optional.empty());
+ }
+
+ static Builder.RequireSSLStrategyTrustStore builder() {
+ return (strategy, trustStore) -> hostNameVerifier -> new Builder.ReadyToBuild(strategy, hostNameVerifier, trustStore);
+ }
+
+ private final SSLValidationStrategy strategy;
+ private final HostNameVerifier hostNameVerifier;
+ private final Optional<SSLTrustStore> trustStore;
+ private final Optional<SSLKeyStore> keyStore;
+
+ private SSLConfiguration(SSLValidationStrategy strategy, HostNameVerifier hostNameVerifier, Optional<SSLTrustStore> trustStore, Optional<SSLKeyStore> keyStore) {
+ Preconditions.checkNotNull(strategy);
+ Preconditions.checkNotNull(trustStore);
+ Preconditions.checkNotNull(hostNameVerifier);
+ Preconditions.checkArgument(strategy != OVERRIDE || trustStore.isPresent(), "%s strategy requires trustStore to be present", OVERRIDE.name());
+
+ this.strategy = strategy;
+ this.trustStore = trustStore;
+ this.keyStore = keyStore;
+ this.hostNameVerifier = hostNameVerifier;
+ }
+
+ public SSLValidationStrategy getStrategy() {
+ return strategy;
+ }
+
+ public Optional<SSLTrustStore> getTrustStore() {
+ return trustStore;
+ }
+
+ public Optional<SSLKeyStore> getKeyStore() {
+ return keyStore;
+ }
+
+ public HostNameVerifier getHostNameVerifier() {
+ return hostNameVerifier;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof SSLConfiguration) {
+ SSLConfiguration that = (SSLConfiguration) o;
+
+ return Objects.equals(this.strategy, that.strategy)
+ && Objects.equals(this.trustStore, that.trustStore)
+ && Objects.equals(this.hostNameVerifier, that.hostNameVerifier);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(strategy, trustStore, hostNameVerifier);
+ }
+ }
+
+ private static String USE_SSL = "ssl.enabled";
+
+ private static String SSL_TRUST_STORE_PATH = "ssl.truststore";
+ private static String SSL_TRUST_STORE_PASSWORD = "ssl.truststore.password";
+ private static String SSL_VALIDATION_STRATEGY = "ssl.validation.strategy";
+ private static String SSL_HOSTNAME_VERIFIER = "ssl.hostname.verifier";
+
+ private static String SSL_KEY_STORE_PATH = "ssl.keystore";
+ private static String SSL_KEY_STORE_PASSWORD = "ssl.keystore.password";
+
public static class ManagementCredentials {
static ManagementCredentials from(Configuration configuration) {
@@ -114,6 +371,8 @@ public class RabbitMQConfiguration {
private Optional<Integer> handshakeTimeoutInMs;
private Optional<Integer> shutdownTimeoutInMs;
private Optional<Integer> networkRecoveryIntervalInMs;
+ private Optional<Boolean> useSsl;
+ private Optional<SSLConfiguration> sslConfiguration;
private Builder(URI amqpUri, URI managementUri, ManagementCredentials managementCredentials) {
this.amqpUri = amqpUri;
@@ -126,6 +385,8 @@ public class RabbitMQConfiguration {
this.handshakeTimeoutInMs = Optional.empty();
this.shutdownTimeoutInMs = Optional.empty();
this.networkRecoveryIntervalInMs = Optional.empty();
+ this.useSsl = Optional.empty();
+ this.sslConfiguration = Optional.empty();
}
public Builder maxRetries(int maxRetries) {
@@ -163,6 +424,16 @@ public class RabbitMQConfiguration {
return this;
}
+ public Builder useSsl(Boolean useSsl) {
+ this.useSsl = Optional.ofNullable(useSsl);
+ return this;
+ }
+
+ public Builder sslConfiguration(SSLConfiguration sslConfiguration) {
+ this.sslConfiguration = Optional.of(sslConfiguration);
+ return this;
+ }
+
public RabbitMQConfiguration build() {
Preconditions.checkNotNull(amqpUri, "'amqpUri' should not be null");
Preconditions.checkNotNull(managementUri, "'managementUri' should not be null");
@@ -176,9 +447,12 @@ public class RabbitMQConfiguration {
channelRpcTimeoutInMs.orElse(DEFAULT_CHANNEL_RPC_TIMEOUT),
handshakeTimeoutInMs.orElse(DEFAULT_HANDSHAKE_TIMEOUT),
shutdownTimeoutInMs.orElse(DEFAULT_SHUTDOWN_TIMEOUT),
- networkRecoveryIntervalInMs.orElse(DEFAULT_NETWORK_RECOVERY_INTERVAL)
+ networkRecoveryIntervalInMs.orElse(DEFAULT_NETWORK_RECOVERY_INTERVAL),
+ useSsl.orElse(false),
+ sslConfiguration.orElse(defaultBehavior())
);
}
+
}
private static final String URI_PROPERTY_NAME = "uri";
@@ -197,11 +471,16 @@ public class RabbitMQConfiguration {
Preconditions.checkState(!Strings.isNullOrEmpty(managementUriAsString), "You need to specify the management URI of RabbitMQ");
URI managementUri = checkURI(managementUriAsString);
+ Boolean useSsl = configuration.getBoolean(USE_SSL, false);
+
ManagementCredentials managementCredentials = ManagementCredentials.from(configuration);
return builder()
.amqpUri(amqpUri)
.managementUri(managementUri)
.managementCredentials(managementCredentials)
+ .useSsl(useSsl)
+ .sslConfiguration(sslTrustConfiguration(configuration))
+ .sslConfiguration(sslTrustConfiguration(configuration))
.build();
}
@@ -213,6 +492,46 @@ public class RabbitMQConfiguration {
}
}
+ private static SSLConfiguration sslTrustConfiguration(Configuration configuration) {
+ SSLValidationStrategy sslStrategy = Optional
+ .ofNullable(configuration.getString(SSL_VALIDATION_STRATEGY))
+ .map(SSLValidationStrategy::from)
+ .orElse(SSLValidationStrategy.DEFAULT);
+
+ HostNameVerifier hostNameVerifier = Optional
+ .ofNullable(configuration.getString(SSL_HOSTNAME_VERIFIER))
+ .map(HostNameVerifier::from)
+ .orElse(HostNameVerifier.DEFAULT);
+
+ return SSLConfiguration.builder()
+ .sslStrategy(sslStrategy, getSSLTrustStore(configuration))
+ .hostNameVerifier(hostNameVerifier)
+ .sslKeyStore(getSSLKeyStore(configuration))
+ .build();
+ }
+
+ private static Optional<SSLTrustStore> getSSLTrustStore(Configuration configuration) {
+ String trustStorePath = configuration.getString(SSL_TRUST_STORE_PATH);
+ String trustStorePassword = configuration.getString(SSL_TRUST_STORE_PASSWORD);
+
+ if (trustStorePath == null && trustStorePassword == null) {
+ return Optional.empty();
+ }
+
+ return Optional.of(SSLTrustStore.of(trustStorePath, trustStorePassword));
+ }
+
+ private static Optional<SSLKeyStore> getSSLKeyStore(Configuration configuration) {
+ String keyStorePath = configuration.getString(SSL_KEY_STORE_PATH);
+ String keyStorePassword = configuration.getString(SSL_KEY_STORE_PASSWORD);
+
+ if (keyStorePath == null && keyStorePassword == null) {
+ return Optional.empty();
+ }
+
+ return Optional.of(SSLKeyStore.of(keyStorePath, keyStorePassword));
+ }
+
private final URI uri;
private final URI managementUri;
private final int maxRetries;
@@ -222,12 +541,14 @@ public class RabbitMQConfiguration {
private final int handshakeTimeoutInMs;
private final int shutdownTimeoutInMs;
private final int networkRecoveryIntervalInMs;
+ private final Boolean useSsl;
+ private final SSLConfiguration sslConfiguration;
private final ManagementCredentials managementCredentials;
private RabbitMQConfiguration(URI uri, URI managementUri, ManagementCredentials managementCredentials, int maxRetries, int minDelayInMs,
- int connectionTimeoutInMs, int channelRpcTimeoutInMs, int handshakeTimeoutInMs, int shutdownTimeoutInMs, int networkRecoveryIntervalInMs) {
+ int connectionTimeoutInMs, int channelRpcTimeoutInMs, int handshakeTimeoutInMs, int shutdownTimeoutInMs, int networkRecoveryIntervalInMs, Boolean useSsl, SSLConfiguration sslConfiguration) {
this.uri = uri;
this.managementUri = managementUri;
this.managementCredentials = managementCredentials;
@@ -238,6 +559,8 @@ public class RabbitMQConfiguration {
this.handshakeTimeoutInMs = handshakeTimeoutInMs;
this.shutdownTimeoutInMs = shutdownTimeoutInMs;
this.networkRecoveryIntervalInMs = networkRecoveryIntervalInMs;
+ this.useSsl = useSsl;
+ this.sslConfiguration = sslConfiguration;
}
public URI getUri() {
@@ -280,6 +603,14 @@ public class RabbitMQConfiguration {
return managementCredentials;
}
+ public Boolean useSsl() {
+ return useSsl;
+ }
+
+ public SSLConfiguration getSslConfiguration() {
+ return sslConfiguration;
+ }
+
@Override
public final boolean equals(Object o) {
if (o instanceof RabbitMQConfiguration) {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[james-project] 04/23: JAMES-3502,
add rabbitmq tls support in connection factory
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4547fd9847eecee5a59a11fa496c2a715cc012a6
Author: andreasvaldma <andreas.valdmanortal.com>
AuthorDate: Tue Feb 23 19:26:58 2021 +0200
JAMES-3502, add rabbitmq tls support in connection factory
---
backends-common/rabbitmq/pom.xml | 5 ++
.../rabbitmq/RabbitMQConnectionFactory.java | 90 +++++++++++++++++++++-
2 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml
index 1bfe6ba..99a0507 100644
--- a/backends-common/rabbitmq/pom.xml
+++ b/backends-common/rabbitmq/pom.xml
@@ -94,6 +94,11 @@
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>4.4.5</version>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
index cb45fc7..83dee07 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConnectionFactory.java
@@ -18,27 +18,42 @@
****************************************************************/
package org.apache.james.backends.rabbitmq;
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
import java.time.Duration;
+import java.util.Optional;
import javax.inject.Inject;
+import javax.net.ssl.SSLContext;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.ssl.TrustStrategy;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.util.retry.Retry;
+import static org.apache.james.backends.rabbitmq.RabbitMQConfiguration.SSLConfiguration.*;
+
public class RabbitMQConnectionFactory {
+ private static final TrustStrategy TRUST_ALL = (x509Certificates, authType) -> true;
+
private final ConnectionFactory connectionFactory;
private final RabbitMQConfiguration configuration;
@Inject
public RabbitMQConnectionFactory(RabbitMQConfiguration rabbitMQConfiguration) {
- this.connectionFactory = from(rabbitMQConfiguration);
this.configuration = rabbitMQConfiguration;
+ this.connectionFactory = from(rabbitMQConfiguration);
}
private ConnectionFactory from(RabbitMQConfiguration rabbitMQConfiguration) {
@@ -54,18 +69,89 @@ public class RabbitMQConnectionFactory {
connectionFactory.setUsername(rabbitMQConfiguration.getManagementCredentials().getUser());
connectionFactory.setPassword(String.valueOf(rabbitMQConfiguration.getManagementCredentials().getPassword()));
+ if (configuration.useSsl()) setupSslConfiguration(connectionFactory);
+
return connectionFactory;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+ private void setupSslConfiguration(ConnectionFactory connectionFactory) {
+ try {
+ connectionFactory.useSslProtocol(sslContext(configuration));
+ setupHostNameVerification(connectionFactory);
+ } catch (KeyManagementException | NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | UnrecoverableKeyException e) {
+ throw new RuntimeException("Cannot set SSL options to the connection factory", e);
+ }
+ }
+
+ private SSLContext sslContext(RabbitMQConfiguration configuration) throws KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException {
+ SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
+
+ RabbitMQConfiguration.SSLConfiguration sslConfiguration = configuration.getSslConfiguration();
+
+ setupSslValidationStrategy(sslContextBuilder, sslConfiguration);
+
+ setupClientCertificateAuthentication(sslContextBuilder, sslConfiguration);
+
+ return sslContextBuilder.build();
+
+ }
+
+ private void setupClientCertificateAuthentication(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration.SSLConfiguration sslConfiguration) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
+ Optional<SSLKeyStore> keyStore = sslConfiguration.getKeyStore();
+
+ if (keyStore.isPresent()) {
+ SSLKeyStore sslKeyStore = keyStore.get();
+
+ sslContextBuilder.loadKeyMaterial(sslKeyStore.getFile(), sslKeyStore.getPassword(), null);
+ }
+ }
+
+ private void setupSslValidationStrategy(SSLContextBuilder sslContextBuilder, RabbitMQConfiguration.SSLConfiguration sslConfiguration) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
+ SSLValidationStrategy strategy = sslConfiguration
+ .getStrategy();
+
+ switch (strategy) {
+ case DEFAULT:
+ break;
+ case IGNORE:
+ sslContextBuilder.loadTrustMaterial(TRUST_ALL);
+ break;
+ case OVERRIDE:
+ applyTrustStore(sslContextBuilder);
+ break;
+ default:
+ throw new NotImplementedException(
+ String.format("unrecognized strategy '%s'", strategy.name()));
+ }
+ }
+
+ private SSLContextBuilder applyTrustStore(SSLContextBuilder sslContextBuilder) throws CertificateException, NoSuchAlgorithmException,
+ KeyStoreException, IOException {
+
+ SSLTrustStore trustStore = configuration.getSslConfiguration()
+ .getTrustStore()
+ .orElseThrow(() -> new IllegalStateException("SSLTrustStore cannot to be empty"));
+
+ return sslContextBuilder
+ .loadTrustMaterial(trustStore.getFile(), trustStore.getPassword());
+ }
+
+ private void setupHostNameVerification(ConnectionFactory connectionFactory) {
+ HostNameVerifier hostNameVerifier = configuration.getSslConfiguration()
+ .getHostNameVerifier();
+
+ if (hostNameVerifier == HostNameVerifier.DEFAULT) connectionFactory.enableHostnameVerification();
+ }
+
Connection create() {
return connectionMono().block();
}
Mono<Connection> connectionMono() {
return Mono.fromCallable(connectionFactory::newConnection)
- .retryWhen(Retry.backoff(configuration.getMaxRetries(), Duration.ofMillis(configuration.getMinDelayInMs())).scheduler(Schedulers.elastic()));
+ .retryWhen(Retry.backoff(configuration.getMaxRetries(), Duration.ofMillis(configuration.getMinDelayInMs())).scheduler(Schedulers.elastic()));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org