From 61e1bdca30c8a9d21a86e5baa46b25a7787fe741 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Mon, 30 Jan 2017 11:03:49 +0100 Subject: [PATCH] JAMES-1902 create a smtp only project that pulls only required dependencies --- .../container/guice/jpa-common-guice/pom.xml | 318 +++++++++++++++++ .../james/modules/data/JPADataModule.java | 0 .../modules/data/JPADomainListModule.java | 0 .../data/JPARecipientRewriteTableModule.java | 0 .../data/JPAUsersRepositoryModule.java | 0 server/container/guice/jpa-guice/pom.xml | 4 + server/container/guice/jpa-smtp/README.adoc | 40 +++ server/container/guice/jpa-smtp/pom.xml | 321 ++++++++++++++++++ .../sample-configuration/dnsservice.xml | 29 ++ .../sample-configuration/domainlist.xml | 28 ++ .../james-database.properties | 40 +++ .../sample-configuration/jmx.properties | 28 ++ .../sample-configuration/mailetcontainer.xml | 137 ++++++++ .../mailrepositorystore.xml | 34 ++ .../recipientrewritetable.xml | 27 ++ .../sample-configuration/smtpserver.xml | 105 ++++++ .../sample-configuration/usersrepository.xml | 27 ++ .../org/apache/james/JPAConfiguration.java | 66 ++++ .../org/apache/james/JPAJamesServerMain.java | 53 +++ .../main/resources/META-INF/persistence.xml | 41 +++ .../jpa-smtp/src/main/resources/logback.xml | 22 ++ .../org/apache/james/JPAJamesServerTest.java | 94 +++++ .../james/TestJPAConfigurationModule.java | 48 +++ .../src/test/resources/dnsservice.xml | 29 ++ .../resources/fakemailrepositorystore.xml | 31 ++ .../jpa-smtp/src/test/resources/keystore | Bin 0 -> 2245 bytes .../src/test/resources/mailetcontainer.xml | 123 +++++++ .../test/resources/mailrepositorystore.xml | 31 ++ .../src/test/resources/managesieveserver.xml | 65 ++++ .../src/test/resources/smtpserver.xml | 105 ++++++ server/container/guice/pom.xml | 7 + 31 files changed, 1853 insertions(+) create mode 100644 server/container/guice/jpa-common-guice/pom.xml rename server/container/guice/{jpa-guice => jpa-common-guice}/src/main/java/org/apache/james/modules/data/JPADataModule.java (100%) rename server/container/guice/{jpa-guice => jpa-common-guice}/src/main/java/org/apache/james/modules/data/JPADomainListModule.java (100%) rename server/container/guice/{jpa-guice => jpa-common-guice}/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java (100%) rename server/container/guice/{jpa-guice => jpa-common-guice}/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java (100%) create mode 100644 server/container/guice/jpa-smtp/README.adoc create mode 100644 server/container/guice/jpa-smtp/pom.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/dnsservice.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/domainlist.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/james-database.properties create mode 100644 server/container/guice/jpa-smtp/sample-configuration/jmx.properties create mode 100644 server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/mailrepositorystore.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/recipientrewritetable.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/smtpserver.xml create mode 100644 server/container/guice/jpa-smtp/sample-configuration/usersrepository.xml create mode 100644 server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAConfiguration.java create mode 100644 server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java create mode 100644 server/container/guice/jpa-smtp/src/main/resources/META-INF/persistence.xml create mode 100644 server/container/guice/jpa-smtp/src/main/resources/logback.xml create mode 100644 server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java create mode 100644 server/container/guice/jpa-smtp/src/test/java/org/apache/james/TestJPAConfigurationModule.java create mode 100644 server/container/guice/jpa-smtp/src/test/resources/dnsservice.xml create mode 100644 server/container/guice/jpa-smtp/src/test/resources/fakemailrepositorystore.xml create mode 100644 server/container/guice/jpa-smtp/src/test/resources/keystore create mode 100644 server/container/guice/jpa-smtp/src/test/resources/mailetcontainer.xml create mode 100644 server/container/guice/jpa-smtp/src/test/resources/mailrepositorystore.xml create mode 100644 server/container/guice/jpa-smtp/src/test/resources/managesieveserver.xml create mode 100644 server/container/guice/jpa-smtp/src/test/resources/smtpserver.xml diff --git a/server/container/guice/jpa-common-guice/pom.xml b/server/container/guice/jpa-common-guice/pom.xml new file mode 100644 index 00000000000..34af8d0f830 --- /dev/null +++ b/server/container/guice/jpa-common-guice/pom.xml @@ -0,0 +1,318 @@ + + + + + 4.0.0 + + + org.apache.james + james-server-guice + 3.0.0-beta6-SNAPSHOT + ../pom.xml + + + james-server-jpa-common-guice + jar + + Apache James :: Server :: JPA - guice common + + + empty + + + + + disable-build-for-older-jdk + + (,1.8) + + + + + maven-jar-plugin + + + default-jar + none + + + jar + none + + + test-jar + none + + + + + maven-compiler-plugin + + + default-compile + none + + + default-testCompile + none + + + + + maven-surefire-plugin + + + default-test + none + + + + + maven-source-plugin + + + attach-sources + none + + + + + maven-install-plugin + + + default-install + none + + + + + maven-resources-plugin + + + default-resources + none + + + default-testResources + none + + + + + maven-site-plugin + + + attach-descriptor + none + + + + + + + + build-for-jdk-8 + + [1.8,) + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/${project.artifactId}.lib + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + default-jar + + jar + + + ${project.artifactId} + + + true + ${project.artifactId}.lib/ + org.apache.james.JPAJamesServerMain + false + + + + + + test-jar + + test-jar + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + org.apache.derby + derby + test + + + ${project.groupId} + apache-james-mailbox-jpa + + + ${project.groupId} + apache-james-mailbox-jpa + test + test-jar + + + ${project.groupId} + apache-james-mailbox-lucene + + + ${project.groupId} + james-server-data-jpa + + + ${project.groupId} + james-server-guice-common + + + ${project.groupId} + james-server-guice-common + test-jar + test + + + ch.qos.logback + logback-classic + 1.1.7 + + + com.jayway.awaitility + awaitility + + + com.jayway.restassured + rest-assured + test + + + com.nurkiewicz.asyncretry + asyncretry + + + org.assertj + assertj-core + ${assertj-3.version} + test + + + org.mockito + mockito-core + test + + + + + jpa + + **/*.java + + + + animal-sniffer-java-8 + + [1.8,) + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + org.codehaus.mojo.signature + java18 + 1.0 + + + + + check_java_8 + test + + check + + + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/suite/*.java + **/suite/**/*.java + + + ${jpa.includes} + + + + + + diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java similarity index 100% rename from server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java rename to server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java similarity index 100% rename from server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java rename to server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java similarity index 100% rename from server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java rename to server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java similarity index 100% rename from server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java rename to server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml index f02b70c78ac..07ca6bf4c15 100644 --- a/server/container/guice/jpa-guice/pom.xml +++ b/server/container/guice/jpa-guice/pom.xml @@ -225,6 +225,10 @@ test-jar test + + ${project.groupId} + james-server-jpa-common-guice + ch.qos.logback logback-classic diff --git a/server/container/guice/jpa-smtp/README.adoc b/server/container/guice/jpa-smtp/README.adoc new file mode 100644 index 00000000000..bedf715ff78 --- /dev/null +++ b/server/container/guice/jpa-smtp/README.adoc @@ -0,0 +1,40 @@ += Guice-JPA Module How-to + +== Building + +=== Requirements + + * Java 8 SDK + * Docker + * Maven + +=== Building the artifacts + +An usual compilation using maven will produce two artifacts into target directory : + + * james-server-jpa-smtp-${version}.jar + * james-server-jpa-smtp-${version}.lib + +== Running + +=== Requirements + +=== James Launch + +To run james, you have to create a directory containing required configuration files. + +A sample directory (appropriately named sample-directory) is provided with some +default value you may need to replace. + +You also need to generate a keystore with the following command : +[source] +---- +$ keytool -genkey -alias james -keyalg RSA -keystore conf/keystore +---- + +Once everything is set up, you just have to run the jar with : + +[source] +---- +$ java -Dworking.directory=sample-configuration -jar target/james-server-jpa-smtp-${version}.jar +---- diff --git a/server/container/guice/jpa-smtp/pom.xml b/server/container/guice/jpa-smtp/pom.xml new file mode 100644 index 00000000000..430fb8fbf6f --- /dev/null +++ b/server/container/guice/jpa-smtp/pom.xml @@ -0,0 +1,321 @@ + + + + + 4.0.0 + + + org.apache.james + james-server-guice + 3.0.0-beta6-SNAPSHOT + ../pom.xml + + + james-server-jpa-smtp-guice + jar + + Apache James :: Server :: JPA + SMTP - guice injection + An advanced email server - JPA backend for SMTP with guice injection + + + empty + + + + + disable-build-for-older-jdk + + (,1.8) + + + + + maven-jar-plugin + + + default-jar + none + + + jar + none + + + test-jar + none + + + + + maven-compiler-plugin + + + default-compile + none + + + default-testCompile + none + + + + + maven-surefire-plugin + + + default-test + none + + + + + maven-source-plugin + + + attach-sources + none + + + + + maven-install-plugin + + + default-install + none + + + + + maven-resources-plugin + + + default-resources + none + + + default-testResources + none + + + + + maven-site-plugin + + + attach-descriptor + none + + + + + + + + build-for-jdk-8 + + [1.8,) + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/${project.artifactId}.lib + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + default-jar + + jar + + + ${project.artifactId} + + + true + ${project.artifactId}.lib/ + org.apache.james.JPAJamesServerMain + false + + + + + + test-jar + + test-jar + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + ${project.groupId} + apache-james-backends-jpa + ${project.version} + test-jar + test + + + ${project.groupId} + james-server-data-jpa + + + ${project.groupId} + james-server-guice-common + + + ${project.groupId} + james-server-guice-common + test-jar + test + + + ${project.groupId} + james-server-jpa-common-guice + + + ch.qos.logback + logback-classic + 1.1.7 + + + com.h2database + h2 + test + + + com.jayway.awaitility + awaitility + + + com.jayway.restassured + rest-assured + test + + + com.nurkiewicz.asyncretry + asyncretry + + + org.apache.derby + derby + test + + + org.assertj + assertj-core + ${assertj-3.version} + test + + + org.mockito + mockito-core + test + + + + + jpa + + **/*.java + + + + animal-sniffer-java-8 + + [1.8,) + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + org.codehaus.mojo.signature + java18 + 1.0 + + + + + check_java_8 + test + + check + + + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/suite/*.java + **/suite/**/*.java + + + ${jpa.includes} + + + + + + diff --git a/server/container/guice/jpa-smtp/sample-configuration/dnsservice.xml b/server/container/guice/jpa-smtp/sample-configuration/dnsservice.xml new file mode 100644 index 00000000000..0978a00b899 --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/dnsservice.xml @@ -0,0 +1,29 @@ + + + + + + 8.8.8.8 + 62.210.16.6 + + false + false + 50000 + diff --git a/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml b/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml new file mode 100644 index 00000000000..8d001185bbb --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml @@ -0,0 +1,28 @@ + + + + + + james.apache.org + + true + true + localhost + diff --git a/server/container/guice/jpa-smtp/sample-configuration/james-database.properties b/server/container/guice/jpa-smtp/sample-configuration/james-database.properties new file mode 100644 index 00000000000..b3ac7ebc6e5 --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/james-database.properties @@ -0,0 +1,40 @@ +# 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. + +# This template file can be used as example for James Server configuration +# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS + +# See http://james.apache.org/server/3/config.html for usage + +# Use derby as default +database.driverClassName=org.apache.derby.jdbc.EmbeddedDriver +database.url=jdbc:derby:../var/store/derby;create=true +database.username=app +database.password=app + +# Supported adapters are: +# DB2, DERBY, H2, HSQL, INFORMIX, MYSQL, ORACLE, POSTGRESQL, SQL_SERVER, SYBASE +vendorAdapter.database=DERBY + +# Use streaming for Blobs +# This is only supported on a limited set of databases atm. You should check if its supported by your DB before enable +# it. +# +# See: +# http://openjpa.apache.org/builds/latest/docs/manual/ref_guide_mapping_jpa.html #7.11. LOB Streaming +# +openjpa.streaming=false \ No newline at end of file diff --git a/server/container/guice/jpa-smtp/sample-configuration/jmx.properties b/server/container/guice/jpa-smtp/sample-configuration/jmx.properties new file mode 100644 index 00000000000..a1dbdf8924b --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/jmx.properties @@ -0,0 +1,28 @@ +# 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. +# + +# This template file can be used as example for James Server configuration +# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS + +# This template file can be used as example for James Server configuration +# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS + +# See http://james.apache.org/server/3/config.html for usage + +jmx.address=127.0.0.1 +jmx.port=9999 diff --git a/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml b/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml new file mode 100644 index 00000000000..968b59c4d0e --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml @@ -0,0 +1,137 @@ + + + + + + + + postmaster@james.minet.net + + + + 20 + + + + + + + + + sieve-manager-check + + + transport + + + true + + + transport + + + transport + + + + + + + spam + 550 Requested action not taken: rejected - see http://njabl.org/ + + + transport + + + + + + + file://var/mail/error/ + + + + + + + X-UserIsAuth + true + + + X-WasSigned + true + + + + + local-address-error + 550 - Requested action not taken: no such user here + + + outgoing + 5000, 100000, 500000 + 25 + 0 + 10 + true + bounces + + + relay-denied + + + + + + file://var/mail/spam/ + + + + + + none + + + file://var/mail/address-error/ + + + + + + none + + + file://var/mail/relay-denied/ + Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation + + + + + + false + + + + + + + diff --git a/server/container/guice/jpa-smtp/sample-configuration/mailrepositorystore.xml b/server/container/guice/jpa-smtp/sample-configuration/mailrepositorystore.xml new file mode 100644 index 00000000000..acca810221d --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/mailrepositorystore.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + file + + + + + + diff --git a/server/container/guice/jpa-smtp/sample-configuration/recipientrewritetable.xml b/server/container/guice/jpa-smtp/sample-configuration/recipientrewritetable.xml new file mode 100644 index 00000000000..7e7f586a3c8 --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/recipientrewritetable.xml @@ -0,0 +1,27 @@ + + + + + + true + 10 + some@domain=some + + diff --git a/server/container/guice/jpa-smtp/sample-configuration/smtpserver.xml b/server/container/guice/jpa-smtp/sample-configuration/smtpserver.xml new file mode 100644 index 00000000000..c34fcd1c37c --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/smtpserver.xml @@ -0,0 +1,105 @@ + + + + + + + smtpserver-global + 0.0.0.0:1025 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + false + 0.0.0.0/0 + true + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-TLS + 0.0.0.0:1465 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-authenticated + 0.0.0.0:1587 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + + diff --git a/server/container/guice/jpa-smtp/sample-configuration/usersrepository.xml b/server/container/guice/jpa-smtp/sample-configuration/usersrepository.xml new file mode 100644 index 00000000000..fc761078f38 --- /dev/null +++ b/server/container/guice/jpa-smtp/sample-configuration/usersrepository.xml @@ -0,0 +1,27 @@ + + + + + + MD5 + true + true + + diff --git a/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAConfiguration.java b/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAConfiguration.java new file mode 100644 index 00000000000..c0f7d763bf8 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAConfiguration.java @@ -0,0 +1,66 @@ +/**************************************************************** + * 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; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; + +public class JPAConfiguration { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String driverName; + private String driverURL; + + public Builder driverName(String driverName) { + this.driverName = driverName; + return this; + } + + public Builder driverURL(String driverURL) { + this.driverURL = driverURL; + return this; + } + + public JPAConfiguration build() { + Preconditions.checkNotNull(driverName); + Preconditions.checkNotNull(driverURL); + return new JPAConfiguration(driverName, driverURL); + } + } + + private final String driverName; + private final String driverURL; + + @VisibleForTesting JPAConfiguration(String driverName, String driverURL) { + this.driverName = driverName; + this.driverURL = driverURL; + } + + public String getDriverName() { + return driverName; + } + + public String getDriverURL() { + return driverURL; + } + +} diff --git a/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java new file mode 100644 index 00000000000..ce01b8d7d4e --- /dev/null +++ b/server/container/guice/jpa-smtp/src/main/java/org/apache/james/JPAJamesServerMain.java @@ -0,0 +1,53 @@ +/**************************************************************** + * 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; + +import javax.persistence.EntityManagerFactory; + +import org.apache.james.modules.data.JPADataModule; +import org.apache.james.modules.protocols.ProtocolHandlerModule; +import org.apache.james.modules.protocols.SMTPServerModule; +import org.apache.james.modules.server.ActiveMQQueueModule; +import org.apache.james.modules.server.JMXServerModule; +import org.apache.james.modules.server.RawPostDequeueDecoratorModule; +import org.apache.openjpa.persistence.OpenJPAPersistence; + +import com.google.inject.Module; +import com.google.inject.util.Modules; + +public class JPAJamesServerMain { + + public static final Module protocols = Modules.combine( + new ProtocolHandlerModule(), + new SMTPServerModule()); + + public static final Module jpaServerModule = Modules.combine( + new JPADataModule(), + (binder) -> binder.bind(EntityManagerFactory.class).toProvider(() -> OpenJPAPersistence.getEntityManagerFactory()), + new ActiveMQQueueModule(), + new RawPostDequeueDecoratorModule()); + + public static void main(String[] args) throws Exception { + GuiceJamesServer server = new GuiceJamesServer() + .combineWith(jpaServerModule, protocols, new JMXServerModule()); + server.start(); + } + +} diff --git a/server/container/guice/jpa-smtp/src/main/resources/META-INF/persistence.xml b/server/container/guice/jpa-smtp/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000000..c2d612a5924 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,41 @@ + + + + + + + org.apache.james.mailbox.jpa.mail.model.JPAUserFlag + org.apache.james.mailbox.jpa.user.model.JPASubscription + org.apache.james.domainlist.jpa.model.JPADomain + org.apache.james.user.jpa.model.JPAUser + org.apache.james.rrt.jpa.model.JPARecipientRewrite + + + + + + + + + + diff --git a/server/container/guice/jpa-smtp/src/main/resources/logback.xml b/server/container/guice/jpa-smtp/src/main/resources/logback.xml new file mode 100644 index 00000000000..0e1ff22440d --- /dev/null +++ b/server/container/guice/jpa-smtp/src/main/resources/logback.xml @@ -0,0 +1,22 @@ + + + + + true + + + + + %d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx + false + + + + + + + + + + + diff --git a/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java new file mode 100644 index 00000000000..7a22c194c08 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java @@ -0,0 +1,94 @@ +/**************************************************************** + * 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; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; + +import javax.persistence.EntityManagerFactory; + +import org.apache.james.backends.jpa.JpaTestCluster; +import org.apache.james.domainlist.jpa.model.JPADomain; +import org.apache.james.modules.TestFilesystemModule; +import org.apache.james.rrt.jpa.model.JPARecipientRewrite; +import org.apache.james.user.jpa.model.JPAUser; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class JPAJamesServerTest { + + private static final int SMTP_PORT = 1025; + + private GuiceJamesServer server; + private SocketChannel socketChannel; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @After + public void teardown() { + server.stop(); + } + + private org.apache.james.GuiceJamesServer createJamesServer() { + return new GuiceJamesServer() + .combineWith(JPAJamesServerMain.jpaServerModule, JPAJamesServerMain.protocols) + .overrideWith( + new TestFilesystemModule(temporaryFolder), + new TestJPAConfigurationModule(), + (binder) -> binder.bind(EntityManagerFactory.class) + .toInstance(JpaTestCluster.create(JPAUser.class, JPADomain.class, JPARecipientRewrite.class) + .getEntityManagerFactory())); + } + + @Before + public void setup() throws Exception { + server = createJamesServer(); + socketChannel = SocketChannel.open(); + server.start(); + } + + @After + public void tearDown() throws Exception { + server.stop(); + } + + @Test + public void connectSMTPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", SMTP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("220 JAMES Linagora's SMTP awesome Server"); + } + + private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException { + ByteBuffer byteBuffer = ByteBuffer.allocate(1000); + socketChannel.read(byteBuffer); + byte[] bytes = byteBuffer.array(); + return new String(bytes, Charset.forName("UTF-8")); + } + +} diff --git a/server/container/guice/jpa-smtp/src/test/java/org/apache/james/TestJPAConfigurationModule.java b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/TestJPAConfigurationModule.java new file mode 100644 index 00000000000..7c064c49fa4 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/TestJPAConfigurationModule.java @@ -0,0 +1,48 @@ +/**************************************************************** + * 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; + +import java.io.FileNotFoundException; + +import javax.inject.Singleton; + +import org.apache.commons.configuration.ConfigurationException; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +public class TestJPAConfigurationModule extends AbstractModule { + + private static final String JDBC_EMBEDDED_URL = "jdbc:derby:memory:mailboxintegration;create=true"; + private static final String JDBC_EMBEDDED_DRIVER = org.apache.derby.jdbc.EmbeddedDriver.class.getName(); + + @Override + protected void configure() { + } + + @Provides + @Singleton + JPAConfiguration provideConfiguration() throws FileNotFoundException, ConfigurationException{ + return JPAConfiguration.builder() + .driverName(JDBC_EMBEDDED_DRIVER) + .driverURL(JDBC_EMBEDDED_URL) + .build(); + } +} diff --git a/server/container/guice/jpa-smtp/src/test/resources/dnsservice.xml b/server/container/guice/jpa-smtp/src/test/resources/dnsservice.xml new file mode 100644 index 00000000000..0978a00b899 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/resources/dnsservice.xml @@ -0,0 +1,29 @@ + + + + + + 8.8.8.8 + 62.210.16.6 + + false + false + 50000 + diff --git a/server/container/guice/jpa-smtp/src/test/resources/fakemailrepositorystore.xml b/server/container/guice/jpa-smtp/src/test/resources/fakemailrepositorystore.xml new file mode 100644 index 00000000000..2d19a802da9 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/resources/fakemailrepositorystore.xml @@ -0,0 +1,31 @@ + + + + + + + + + file + + + + + diff --git a/server/container/guice/jpa-smtp/src/test/resources/keystore b/server/container/guice/jpa-smtp/src/test/resources/keystore new file mode 100644 index 0000000000000000000000000000000000000000..536a6c792b0740ef4273327bf4a61ffc2d6491d8 GIT binary patch literal 2245 zcmchY={pn*7sh8LBQ%y#WJwLmHX~!-n&e4IWZ$x7nXzWyM!ymF9%GH0|)`01HpknC;&o)EW|hTnC0KzVn%TKNE#dU1v||+1tZxX zS_9GsgkCLFCv|_)LvA!S*k!K2h)$={;+p9hHH7Nb0p>KwaVg~IFb3Sc1wDRw9$A){s zjWgyn8QQ_DwD67^UN~?lj{Brp?9aL{)#!V+F@3yd+SXoy#ls2T};RV4e2y4MYI1_L5*8Y+3@jZ}Jq=k;pjN{&W6V&8CnMam*;{LK8_ zVM=cij+9`Yn?R}TQ&+mUIg*K2CR|gqXqw>>3OJI|3T0Q6?~|~GQ+Cq*Ub{W= z#tEY5JH3B7<^Ay^isK!NQlyqlK>%jK4bn-JJ1I_tg1E53mrrAfv?W-!v5v*W1PD^o zxAg%m|LiTHI$`?t4_QyHAX{D{qH>>39tRp>KI;&`pMqjM%_S@a>jO>` z6pB-cdX{xVxy#YMXTrC-^vxG;KHTzHJl8ZO(ySb{-z~l#bcPwmZz!xT*qai`@=~g7 zm%`Wwk)!3E8#0=esd0RL9=xO}l_gdqO`CGH7ked&sARd)5kT$wm= z(V}s9O156MBTz(2khxa8_$Q`dZatu&qt;^pD<4J1$qXsr6Vb23Hu=&yB~!VNc_Jq7 z>VHqD5r3dce|yB1wtClTIY>%O@DHRB{=}X}6o%-w9had83mD84mrS?s_A(A^%{Ybf zRT$$U8`bB!I?xkRBP`95KfExp?{qx}b$oLcb-j z058_v&mR{oY2ohUgL4l=i3{_fF(`FqRg~I!WempdH=@zXD*wg*_c%nL)ISY5{1;#% zkPm<&0%0H`5C}-{<*=1KBbO?SE#xkKMXvqKHKh)AwKZ^R?x7Gq zEJ*}Q`i!-;D;`bn<_(PMs?Z!Azhb;wGdEjk+VigAO}tt$&0gSSAkd^Qu!YeAVl>_P zq$(ep;B$ZZRcA%4lYiy6#UI5)x3Z~7q5Zti`7%_(oi!vm`e!I-%8fY0(DZ6xzl)3s zC8vu)lBpgh%sJWw?xJ&^Lf|}E;FK>dP{OL^>8>odoE0JSm(A1w7;@mTwWsWTaS38liiOoY7+EQJp|1|ONst!#A z0&q=oUM&(2S+u)9)NE3)LgN5Iy~&PWa%6*-3MUjfcyByu7b)f3tpKXQeTd-2|17(3qjJ zuCdt!7~*+Jj-k$)2}|B;vFe5_aZzP>x+f-|h}*dnJi&WkeY1Xb&&jLmqkgpE0spgY zybxo}kn!S$8P;k(zWJ(t|K7IXP**)mv%t;DM3PJALygR(3trmZ)bjb(P7m4wUZX6{ zTa^)O + + + + + + + postmaster@localhost + + + + 20 + + + + + + + + + transport + + + + transport + + + + + + + + file://var/mail/error/ + + + + + + + X-UserIsAuth + true + + + bcc + + + X-WasSigned + true + + + bcc + + + + + outgoing + 5 minutes + 10 minutes + 45 minutes + 2 hours + 3 hours + 6 hours + 0 + 0 + 1 + false + bounces + + + + + + + none + true + true + + + file://var/mail/address-error/ + + + + + + none + + + file://var/mail/relay-denied/ + Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation + + + + + + false + + + + + + diff --git a/server/container/guice/jpa-smtp/src/test/resources/mailrepositorystore.xml b/server/container/guice/jpa-smtp/src/test/resources/mailrepositorystore.xml new file mode 100644 index 00000000000..3ca4a1d0056 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/resources/mailrepositorystore.xml @@ -0,0 +1,31 @@ + + + + + + + + + file + + + + + diff --git a/server/container/guice/jpa-smtp/src/test/resources/managesieveserver.xml b/server/container/guice/jpa-smtp/src/test/resources/managesieveserver.xml new file mode 100644 index 00000000000..ec57e0947f9 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/resources/managesieveserver.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + managesieveserver + + 0.0.0.0:4190 + + 200 + + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + SunX509 + + + + 360 + + + 0 + + + 0 + 0 + true + + + + + + diff --git a/server/container/guice/jpa-smtp/src/test/resources/smtpserver.xml b/server/container/guice/jpa-smtp/src/test/resources/smtpserver.xml new file mode 100644 index 00000000000..a3d4b8f05a0 --- /dev/null +++ b/server/container/guice/jpa-smtp/src/test/resources/smtpserver.xml @@ -0,0 +1,105 @@ + + + + + + + smtpserver-global + 0.0.0.0:1025 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + false + 0.0.0.0/0 + true + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-TLS + 0.0.0.0:10465 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-authenticated + 0.0.0.0:1587 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + + diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml index 58241293a0f..76fd74e8465 100644 --- a/server/container/guice/pom.xml +++ b/server/container/guice/pom.xml @@ -90,6 +90,11 @@ james-server-guice-webadmin ${project.version} + + ${project.groupId} + james-server-jpa-common-guice + ${project.version} + @@ -101,7 +106,9 @@ mailbox mailet memory-guice + jpa-common-guice jpa-guice + jpa-smtp onami protocols/imap protocols/jmap