You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2019/06/26 10:22:19 UTC

[james-project] branch master updated (581b64b -> 6861d2a)

This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 581b64b  JAMES-2774 log when fail to dispatch in EventDispatcher
     new bb1fd29  JAMES-1975 Add DKIM integration test
     new 6861d2a  JAMES-1975 Inject PublicKeyRecordRetriever for DKIMVerify mailet

The 2 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:
 .../org/apache/james/CassandraJamesServerMain.java |   4 +-
 .../java/org/apache/james/JPAJamesServerMain.java  |   4 +-
 .../java/org/apache/james/JPAJamesServerMain.java  |   3 +-
 server/container/guice/mailet/pom.xml              |   4 +
 .../james/modules/server/DKIMMailetModule.java}    |  15 +-
 server/container/guice/memory-guice/pom.xml        |   8 +-
 .../org/apache/james/MemoryJamesServerMain.java    |   4 +-
 .../org/apache/james/jdkim/mailets/DKIMVerify.java |  30 ++--
 .../mailets/MockPublicKeyRecordRetriever.java      |  57 ++++++++
 .../apache/james/jdkim/mailets/DKIMSignTest.java   |   1 -
 .../apache/james/jdkim/mailets/DKIMVerifyTest.java |  13 +-
 server/mailet/integration-testing/pom.xml          |   4 +
 .../apache/james/mailets/DKIMIntegrationTest.java  | 161 +++++++++++++++++++++
 .../transport/mailets/ExtractAttributeStub.java    |  36 +++--
 14 files changed, 287 insertions(+), 57 deletions(-)
 copy server/container/guice/{guice-common/src/main/java/org/apache/james/modules/server/RawPostDequeueDecoratorModule.java => mailet/src/main/java/org/apache/james/modules/server/DKIMMailetModule.java} (75%)
 create mode 100644 server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/MockPublicKeyRecordRetriever.java
 create mode 100644 server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java
 copy mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java => server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ExtractAttributeStub.java (70%)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 01/02: JAMES-1975 Add DKIM integration test

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit bb1fd290fa100bf733539effdca051057a10305f
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Fri May 17 08:21:09 2019 +0200

    JAMES-1975 Add DKIM integration test
---
 pom.xml                                            |   5 +
 server/container/guice/cassandra-guice/pom.xml     |   4 +
 .../org/apache/james/CassandraJamesServerMain.java |   4 +-
 server/container/guice/jpa-guice/pom.xml           |   4 +
 .../java/org/apache/james/JPAJamesServerMain.java  |   4 +-
 server/container/guice/jpa-smtp-common/pom.xml     |   4 +
 .../java/org/apache/james/JPAJamesServerMain.java  |   3 +-
 server/container/guice/memory-guice/pom.xml        |  12 +-
 .../org/apache/james/MemoryJamesServerMain.java    |   4 +-
 .../apache/james/mailets/DKIMIntegrationTest.java  | 159 +++++++++++++++++++++
 .../transport/mailets/ExtractAttributeStub.java    |  50 +++++++
 server/mailet/mailets-guice/pom.xml                |  47 ++++++
 .../configuration/MailetsConfigurationModule.java  |  33 +++++
 server/pom.xml                                     |   1 +
 14 files changed, 326 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 670f5c2..eda4654 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1560,6 +1560,11 @@
             </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
+                <artifactId>james-server-mailets-guice</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
                 <artifactId>james-server-memory-guice</artifactId>
                 <version>${project.version}</version>
             </dependency>
diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml
index 206e9bd..cbbddc0 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -83,6 +83,10 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailets-guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mailbox-quota-search-elasticsearch</artifactId>
         </dependency>
         <dependency>
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index d7f5ddd..ddab14f 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -19,6 +19,7 @@
 
 package org.apache.james;
 
+import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.BlobExportMechanismModule;
 import org.apache.james.modules.MailboxModule;
 import org.apache.james.modules.activemq.ActiveMQQueueModule;
@@ -131,7 +132,8 @@ public class CassandraJamesServerMain {
         CASSANDRA_SERVER_CORE_MODULE,
         CASSANDRA_MAILBOX_MODULE,
         PROTOCOLS,
-        PLUGINS);
+        PLUGINS,
+        new MailetsConfigurationModule());
 
     public static void main(String[] args) throws Exception {
         Configuration configuration = Configuration.builder()
diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml
index 0340513..d10f37a 100644
--- a/server/container/guice/jpa-guice/pom.xml
+++ b/server/container/guice/jpa-guice/pom.xml
@@ -147,6 +147,10 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailets-guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-testing</artifactId>
             <scope>test</scope>
         </dependency>
diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
index 30a6322..b036a22 100644
--- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -19,6 +19,7 @@
 
 package org.apache.james;
 
+import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.MailboxModule;
 import org.apache.james.modules.activemq.ActiveMQQueueModule;
 import org.apache.james.modules.data.JPADataModule;
@@ -95,7 +96,8 @@ public class JPAJamesServerMain {
 
         GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
                     .combineWith(JPA_MODULE_AGGREGATE,
-                            new JMXServerModule());
+                            new JMXServerModule(),
+                            new MailetsConfigurationModule());
         server.start();
     }
 
diff --git a/server/container/guice/jpa-smtp-common/pom.xml b/server/container/guice/jpa-smtp-common/pom.xml
index 522f208..a4e6dc0 100644
--- a/server/container/guice/jpa-smtp-common/pom.xml
+++ b/server/container/guice/jpa-smtp-common/pom.xml
@@ -74,6 +74,10 @@
             <artifactId>james-server-jpa-common-guice</artifactId>
         </dependency>
         <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailets-guice</artifactId>
+        </dependency>
+        <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
         </dependency>
diff --git a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
index 3fd88a9..d2238d1 100644
--- a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -19,6 +19,7 @@
 
 package org.apache.james;
 
+import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.activemq.ActiveMQQueueModule;
 import org.apache.james.modules.data.JPADataModule;
 import org.apache.james.modules.data.JPAEntityManagerModule;
@@ -62,7 +63,7 @@ public class JPAJamesServerMain {
             .build();
 
         GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
-                    .combineWith(JPA_SERVER_MODULE, PROTOCOLS);
+                    .combineWith(JPA_SERVER_MODULE, PROTOCOLS, new MailetsConfigurationModule());
         server.start();
     }
 
diff --git a/server/container/guice/memory-guice/pom.xml b/server/container/guice/memory-guice/pom.xml
index c69c31f..a3a9fb8 100644
--- a/server/container/guice/memory-guice/pom.xml
+++ b/server/container/guice/memory-guice/pom.xml
@@ -98,10 +98,6 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-mailbox-plugin-deleted-messages-vault-guice</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-guice-common</artifactId>
         </dependency>
         <dependency>
@@ -174,6 +170,14 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailbox-plugin-deleted-messages-vault-guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailets-guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-mailrepository-memory</artifactId>
         </dependency>
         <dependency>
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
index 18f4394..73d33d2 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.jwt.JwtConfiguration;
+import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.BlobExportMechanismModule;
 import org.apache.james.modules.BlobMemoryModule;
 import org.apache.james.modules.MailboxModule;
@@ -123,7 +124,8 @@ public class MemoryJamesServerMain {
         IN_MEMORY_SERVER_MODULE,
         PROTOCOLS,
         JMAP,
-        WEBADMIN);
+        WEBADMIN,
+        new MailetsConfigurationModule());
 
     public static void main(String[] args) throws Exception {
         Configuration configuration = Configuration.builder()
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java
new file mode 100644
index 0000000..79bb150
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java
@@ -0,0 +1,159 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailets;
+
+import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
+import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.jdkim.MockPublicKeyRecordRetriever;
+import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
+import org.apache.james.jdkim.mailets.DKIMSign;
+import org.apache.james.jdkim.mailets.DKIMVerify;
+import org.apache.james.mailets.configuration.CommonProcessors;
+import org.apache.james.mailets.configuration.MailetConfiguration;
+import org.apache.james.mailets.configuration.MailetContainer;
+import org.apache.james.mailets.configuration.ProcessorConfiguration;
+import org.apache.james.modules.protocols.ImapGuiceProbe;
+import org.apache.james.modules.protocols.SmtpGuiceProbe;
+import org.apache.james.probe.DataProbe;
+import org.apache.james.transport.mailets.ExtractAttributeStub;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+
+public class DKIMIntegrationTest {
+
+    private static final String FROM_LOCAL_PART = "fromUser";
+    private static final String FROM = FROM_LOCAL_PART + "@" + DEFAULT_DOMAIN;
+    private static final String RECIPIENT_LOCAL_PART = "touser";
+    private static final String RECIPIENT = RECIPIENT_LOCAL_PART + "@" + DEFAULT_DOMAIN;
+
+    private static final String TESTING_PEM = "-----BEGIN RSA PRIVATE KEY-----\r\n" +
+            "MIICXAIBAAKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoT\r\n" +
+            "M5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRH\r\n" +
+            "r7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB\r\n" +
+            "AoGBAI8XcwnZi0Sq5N89wF+gFNhnREFo3rsJDaCY8iqHdA5DDlnr3abb/yhipw0I\r\n" +
+            "/1HlgC6fIG2oexXOXFWl+USgqRt1kTt9jXhVFExg8mNko2UelAwFtsl8CRjVcYQO\r\n" +
+            "cedeH/WM/mXjg2wUqqZenBmlKlD6vNb70jFJeVaDJ/7n7j8BAkEA9NkH2D4Zgj/I\r\n" +
+            "OAVYccZYH74+VgO0e7VkUjQk9wtJ2j6cGqJ6Pfj0roVIMUWzoBb8YfErR8l6JnVQ\r\n" +
+            "bfy83gJeiQJBAOHk3ow7JjAn8XuOyZx24KcTaYWKUkAQfRWYDFFOYQF4KV9xLSEt\r\n" +
+            "ycY0kjsdxGKDudWcsATllFzXDCQF6DTNIWECQEA52ePwTjKrVnLTfCLEG4OgHKvl\r\n" +
+            "Zud4amthwDyJWoMEH2ChNB2je1N4JLrABOE+hk+OuoKnKAKEjWd8f3Jg/rkCQHj8\r\n" +
+            "mQmogHqYWikgP/FSZl518jV48Tao3iXbqvU9Mo2T6yzYNCCqIoDLFWseNVnCTZ0Q\r\n" +
+            "b+IfiEf1UeZVV5o4J+ECQDatNnS3V9qYUKjj/krNRD/U0+7eh8S2ylLqD3RlSn9K\r\n" +
+            "tYGRMgAtUXtiOEizBH6bd/orzI9V9sw8yBz+ZqIH25Q=\r\n" +
+            "-----END RSA PRIVATE KEY-----\r\n";
+    private static final MailetConfiguration DKIMSIGN_MAILET = MailetConfiguration.builder()
+            .matcher(All.class)
+            .mailet(DKIMSign.class)
+            .addProperty(
+                    "signatureTemplate",
+                    "v=1; s=selector; d=example.com; h=from:to:received:received; a=rsa-sha256; bh=; b=;")
+            .addProperty("privateKey", TESTING_PEM)
+            .build();
+    private static final MailetConfiguration DKIMVERIFY_MAILET = MailetConfiguration.builder()
+            .matcher(All.class)
+            .mailet(DKIMVerify.class)
+            .build();
+    private static final MailetConfiguration STUB_MAILET = MailetConfiguration.builder()
+        .matcher(All.class)
+        .mailet(ExtractAttributeStub.class)
+        .addProperty("attributeName", DKIMVerify.DKIM_AUTH_RESULT.asString())
+        .build();
+
+    private static final PublicKeyRecordRetriever MOCK_PUBLIC_KEY_RECORD_RETRIEVER = new MockPublicKeyRecordRetriever(
+            "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoTM5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRHr7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB;",
+            "selector", "example.com");
+
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
+
+    private TemporaryJamesServer jamesServer;
+    private DataProbe dataProbe;
+    private List<Optional<String>> dkimAuthResults;
+
+    @Before
+    public void setup() throws Exception {
+        dkimAuthResults = new ArrayList<>();
+        ExtractAttributeStub.setDkimAuthResultInspector(value -> dkimAuthResults.add(value.map(result -> (String) result)));
+        MailetContainer.Builder mailetContainer = TemporaryJamesServer.SIMPLE_MAILET_CONTAINER_CONFIGURATION
+                .putProcessor(ProcessorConfiguration.transport()
+                        .addMailet(DKIMSIGN_MAILET)
+                        .addMailet(DKIMVERIFY_MAILET)
+                        .addMailet(STUB_MAILET)
+                        .addMailetsFrom(CommonProcessors.transport()));
+
+        jamesServer = TemporaryJamesServer
+            .builder()
+            .withBase(Modules.combine(
+                MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE,
+                binder -> binder.bind(PublicKeyRecordRetriever.class).toInstance(MOCK_PUBLIC_KEY_RECORD_RETRIEVER)))
+            .withMailetContainer(mailetContainer)
+            .build(temporaryFolder);
+
+        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DEFAULT_DOMAIN);
+
+        dataProbe.addUser(RECIPIENT, PASSWORD);
+    }
+
+    @After
+    public void tearDown() {
+        jamesServer.shutdown();
+    }
+
+    @Test
+    public void incomingMessageShouldBeReceivedSignedAndChecked() throws Exception {
+        messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .sendMessage(FROM, RECIPIENT);
+
+        imapMessageReader.connect(LOCALHOST_IP, jamesServer.getProbe(ImapGuiceProbe.class).getImapPort())
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(awaitAtMostOneMinute);
+
+        assertThat(dkimAuthResults)
+                .hasSize(1);
+        assertThat(dkimAuthResults.get(0))
+                .hasValueSatisfying(result -> assertThat(result).startsWith("pass"));
+
+        assertThat(imapMessageReader.readFirstMessageHeaders())
+                .contains("DKIM-Signature");
+    }
+}
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ExtractAttributeStub.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ExtractAttributeStub.java
new file mode 100644
index 0000000..b5aecc0
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ExtractAttributeStub.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets;
+
+import org.apache.mailet.AttributeName;
+import org.apache.mailet.AttributeUtils;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+import javax.mail.MessagingException;
+
+import java.util.Optional;
+import java.util.function.Consumer;
+
+public class ExtractAttributeStub extends GenericMailet {
+
+    private static Consumer<Optional<?>> dkimAuthResultInspector;
+    private AttributeName name;
+
+    @Override
+    public void init() {
+        name = AttributeName.of(getInitParameter("attributeName"));
+    }
+
+    @Override
+    public void service(Mail mail) throws MessagingException {
+        dkimAuthResultInspector.accept(AttributeUtils.getAttributeValueFromMail(mail, name));
+    }
+
+    public static void setDkimAuthResultInspector(Consumer<Optional<?>> inspector) {
+        dkimAuthResultInspector = inspector;
+    }
+}
diff --git a/server/mailet/mailets-guice/pom.xml b/server/mailet/mailets-guice/pom.xml
new file mode 100644
index 0000000..f91b437
--- /dev/null
+++ b/server/mailet/mailets-guice/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied. See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.james</groupId>
+        <artifactId>james-server</artifactId>
+        <version>3.4.0-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>james-server-mailets-guice</artifactId>
+    <packaging>bundle</packaging>
+
+    <name>Apache James :: Server :: Mailets Guice</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.google.inject</groupId>
+            <artifactId>guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.james.jdkim</groupId>
+            <artifactId>apache-jdkim-library</artifactId>
+            <version>0.2</version>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/server/mailet/mailets-guice/src/main/java/org/apache/james/mailets/configuration/MailetsConfigurationModule.java b/server/mailet/mailets-guice/src/main/java/org/apache/james/mailets/configuration/MailetsConfigurationModule.java
new file mode 100644
index 0000000..8c54221
--- /dev/null
+++ b/server/mailet/mailets-guice/src/main/java/org/apache/james/mailets/configuration/MailetsConfigurationModule.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailets.configuration;
+
+import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
+import org.apache.james.jdkim.impl.DNSPublicKeyRecordRetriever;
+import org.apache.james.jdkim.impl.MultiplexingPublicKeyRecordRetriever;
+
+import com.google.inject.AbstractModule;
+
+public class MailetsConfigurationModule extends AbstractModule {
+    @Override
+    public void configure() {
+        bind(PublicKeyRecordRetriever.class).toInstance(new MultiplexingPublicKeyRecordRetriever("dns", new DNSPublicKeyRecordRetriever()));
+    }
+}
diff --git a/server/pom.xml b/server/pom.xml
index 0d82ea6..025a57e 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -77,6 +77,7 @@
         <module>mailet/mailetcontainer-api</module>
         <module>mailet/mailetcontainer-camel</module>
         <module>mailet/mailets</module>
+        <module>mailet/mailets-guice</module>
 
         <module>mailrepository/deleted-messages-vault-repository</module>
         <module>mailrepository/mailrepository-api</module>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 02/02: JAMES-1975 Inject PublicKeyRecordRetriever for DKIMVerify mailet

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6861d2a3b419674057bccdeaa0aa250c7f858496
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Mon Jun 3 15:43:11 2019 +0200

    JAMES-1975 Inject PublicKeyRecordRetriever for DKIMVerify mailet
---
 pom.xml                                            |  5 --
 server/container/guice/cassandra-guice/pom.xml     |  4 --
 .../org/apache/james/CassandraJamesServerMain.java |  4 +-
 server/container/guice/jpa-guice/pom.xml           |  4 --
 .../java/org/apache/james/JPAJamesServerMain.java  |  4 +-
 server/container/guice/jpa-smtp-common/pom.xml     |  4 --
 .../java/org/apache/james/JPAJamesServerMain.java  |  4 +-
 server/container/guice/mailet/pom.xml              |  4 ++
 .../james/modules/server/DKIMMailetModule.java}    |  4 +-
 server/container/guice/memory-guice/pom.xml        |  4 --
 .../org/apache/james/MemoryJamesServerMain.java    |  4 +-
 .../org/apache/james/jdkim/mailets/DKIMVerify.java | 30 +++++----
 .../mailets/MockPublicKeyRecordRetriever.java      | 57 +++++++++++++++++
 .../apache/james/jdkim/mailets/DKIMSignTest.java   |  1 -
 .../apache/james/jdkim/mailets/DKIMVerifyTest.java | 13 +---
 server/mailet/integration-testing/pom.xml          |  4 ++
 .../apache/james/mailets/DKIMIntegrationTest.java  | 72 +++++++++++-----------
 server/mailet/mailets-guice/pom.xml                | 47 --------------
 server/pom.xml                                     |  1 -
 19 files changed, 134 insertions(+), 136 deletions(-)

diff --git a/pom.xml b/pom.xml
index eda4654..670f5c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1560,11 +1560,6 @@
             </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
-                <artifactId>james-server-mailets-guice</artifactId>
-                <version>${project.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>${james.groupId}</groupId>
                 <artifactId>james-server-memory-guice</artifactId>
                 <version>${project.version}</version>
             </dependency>
diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml
index cbbddc0..206e9bd 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -83,10 +83,6 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-mailets-guice</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mailbox-quota-search-elasticsearch</artifactId>
         </dependency>
         <dependency>
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index ddab14f..0bdafb5 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -19,7 +19,6 @@
 
 package org.apache.james;
 
-import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.BlobExportMechanismModule;
 import org.apache.james.modules.MailboxModule;
 import org.apache.james.modules.activemq.ActiveMQQueueModule;
@@ -49,6 +48,7 @@ import org.apache.james.modules.protocols.ProtocolHandlerModule;
 import org.apache.james.modules.protocols.SMTPServerModule;
 import org.apache.james.modules.server.CassandraDataRoutesModules;
 import org.apache.james.modules.server.CassandraRoutesModule;
+import org.apache.james.modules.server.DKIMMailetModule;
 import org.apache.james.modules.server.DLPRoutesModule;
 import org.apache.james.modules.server.DataRoutesModules;
 import org.apache.james.modules.server.ElasticSearchMetricReporterModule;
@@ -133,7 +133,7 @@ public class CassandraJamesServerMain {
         CASSANDRA_MAILBOX_MODULE,
         PROTOCOLS,
         PLUGINS,
-        new MailetsConfigurationModule());
+        new DKIMMailetModule());
 
     public static void main(String[] args) throws Exception {
         Configuration configuration = Configuration.builder()
diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml
index d10f37a..0340513 100644
--- a/server/container/guice/jpa-guice/pom.xml
+++ b/server/container/guice/jpa-guice/pom.xml
@@ -147,10 +147,6 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-mailets-guice</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-testing</artifactId>
             <scope>test</scope>
         </dependency>
diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
index b036a22..df86f96 100644
--- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -19,7 +19,6 @@
 
 package org.apache.james;
 
-import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.MailboxModule;
 import org.apache.james.modules.activemq.ActiveMQQueueModule;
 import org.apache.james.modules.data.JPADataModule;
@@ -33,6 +32,7 @@ import org.apache.james.modules.protocols.ManageSieveServerModule;
 import org.apache.james.modules.protocols.POP3ServerModule;
 import org.apache.james.modules.protocols.ProtocolHandlerModule;
 import org.apache.james.modules.protocols.SMTPServerModule;
+import org.apache.james.modules.server.DKIMMailetModule;
 import org.apache.james.modules.server.DataRoutesModules;
 import org.apache.james.modules.server.DefaultProcessorsConfigurationProviderModule;
 import org.apache.james.modules.server.ElasticSearchMetricReporterModule;
@@ -97,7 +97,7 @@ public class JPAJamesServerMain {
         GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
                     .combineWith(JPA_MODULE_AGGREGATE,
                             new JMXServerModule(),
-                            new MailetsConfigurationModule());
+                            new DKIMMailetModule());
         server.start();
     }
 
diff --git a/server/container/guice/jpa-smtp-common/pom.xml b/server/container/guice/jpa-smtp-common/pom.xml
index a4e6dc0..522f208 100644
--- a/server/container/guice/jpa-smtp-common/pom.xml
+++ b/server/container/guice/jpa-smtp-common/pom.xml
@@ -74,10 +74,6 @@
             <artifactId>james-server-jpa-common-guice</artifactId>
         </dependency>
         <dependency>
-            <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-mailets-guice</artifactId>
-        </dependency>
-        <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
         </dependency>
diff --git a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
index d2238d1..e7af8a1 100644
--- a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -19,12 +19,12 @@
 
 package org.apache.james;
 
-import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.activemq.ActiveMQQueueModule;
 import org.apache.james.modules.data.JPADataModule;
 import org.apache.james.modules.data.JPAEntityManagerModule;
 import org.apache.james.modules.protocols.ProtocolHandlerModule;
 import org.apache.james.modules.protocols.SMTPServerModule;
+import org.apache.james.modules.server.DKIMMailetModule;
 import org.apache.james.modules.server.DataRoutesModules;
 import org.apache.james.modules.server.DefaultProcessorsConfigurationProviderModule;
 import org.apache.james.modules.server.ElasticSearchMetricReporterModule;
@@ -63,7 +63,7 @@ public class JPAJamesServerMain {
             .build();
 
         GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
-                    .combineWith(JPA_SERVER_MODULE, PROTOCOLS, new MailetsConfigurationModule());
+                    .combineWith(JPA_SERVER_MODULE, PROTOCOLS, new DKIMMailetModule());
         server.start();
     }
 
diff --git a/server/container/guice/mailet/pom.xml b/server/container/guice/mailet/pom.xml
index 71f324f..4cd2a76 100644
--- a/server/container/guice/mailet/pom.xml
+++ b/server/container/guice/mailet/pom.xml
@@ -57,6 +57,10 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailet-dkim</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-mailetcontainer-api</artifactId>
         </dependency>
         <dependency>
diff --git a/server/mailet/mailets-guice/src/main/java/org/apache/james/mailets/configuration/MailetsConfigurationModule.java b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/DKIMMailetModule.java
similarity index 93%
rename from server/mailet/mailets-guice/src/main/java/org/apache/james/mailets/configuration/MailetsConfigurationModule.java
rename to server/container/guice/mailet/src/main/java/org/apache/james/modules/server/DKIMMailetModule.java
index 8c54221..ac89563 100644
--- a/server/mailet/mailets-guice/src/main/java/org/apache/james/mailets/configuration/MailetsConfigurationModule.java
+++ b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/DKIMMailetModule.java
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mailets.configuration;
+package org.apache.james.modules.server;
 
 import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
 import org.apache.james.jdkim.impl.DNSPublicKeyRecordRetriever;
@@ -25,7 +25,7 @@ import org.apache.james.jdkim.impl.MultiplexingPublicKeyRecordRetriever;
 
 import com.google.inject.AbstractModule;
 
-public class MailetsConfigurationModule extends AbstractModule {
+public class DKIMMailetModule extends AbstractModule {
     @Override
     public void configure() {
         bind(PublicKeyRecordRetriever.class).toInstance(new MultiplexingPublicKeyRecordRetriever("dns", new DNSPublicKeyRecordRetriever()));
diff --git a/server/container/guice/memory-guice/pom.xml b/server/container/guice/memory-guice/pom.xml
index a3a9fb8..e558b01 100644
--- a/server/container/guice/memory-guice/pom.xml
+++ b/server/container/guice/memory-guice/pom.xml
@@ -174,10 +174,6 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
-            <artifactId>james-server-mailets-guice</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-mailrepository-memory</artifactId>
         </dependency>
         <dependency>
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
index 73d33d2..191cf83 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -23,7 +23,6 @@ import java.util.Optional;
 
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.jwt.JwtConfiguration;
-import org.apache.james.mailets.configuration.MailetsConfigurationModule;
 import org.apache.james.modules.BlobExportMechanismModule;
 import org.apache.james.modules.BlobMemoryModule;
 import org.apache.james.modules.MailboxModule;
@@ -39,6 +38,7 @@ import org.apache.james.modules.protocols.POP3ServerModule;
 import org.apache.james.modules.protocols.ProtocolHandlerModule;
 import org.apache.james.modules.protocols.SMTPServerModule;
 import org.apache.james.modules.server.CamelMailetContainerModule;
+import org.apache.james.modules.server.DKIMMailetModule;
 import org.apache.james.modules.server.DLPRoutesModule;
 import org.apache.james.modules.server.DataRoutesModules;
 import org.apache.james.modules.server.JMXServerModule;
@@ -125,7 +125,7 @@ public class MemoryJamesServerMain {
         PROTOCOLS,
         JMAP,
         WEBADMIN,
-        new MailetsConfigurationModule());
+        new DKIMMailetModule());
 
     public static void main(String[] args) throws Exception {
         Configuration configuration = Configuration.builder()
diff --git a/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/DKIMVerify.java b/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/DKIMVerify.java
index 92e6015..2a2b11a 100644
--- a/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/DKIMVerify.java
+++ b/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/DKIMVerify.java
@@ -24,12 +24,14 @@ import java.io.OutputStream;
 import java.util.List;
 import java.util.Optional;
 
+import javax.inject.Inject;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.jdkim.DKIMVerifier;
 import org.apache.james.jdkim.api.BodyHasher;
 import org.apache.james.jdkim.api.Headers;
+import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
 import org.apache.james.jdkim.api.SignatureRecord;
 import org.apache.james.jdkim.exceptions.FailException;
 import org.apache.mailet.Attribute;
@@ -42,30 +44,36 @@ import com.google.common.annotations.VisibleForTesting;
 
 /**
  * This mailet verify a message using the DKIM protocol
- * 
+ *
  * Sample configuration:
  * <pre><code>
  * &lt;mailet match=&quot;All&quot; class=&quot;DKIMVerify&quot;&gt;
  * &lt;/mailet&gt;
  * </code></pre>
- * 
- * By default the mailet assume that Javamail will use LF instead of CRLF 
- * so it will verify the hash using converted newlines. If you don't want this 
- * behaviout then set forceCRLF attribute to false. 
+ *
+ * By default the mailet assume that Javamail will use LF instead of CRLF
+ * so it will verify the hash using converted newlines. If you don't want this
+ * behaviour then set forceCRLF attribute to false.
  */
 public class DKIMVerify extends GenericMailet {
 
     public static final AttributeName DKIM_AUTH_RESULT = AttributeName.of("jDKIM.AUTHRESULT");
-    
-    @VisibleForTesting DKIMVerifier verifier = null;
+
+    @VisibleForTesting
+    DKIMVerifier verifier;
+
     private boolean forceCRLF;
 
+    @Inject
+    public DKIMVerify(PublicKeyRecordRetriever publicKeyRecordRetriever) {
+        verifier = new DKIMVerifier(publicKeyRecordRetriever);
+    }
+
     @Override
     public void init() {
-        verifier = new DKIMVerifier();
         forceCRLF = getInitParameter("forceCRLF", true);
     }
-    
+
     public void service(Mail mail) throws MessagingException {
         try {
             MimeMessage message = mail.getMessage();
@@ -96,13 +104,13 @@ public class DKIMVerify extends GenericMailet {
 
     @VisibleForTesting
     static List<SignatureRecord> verify(DKIMVerifier verifier, MimeMessage message, boolean forceCRLF)
-            throws MessagingException, FailException {
+        throws MessagingException, FailException {
         Headers headers = new MimeMessageHeaders(message);
         BodyHasher bh = verifier.newBodyHasher(headers);
         try {
             if (bh != null) {
                 OutputStream os = new HeaderSkippingOutputStream(bh
-                        .getOutputStream());
+                    .getOutputStream());
                 if (forceCRLF) {
                     os = new CRLFOutputStream(os);
                 }
diff --git a/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/MockPublicKeyRecordRetriever.java b/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/MockPublicKeyRecordRetriever.java
new file mode 100644
index 0000000..d3b5d63
--- /dev/null
+++ b/server/mailet/dkim/src/main/java/org/apache/james/jdkim/mailets/MockPublicKeyRecordRetriever.java
@@ -0,0 +1,57 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jdkim.mailets;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
+import org.apache.james.jdkim.exceptions.PermFailException;
+import org.apache.james.jdkim.exceptions.TempFailException;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMultimap;
+
+public class MockPublicKeyRecordRetriever implements PublicKeyRecordRetriever {
+    private final ImmutableMultimap<String, String> records;
+
+    public MockPublicKeyRecordRetriever(String record, CharSequence selector, CharSequence token) {
+        records = ImmutableMultimap.of(makeKey(selector, token), record);
+    }
+
+    public List<String> getRecords(CharSequence methodAndOptions, CharSequence selector, CharSequence token) throws TempFailException, PermFailException {
+        if ("dns/txt".equals(methodAndOptions)) {
+            String search = makeKey(selector, token);
+            Collection<String> res = this.records.get(search);
+            if (res.size() <= 0) {
+                throw new TempFailException("Timout or servfail");
+            } else {
+                return ImmutableList.copyOf(res);
+            }
+        } else {
+            throw new PermFailException("Unsupported method");
+        }
+    }
+
+    private String makeKey(CharSequence selector, CharSequence token) {
+        return selector.toString() + "._domainkey." + token.toString();
+    }
+}
+
diff --git a/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMSignTest.java b/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMSignTest.java
index 305ff5f..28f98cd 100644
--- a/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMSignTest.java
+++ b/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMSignTest.java
@@ -36,7 +36,6 @@ import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMessage.RecipientType;
 
 import org.apache.james.jdkim.DKIMVerifier;
-import org.apache.james.jdkim.MockPublicKeyRecordRetriever;
 import org.apache.james.jdkim.api.SignatureRecord;
 import org.apache.james.jdkim.exceptions.FailException;
 import org.apache.james.jdkim.exceptions.PermFailException;
diff --git a/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMVerifyTest.java b/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMVerifyTest.java
index 27650ab..03f06dc 100644
--- a/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMVerifyTest.java
+++ b/server/mailet/dkim/src/test/java/org/apache/james/jdkim/mailets/DKIMVerifyTest.java
@@ -93,16 +93,9 @@ public class DKIMVerifyTest {
     }
 
     private Mail process(String message) throws Exception {
-        Mailet mailet = new DKIMVerify() {
-
-            @Override
-            public void init() {
-                verifier = new DKIMVerifier(new MockPublicKeyRecordRetriever(
-                        "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoTM5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRHr7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB;",
-                        "selector", "example.com"));
-            }
-            
-        };
+        Mailet mailet = new DKIMVerify((new MockPublicKeyRecordRetriever(
+            "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoTM5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRHr7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB;",
+            "selector", "example.com")));
 
         FakeMailetConfig mci = FakeMailetConfig.builder()
                 .mailetName("Test")
diff --git a/server/mailet/integration-testing/pom.xml b/server/mailet/integration-testing/pom.xml
index 697b075..1aa05f1 100644
--- a/server/mailet/integration-testing/pom.xml
+++ b/server/mailet/integration-testing/pom.xml
@@ -84,6 +84,10 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-mailet-dkim</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-memory-guice</artifactId>
         </dependency>
         <dependency>
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java
index 79bb150..f686b66 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DKIMIntegrationTest.java
@@ -30,10 +30,10 @@ import java.util.List;
 import java.util.Optional;
 
 import org.apache.james.MemoryJamesServerMain;
-import org.apache.james.jdkim.MockPublicKeyRecordRetriever;
 import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
 import org.apache.james.jdkim.mailets.DKIMSign;
 import org.apache.james.jdkim.mailets.DKIMVerify;
+import org.apache.james.jdkim.mailets.MockPublicKeyRecordRetriever;
 import org.apache.james.mailets.configuration.CommonProcessors;
 import org.apache.james.mailets.configuration.MailetConfiguration;
 import org.apache.james.mailets.configuration.MailetContainer;
@@ -52,6 +52,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
+import com.google.inject.util.Modules;
 
 public class DKIMIntegrationTest {
 
@@ -61,32 +62,35 @@ public class DKIMIntegrationTest {
     private static final String RECIPIENT = RECIPIENT_LOCAL_PART + "@" + DEFAULT_DOMAIN;
 
     private static final String TESTING_PEM = "-----BEGIN RSA PRIVATE KEY-----\r\n" +
-            "MIICXAIBAAKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoT\r\n" +
-            "M5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRH\r\n" +
-            "r7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB\r\n" +
-            "AoGBAI8XcwnZi0Sq5N89wF+gFNhnREFo3rsJDaCY8iqHdA5DDlnr3abb/yhipw0I\r\n" +
-            "/1HlgC6fIG2oexXOXFWl+USgqRt1kTt9jXhVFExg8mNko2UelAwFtsl8CRjVcYQO\r\n" +
-            "cedeH/WM/mXjg2wUqqZenBmlKlD6vNb70jFJeVaDJ/7n7j8BAkEA9NkH2D4Zgj/I\r\n" +
-            "OAVYccZYH74+VgO0e7VkUjQk9wtJ2j6cGqJ6Pfj0roVIMUWzoBb8YfErR8l6JnVQ\r\n" +
-            "bfy83gJeiQJBAOHk3ow7JjAn8XuOyZx24KcTaYWKUkAQfRWYDFFOYQF4KV9xLSEt\r\n" +
-            "ycY0kjsdxGKDudWcsATllFzXDCQF6DTNIWECQEA52ePwTjKrVnLTfCLEG4OgHKvl\r\n" +
-            "Zud4amthwDyJWoMEH2ChNB2je1N4JLrABOE+hk+OuoKnKAKEjWd8f3Jg/rkCQHj8\r\n" +
-            "mQmogHqYWikgP/FSZl518jV48Tao3iXbqvU9Mo2T6yzYNCCqIoDLFWseNVnCTZ0Q\r\n" +
-            "b+IfiEf1UeZVV5o4J+ECQDatNnS3V9qYUKjj/krNRD/U0+7eh8S2ylLqD3RlSn9K\r\n" +
-            "tYGRMgAtUXtiOEizBH6bd/orzI9V9sw8yBz+ZqIH25Q=\r\n" +
-            "-----END RSA PRIVATE KEY-----\r\n";
+        "MIICXAIBAAKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoT\r\n" +
+        "M5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRH\r\n" +
+        "r7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB\r\n" +
+        "AoGBAI8XcwnZi0Sq5N89wF+gFNhnREFo3rsJDaCY8iqHdA5DDlnr3abb/yhipw0I\r\n" +
+        "/1HlgC6fIG2oexXOXFWl+USgqRt1kTt9jXhVFExg8mNko2UelAwFtsl8CRjVcYQO\r\n" +
+        "cedeH/WM/mXjg2wUqqZenBmlKlD6vNb70jFJeVaDJ/7n7j8BAkEA9NkH2D4Zgj/I\r\n" +
+        "OAVYccZYH74+VgO0e7VkUjQk9wtJ2j6cGqJ6Pfj0roVIMUWzoBb8YfErR8l6JnVQ\r\n" +
+        "bfy83gJeiQJBAOHk3ow7JjAn8XuOyZx24KcTaYWKUkAQfRWYDFFOYQF4KV9xLSEt\r\n" +
+        "ycY0kjsdxGKDudWcsATllFzXDCQF6DTNIWECQEA52ePwTjKrVnLTfCLEG4OgHKvl\r\n" +
+        "Zud4amthwDyJWoMEH2ChNB2je1N4JLrABOE+hk+OuoKnKAKEjWd8f3Jg/rkCQHj8\r\n" +
+        "mQmogHqYWikgP/FSZl518jV48Tao3iXbqvU9Mo2T6yzYNCCqIoDLFWseNVnCTZ0Q\r\n" +
+        "b+IfiEf1UeZVV5o4J+ECQDatNnS3V9qYUKjj/krNRD/U0+7eh8S2ylLqD3RlSn9K\r\n" +
+        "tYGRMgAtUXtiOEizBH6bd/orzI9V9sw8yBz+ZqIH25Q=\r\n" +
+        "-----END RSA PRIVATE KEY-----\r\n";
     private static final MailetConfiguration DKIMSIGN_MAILET = MailetConfiguration.builder()
-            .matcher(All.class)
-            .mailet(DKIMSign.class)
-            .addProperty(
-                    "signatureTemplate",
-                    "v=1; s=selector; d=example.com; h=from:to:received:received; a=rsa-sha256; bh=; b=;")
-            .addProperty("privateKey", TESTING_PEM)
-            .build();
+        .matcher(All.class)
+        .mailet(DKIMSign.class)
+        .addProperty(
+            "signatureTemplate",
+            "v=1; s=selector; d=example.com; h=from:to:received:received; a=rsa-sha256; bh=; b=;")
+        .addProperty("privateKey", TESTING_PEM)
+        .build();
+
     private static final MailetConfiguration DKIMVERIFY_MAILET = MailetConfiguration.builder()
-            .matcher(All.class)
-            .mailet(DKIMVerify.class)
-            .build();
+        .matcher(All.class)
+        .mailet(DKIMVerify.class)
+        .build();
+
+
     private static final MailetConfiguration STUB_MAILET = MailetConfiguration.builder()
         .matcher(All.class)
         .mailet(ExtractAttributeStub.class)
@@ -105,7 +109,6 @@ public class DKIMIntegrationTest {
     public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
-    private DataProbe dataProbe;
     private List<Optional<String>> dkimAuthResults;
 
     @Before
@@ -113,21 +116,20 @@ public class DKIMIntegrationTest {
         dkimAuthResults = new ArrayList<>();
         ExtractAttributeStub.setDkimAuthResultInspector(value -> dkimAuthResults.add(value.map(result -> (String) result)));
         MailetContainer.Builder mailetContainer = TemporaryJamesServer.SIMPLE_MAILET_CONTAINER_CONFIGURATION
-                .putProcessor(ProcessorConfiguration.transport()
-                        .addMailet(DKIMSIGN_MAILET)
-                        .addMailet(DKIMVERIFY_MAILET)
-                        .addMailet(STUB_MAILET)
-                        .addMailetsFrom(CommonProcessors.transport()));
+            .putProcessor(ProcessorConfiguration.transport()
+                .addMailet(DKIMSIGN_MAILET)
+                .addMailet(DKIMVERIFY_MAILET)
+                .addMailet(STUB_MAILET)
+                .addMailetsFrom(CommonProcessors.transport()));
 
         jamesServer = TemporaryJamesServer
             .builder()
-            .withBase(Modules.combine(
-                MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE,
-                binder -> binder.bind(PublicKeyRecordRetriever.class).toInstance(MOCK_PUBLIC_KEY_RECORD_RETRIEVER)))
+            .withBase(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+            .withOverrides(binder -> binder.bind(PublicKeyRecordRetriever.class).toInstance(MOCK_PUBLIC_KEY_RECORD_RETRIEVER))
             .withMailetContainer(mailetContainer)
             .build(temporaryFolder);
 
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
         dataProbe.addDomain(DEFAULT_DOMAIN);
 
         dataProbe.addUser(RECIPIENT, PASSWORD);
diff --git a/server/mailet/mailets-guice/pom.xml b/server/mailet/mailets-guice/pom.xml
deleted file mode 100644
index f91b437..0000000
--- a/server/mailet/mailets-guice/pom.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements. See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership. The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License. You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied. See the License for the
-    specific language governing permissions and limitations
-    under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>org.apache.james</groupId>
-        <artifactId>james-server</artifactId>
-        <version>3.4.0-SNAPSHOT</version>
-        <relativePath>../../pom.xml</relativePath>
-    </parent>
-
-    <artifactId>james-server-mailets-guice</artifactId>
-    <packaging>bundle</packaging>
-
-    <name>Apache James :: Server :: Mailets Guice</name>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.google.inject</groupId>
-            <artifactId>guice</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.james.jdkim</groupId>
-            <artifactId>apache-jdkim-library</artifactId>
-            <version>0.2</version>
-        </dependency>
-    </dependencies>
-
-</project>
diff --git a/server/pom.xml b/server/pom.xml
index 025a57e..0d82ea6 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -77,7 +77,6 @@
         <module>mailet/mailetcontainer-api</module>
         <module>mailet/mailetcontainer-camel</module>
         <module>mailet/mailets</module>
-        <module>mailet/mailets-guice</module>
 
         <module>mailrepository/deleted-messages-vault-repository</module>
         <module>mailrepository/mailrepository-api</module>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org