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 ad...@apache.org on 2017/02/09 13:01:19 UTC

[4/7] james-project git commit: JAMES-1925 Split user provisioning and mailboxes provisioning filters

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
index 82828d1..80570cc 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
@@ -5,26 +5,26 @@ Feature: Download GET
   Background:
     Given a domain named "domain.tld"
     And a connected user "username@domain.tld"
-    And "username@domain.tld" has a mailbox "inbox"
+    And "username@domain.tld" has a mailbox "INBOX"
 
   Scenario: Getting an attachment previously stored
-    Given "username@domain.tld" mailbox "inbox" contains a message "1" with an attachment "2"
+    Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
     When "username@domain.tld" downloads "2"
     Then the user should receive that attachment
 
   Scenario: Getting an attachment with an unknown blobId
-    Given "username@domain.tld" mailbox "inbox" contains a message "1" with an attachment "2"
+    Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
     When "username@domain.tld" downloads "2" with a valid authentication token but a bad blobId
     Then the user should receive a not found response
 
   Scenario: Getting an attachment previously stored with a desired name
-    Given "username@domain.tld" mailbox "inbox" contains a message "1" with an attachment "2"
+    Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
     When "username@domain.tld" downloads "2" with "myFileName.txt" name
     Then the user should receive that attachment
     And the attachment is named "myFileName.txt"
 
   Scenario: Getting an attachment previously stored with a non ASCII name
-    Given "username@domain.tld" mailbox "inbox" contains a message "1" with an attachment "2"
+    Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
     When "username@domain.tld" downloads "2" with "\u062f\u064a\u0646\u0627\u0635\u0648\u0631.odt" name
     Then the user should receive that attachment
     And the attachment is named "\u062f\u064a\u0646\u0627\u0635\u0648\u0631.odt"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
index c748014..12d655d 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadPost.feature
@@ -5,13 +5,13 @@ Feature: Alternative authentication mechanism for getting attachment via a POST
   Background:
     Given a domain named "domain.tld"
     And a connected user "username@domain.tld"
-    And "username@domain.tld" has a mailbox "inbox"
+    And "username@domain.tld" has a mailbox "INBOX"
 
   Scenario: Asking for an attachment access token with an unknown blobId
     When "username@domain.tld" asks for a token for attachment "123"
     Then the user should receive a not found response
 
   Scenario: Asking for an attachment access token with a previously stored blobId
-    Given "username@domain.tld" mailbox "inbox" contains a message "1" with an attachment "2"
+    Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
     When "username@domain.tld" asks for a token for attachment "2"
     Then the user should receive an attachment access token

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index 0cd93d1..8c0bb04 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -5,16 +5,16 @@ Feature: GetMessages method
   Background:
     Given a domain named "domain.tld"
     And a connected user "username@domain.tld"
-    And "username@domain.tld" has a mailbox "inbox"
+    And "username@domain.tld" has a mailbox "INBOX"
 
   Scenario: Retrieving a message in several mailboxes should return a single message in these mailboxes
     Given "username@domain.tld" has a mailbox "custom"
-    And the user has a message "m1" in "inbox" and "custom" mailboxes with subject "my test subject", content "testmail"
+    And the user has a message "m1" in "INBOX" and "custom" mailboxes with subject "my test subject", content "testmail"
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
     And the id of the message is "m1"
-    And the message is in "custom,inbox" mailboxes
+    And the message is in "custom,INBOX" mailboxes
 
   Scenario: Retrieving messages with a non null accountId should return a NotSupported error
     When the user ask for messages using its accountId
@@ -42,7 +42,7 @@ Feature: GetMessages method
     And the notFound list should contain the requested message id
 
   Scenario: Retrieving message should return messages when exists
-    Given the user has a message "m1" in "inbox" mailbox with subject "my test subject", content "testmail"
+    Given the user has a message "m1" in "INBOX" mailbox with subject "my test subject", content "testmail"
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -76,9 +76,9 @@ Feature: GetMessages method
 
     Examples:
       |mailbox |content-type |subject           |subject-header  |content                                                                                                                         |preview                                                                                      |
-      |"inbox" |"text/html"  |"my test subject" |my test subject |"This is a <b>HTML</b> mail"                                                                                                    |"This is a HTML mail"                                                                        |
-      |"inbox" |"text/html"  |"my test subject" |my test subject |"This is a <b>HTML</b> mail containing <u>underlined part</u>, <i>italic part</i> and <u><i>underlined AND italic part</i></u>" |"This is a HTML mail containing underlined part, italic part and underlined AND italic part" |
-      |"inbox" |"text/html"  |"my test subject" |my test subject |"This is a <ganan>HTML</b> mail"                                                                                                |"This is a HTML mail"                                                                        |
+      |"INBOX" |"text/html"  |"my test subject" |my test subject |"This is a <b>HTML</b> mail"                                                                                                    |"This is a HTML mail"                                                                        |
+      |"INBOX" |"text/html"  |"my test subject" |my test subject |"This is a <b>HTML</b> mail containing <u>underlined part</u>, <i>italic part</i> and <u><i>underlined AND italic part</i></u>" |"This is a HTML mail containing underlined part, italic part and underlined AND italic part" |
+      |"INBOX" |"text/html"  |"my test subject" |my test subject |"This is a <ganan>HTML</b> mail"                                                                                                |"This is a HTML mail"                                                                        |
 
   Scenario Outline: Retrieving message should return preview with tags when text message
     Given the user has a message "m1" in <mailbox> mailbox with content-type <content-type> subject <subject>, content <content>
@@ -89,10 +89,10 @@ Feature: GetMessages method
 
     Examples:
       |mailbox |content-type |subject           |content                                                                               |preview                                                                               |
-      |"inbox" |"text/plain" |"my test subject" |"Here is a listing of HTML tags : <b>jfjfjfj</b>, <i>jfhdgdgdfj</i>, <u>jfjaaafj</u>" |"Here is a listing of HTML tags : <b>jfjfjfj</b>, <i>jfhdgdgdfj</i>, <u>jfjaaafj</u>" |
+      |"INBOX" |"text/plain" |"my test subject" |"Here is a listing of HTML tags : <b>jfjfjfj</b>, <i>jfhdgdgdfj</i>, <u>jfjaaafj</u>" |"Here is a listing of HTML tags : <b>jfjfjfj</b>, <i>jfhdgdgdfj</i>, <u>jfjaaafj</u>" |
 
   Scenario: Retrieving message should filter properties
-    Given the user has a message "m1" in "inbox" mailbox with subject "my test subject", content "testmail"
+    Given the user has a message "m1" in "INBOX" mailbox with subject "my test subject", content "testmail"
     When the user is getting messages "m1" with properties "id, subject"
     Then no error is returned
     And the list should contain 1 message
@@ -105,7 +105,7 @@ Feature: GetMessages method
     And the property "date" of the message is null
 
   Scenario: Retrieving message should filter header properties
-    Given the user has a message "m1" in "inbox" mailbox with subject "my test subject", content "testmail", headers
+    Given the user has a message "m1" in "INBOX" mailbox with subject "my test subject", content "testmail", headers
       |From    |user@domain.tld |
       |header1 |Header1Content  |
       |HEADer2 |Header2Content  |
@@ -123,14 +123,14 @@ Feature: GetMessages method
     And the property "date" of the message is null
 
   Scenario: Retrieving message should return not found when id does not match
-    Given the user has a message "m1" in "inbox" mailbox with subject "my test subject", content "testmail"
+    Given the user has a message "m1" in "INBOX" mailbox with subject "my test subject", content "testmail"
     When the user ask for an unknown message
     Then no error is returned
     And the list of messages is empty
     And the notFound list should contain the requested message id
     
   Scenario: Retrieving message should return mandatory properties when not asked
-    Given the user has a message "m1" in "inbox" mailbox with subject "my test subject", content "testmail"
+    Given the user has a message "m1" in "INBOX" mailbox with subject "my test subject", content "testmail"
     When the user is getting messages "m1" with properties "subject"
     Then no error is returned
     And the list should contain 1 message
@@ -138,7 +138,7 @@ Feature: GetMessages method
     And the subject of the message is "my test subject"
 
   Scenario: Retrieving message should return attachments when some
-    Given the user has a message "m1" in "inbox" mailbox with two attachments
+    Given the user has a message "m1" in "INBOX" mailbox with two attachments
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -160,7 +160,7 @@ Feature: GetMessages method
       |isInline |true                                       |
 
   Scenario: Retrieving message should return attachments and html body when some attachments and html message
-    Given the user has a message "m1" in "inbox" mailbox with two attachments
+    Given the user has a message "m1" in "INBOX" mailbox with two attachments
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -171,7 +171,7 @@ Feature: GetMessages method
     And the htmlBody of the message is "<b>html</b>\n"
 
   Scenario: Retrieving message should return attachments and text body when some attachments and text message
-    Given the user has a message "m1" in "inbox" mailbox with two attachments in text
+    Given the user has a message "m1" in "INBOX" mailbox with two attachments in text
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -182,7 +182,7 @@ Feature: GetMessages method
     And the property "htmlBody" of the message is null
 
   Scenario: Retrieving message should return attachments and both html/text body when some attachments and both html/text message
-    Given the user has a multipart message "m1" in "inbox" mailbox
+    Given the user has a multipart message "m1" in "INBOX" mailbox
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -193,7 +193,7 @@ Feature: GetMessages method
     And the htmlBody of the message is "<i>blabla</i>\n<b>bloblo</b>\n"
 
   Scenario: Retrieving message should return image and html body when multipart/alternative where first part is multipart/related with html and image
-    Given the user has a multipart/related message "m1" in "inbox" mailbox
+    Given the user has a multipart/related message "m1" in "INBOX" mailbox
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -204,7 +204,7 @@ Feature: GetMessages method
     And the htmlBody of the message is "<html>multipart/related content</html>\n"
 
   Scenario: Retrieving message should return textBody and htmlBody when incoming mail have an inlined HTML and text body without Content-ID
-    Given the user has a message "m1" in "inbox" mailbox, composed of a multipart with inlined text part and inlined html part
+    Given the user has a message "m1" in "INBOX" mailbox, composed of a multipart with inlined text part and inlined html part
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -212,20 +212,20 @@ Feature: GetMessages method
     And the htmlBody of the message is "<html>Hello html body</html>\n"
     
   Scenario: Retrieving message with more than 1000 char by line should return message when exists
-    Given the user has a message "m1" in "inbox" mailbox beginning by a long line
+    Given the user has a message "m1" in "INBOX" mailbox beginning by a long line
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
     And the id of the message is "m1"
 
   Scenario:
-    Given the user has a message "m1" in "inbox" mailbox with two same attachments in text
+    Given the user has a message "m1" in "INBOX" mailbox with two same attachments in text
     When the user ask for messages "m1"
     Then no error is returned
     And the list of attachments of the message contains 2 attachments
 
   Scenario: Retrieving message should read content from multipart when some inline attachment and both html/text multipart
-    Given the user has a message "m1" in "inbox" mailbox with plain/text inline attachment
+    Given the user has a message "m1" in "INBOX" mailbox with plain/text inline attachment
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
@@ -233,7 +233,7 @@ Feature: GetMessages method
     And the htmlBody of the message is "<i>blabla</i>\n<b>bloblo</b>\n"
 
   Scenario: Retrieving message should find html body when text in main multipart and html in inner multipart
-    Given the user has a message "m1" in "inbox" mailbox with text in main multipart and html in inner multipart
+    Given the user has a message "m1" in "INBOX" mailbox with text in main multipart and html in inner multipart
     When the user ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
new file mode 100644
index 0000000..7a91514
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.jmap;
+
+import java.util.List;
+
+import org.apache.james.mailbox.model.MailboxConstants;
+
+import com.google.common.collect.ImmutableList;
+
+public interface DefaultMailboxes {
+
+    String INBOX = MailboxConstants.INBOX;
+    String OUTBOX = "Outbox";
+    String SENT = "Sent";
+    String TRASH = "Trash";
+    String DRAFTS = "Drafts";
+
+    List<String> DEFAULT_MAILBOXES = ImmutableList.of(INBOX, OUTBOX, SENT, TRASH, DRAFTS);
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
new file mode 100644
index 0000000..e12014c
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.jmap;
+
+import java.io.IOException;
+import java.util.Optional;
+import java.util.function.Function;
+
+import javax.inject.Inject;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxSession.User;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Throwables;
+
+public class DefaultMailboxesProvisioningFilter implements Filter {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMailboxesProvisioningFilter.class);
+    private final MailboxManager mailboxManager;
+
+    @Inject
+    @VisibleForTesting DefaultMailboxesProvisioningFilter(MailboxManager mailboxManager) {
+        this.mailboxManager = mailboxManager;
+    }
+    
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+    
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        Optional<MailboxSession> session = Optional.ofNullable((MailboxSession)request.getAttribute(AuthenticationFilter.MAILBOX_SESSION));
+        session.ifPresent(this::createMailboxesIfNeeded);
+        chain.doFilter(request, response);
+    }
+    
+    @VisibleForTesting
+    void createMailboxesIfNeeded(MailboxSession session) {
+        try {
+            User user = session.getUser();
+            createDefaultMailboxes(user);
+        } catch (MailboxException e) {
+            throw Throwables.propagate(e);
+        }
+    }
+
+    private void createDefaultMailboxes(User user) throws MailboxException {
+        MailboxSession session = mailboxManager.createSystemSession(user.getUserName(), LOGGER);
+        DefaultMailboxes.DEFAULT_MAILBOXES.stream()
+            .map(toMailboxPath(session))
+            .filter(mailboxPath -> mailboxDoesntExist(mailboxPath, session))
+            .forEach(mailboxPath -> createMailbox(mailboxPath, session));
+    }
+
+    private boolean mailboxDoesntExist(MailboxPath mailboxPath, MailboxSession session) {
+        try {
+            return !mailboxManager.mailboxExists(mailboxPath, session);
+        } catch (MailboxException e) {
+            throw Throwables.propagate(e);
+        }
+    }
+
+    private Function<String, MailboxPath> toMailboxPath(MailboxSession session) {
+        return mailbox -> new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), mailbox);
+    }
+    
+    private void createMailbox(MailboxPath mailboxPath, MailboxSession session) {
+        try {
+            mailboxManager.createMailbox(mailboxPath, session);
+        } catch (MailboxException e) {
+            throw Throwables.propagate(e);
+        }
+    }
+
+    @Override
+    public void destroy() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
index 25242f4..de3ac75 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
@@ -40,7 +40,7 @@ public class JMAPServer implements Configurable {
     @Inject
     private JMAPServer(JMAPConfiguration jmapConfiguration,
                        AuthenticationServlet authenticationServlet, JMAPServlet jmapServlet, DownloadServlet downloadServlet, UploadServlet uploadServlet,
-                       AuthenticationFilter authenticationFilter, UserProvisioningFilter userProvisioningFilter) {
+                       AuthenticationFilter authenticationFilter, UserProvisioningFilter userProvisioningFilter, DefaultMailboxesProvisioningFilter defaultMailboxesProvisioningFilter) {
 
         server = JettyHttpServer.create(
                 configurationBuilderFor(jmapConfiguration)
@@ -54,6 +54,7 @@ public class JMAPServer implements Configurable {
                         .filter(JMAPUrls.JMAP)
                             .with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("OPTIONS").only()))
                             .and(userProvisioningFilter)
+                            .and(defaultMailboxesProvisioningFilter)
                             .only()
                         .serveAsOneLevelTemplate(JMAPUrls.DOWNLOAD)
                             .with(downloadServlet)

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
index 6145a79..726d37f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
@@ -21,7 +21,6 @@ package org.apache.james.jmap;
 import java.io.IOException;
 import java.util.Optional;
 import java.util.UUID;
-import java.util.function.Function;
 
 import javax.inject.Inject;
 import javax.servlet.Filter;
@@ -31,33 +30,24 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
-import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.user.api.AlreadyExistInUsersRepositoryException;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
 
 public class UserProvisioningFilter implements Filter {
 
-    private static final ImmutableList<String> DEFAULT_MAILBOXES = ImmutableList.of("INBOX", "Outbox", "Sent", "Trash");
-    private static final Logger LOGGER = LoggerFactory.getLogger(UserProvisioningFilter.class);
     private final UsersRepository usersRepository;
-    private final MailboxManager mailboxManager;
 
     @Inject
-    @VisibleForTesting UserProvisioningFilter(UsersRepository usersRepository, MailboxManager mailboxManager) {
+    @VisibleForTesting UserProvisioningFilter(UsersRepository usersRepository) {
         this.usersRepository = usersRepository;
-        this.mailboxManager = mailboxManager;
     }
     
     @Override
@@ -91,7 +81,6 @@ public class UserProvisioningFilter implements Filter {
 
     private void createAccount(User user) throws UsersRepositoryException, BadCredentialsException, MailboxException {
         createUser(user);
-        createDefaultMailboxes(user);
     }
 
     private void createUser(User user) throws UsersRepositoryException {
@@ -101,25 +90,6 @@ public class UserProvisioningFilter implements Filter {
     private String generatePassword() {
         return UUID.randomUUID().toString();
     }
-    
-    private void createDefaultMailboxes(User user) throws BadCredentialsException, MailboxException {
-        MailboxSession session = mailboxManager.createSystemSession(user.getUserName(), LOGGER);
-        DEFAULT_MAILBOXES.stream()
-            .map(toMailboxPath(session))
-            .forEach(mailboxPath -> createMailbox(mailboxPath, session));
-    }
-
-    private Function<String, MailboxPath> toMailboxPath(MailboxSession session) {
-        return mailbox -> new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), mailbox);
-    }
-    
-    private void createMailbox(MailboxPath mailboxPath, MailboxSession session) {
-        try {
-            mailboxManager.createMailbox(mailboxPath, session);
-        } catch (MailboxException e) {
-            throw Throwables.propagate(e);
-        }
-    }
 
     @Override
     public void destroy() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterThreadTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterThreadTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterThreadTest.java
new file mode 100644
index 0000000..ab0c546
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterThreadTest.java
@@ -0,0 +1,268 @@
+/****************************************************************
+ * 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.jmap;
+
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.BadCredentialsException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLCommand;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
+import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxMetaData;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxQuery;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+import com.google.testing.threadtester.AnnotatedTestRunner;
+import com.google.testing.threadtester.ThreadedAfter;
+import com.google.testing.threadtester.ThreadedBefore;
+import com.google.testing.threadtester.ThreadedMain;
+import com.google.testing.threadtester.ThreadedSecondary;
+
+public class DefaultMailboxesProvisioningFilterThreadTest {
+
+    private DefaultMailboxesProvisioningFilter sut;
+    private MailboxSession session;
+    private MailboxManager mailboxManager;
+
+    @ThreadedBefore
+    public void before() {
+        session = new MockMailboxSession("username");
+        mailboxManager = new FakeMailboxManager(session) ;
+        sut = new DefaultMailboxesProvisioningFilter(mailboxManager);
+    }
+    
+    @ThreadedMain
+    public void mainThread() {
+        sut.createMailboxesIfNeeded(session);
+    }
+    
+    @ThreadedSecondary
+    public void secondThread() {
+        sut.createMailboxesIfNeeded(session);
+    }
+    
+    @ThreadedAfter
+    public void after() {
+        // Exception is thrown if test fails
+    }
+    
+    @Test
+    public void testConcurrentAccessToFilterShouldNotThrow() {
+        AnnotatedTestRunner runner = new AnnotatedTestRunner();
+        runner.runTests(this.getClass(), DefaultMailboxesProvisioningFilter.class);
+    }
+    
+    private static class FakeMailboxManager implements MailboxManager {
+        private MailboxSession mailboxSession;
+
+        public FakeMailboxManager(MailboxSession mailboxSession) {
+            this.mailboxSession = mailboxSession;
+        }
+
+        @Override
+        public EnumSet<SearchCapabilities> getSupportedSearchCapabilities() {
+            return EnumSet.noneOf(SearchCapabilities.class);
+        }
+        
+        @Override
+        public void startProcessingRequest(MailboxSession session) {
+        }
+
+        @Override
+        public void endProcessingRequest(MailboxSession session) {
+        }
+
+        @Override
+        public void addListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public void removeListener(MailboxPath mailboxPath, MailboxListener listner, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public void addGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public void removeGlobalListener(MailboxListener listner, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public char getDelimiter() {
+            return 0;
+        }
+
+        @Override
+        public MessageManager getMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public MessageManager getMailbox(MailboxId mailboxId, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public void createMailbox(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
+        }
+
+        @Override
+        public void deleteMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public void renameMailbox(MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public List<MessageRange> copyMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MessageRange> copyMessages(MessageRange set, MailboxId from, MailboxId to, MailboxSession session)
+                throws MailboxException {
+            return null;
+        }
+        
+        @Override
+        public List<MessageRange> moveMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MailboxMetaData> search(MailboxQuery expression, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public boolean mailboxExists(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+            return false;
+        }
+
+        @Override
+        public MailboxSession createSystemSession(String userName, Logger log) throws BadCredentialsException, MailboxException {
+            return mailboxSession;
+        }
+
+        @Override
+        public MailboxSession login(String userid, String passwd, Logger log) throws BadCredentialsException, MailboxException {
+            return null;
+        }
+
+        @Override
+        public void logout(MailboxSession session, boolean force) throws MailboxException {
+        }
+
+        @Override
+        public boolean hasRight(MailboxPath mailboxPath, MailboxACLRight right, MailboxSession session) throws MailboxException {
+            return false;
+        }
+
+        @Override
+        public MailboxACLRights myRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public MailboxACLRights[] listRigths(MailboxPath mailboxPath, MailboxACLEntryKey identifier, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public void setRights(MailboxPath mailboxPath, MailboxACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException {
+        }
+
+        @Override
+        public List<MailboxPath> list(MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public EnumSet<MailboxCapabilities> getSupportedMailboxCapabilities() {
+            return null;
+        }
+        
+        @Override
+        public EnumSet<MessageCapabilities> getSupportedMessageCapabilities() {
+            return null;
+        }
+
+        @Override
+        public List<MailboxAnnotation> getAllAnnotations(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public void updateAnnotations(MailboxPath mailboxPath, MailboxSession session, List<MailboxAnnotation> mailboxAnnotations) throws MailboxException {
+            
+        }
+
+        @Override
+        public boolean hasCapability(MailboxCapabilities capability) {
+            return false;
+        }
+
+        @Override
+        public List<MessageId> search(MultimailboxesSearchQuery expression, MailboxSession session, long limit) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath mailboxPath, MailboxSession session,
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath mailboxPath, MailboxSession session,
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
+            return false;
+        }
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
index ffc37b0..b5f6964 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
@@ -29,7 +29,6 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.lib.mock.InMemoryUsersRepository;
 import org.junit.Before;
@@ -43,8 +42,7 @@ public class UserProvisioningFilterTest {
     @Before
     public void setup() {
         usersRepository = new InMemoryUsersRepository();
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        sut = new UserProvisioningFilter(usersRepository, mailboxManager);
+        sut = new UserProvisioningFilter(usersRepository);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/844efe2a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterThreadTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterThreadTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterThreadTest.java
index eb5ec5c..d375a09 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterThreadTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterThreadTest.java
@@ -18,33 +18,10 @@
  ****************************************************************/
 package org.apache.james.jmap;
 
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.exception.BadCredentialsException;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.apache.james.mailbox.model.MailboxACL.MailboxACLCommand;
-import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
-import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
-import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
-import org.apache.james.mailbox.model.MailboxAnnotation;
-import org.apache.james.mailbox.model.MailboxAnnotationKey;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MailboxQuery;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.user.lib.mock.InMemoryUsersRepository;
 import org.junit.Test;
-import org.slf4j.Logger;
 
 import com.google.testing.threadtester.AnnotatedTestRunner;
 import com.google.testing.threadtester.ThreadedAfter;
@@ -57,14 +34,12 @@ public class UserProvisioningFilterThreadTest {
     private UserProvisioningFilter sut;
     private InMemoryUsersRepository usersRepository;
     private MailboxSession session;
-    private MailboxManager mailboxManager;
 
     @ThreadedBefore
     public void before() {
         usersRepository = new InMemoryUsersRepository();
         session = new MockMailboxSession("username");
-        mailboxManager = new FakeMailboxManager(session) ;
-        sut = new UserProvisioningFilter(usersRepository, mailboxManager);
+        sut = new UserProvisioningFilter(usersRepository);
     }
     
     @ThreadedMain
@@ -87,185 +62,5 @@ public class UserProvisioningFilterThreadTest {
         AnnotatedTestRunner runner = new AnnotatedTestRunner();
         runner.runTests(this.getClass(), UserProvisioningFilter.class);
     }
-    
-    private static class FakeMailboxManager implements MailboxManager {
-        private MailboxSession mailboxSession;
-
-        public FakeMailboxManager(MailboxSession mailboxSession) {
-            this.mailboxSession = mailboxSession;
-        }
-
-        @Override
-        public EnumSet<SearchCapabilities> getSupportedSearchCapabilities() {
-            return EnumSet.noneOf(SearchCapabilities.class);
-        }
-        
-        @Override
-        public void startProcessingRequest(MailboxSession session) {
-        }
-
-        @Override
-        public void endProcessingRequest(MailboxSession session) {
-        }
-
-        @Override
-        public void addListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public void removeListener(MailboxPath mailboxPath, MailboxListener listner, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public void addGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public void removeGlobalListener(MailboxListener listner, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public char getDelimiter() {
-            return 0;
-        }
-
-        @Override
-        public MessageManager getMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public MessageManager getMailbox(MailboxId mailboxId, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public void createMailbox(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
-        }
-
-        @Override
-        public void deleteMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public void renameMailbox(MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public List<MessageRange> copyMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public List<MessageRange> copyMessages(MessageRange set, MailboxId from, MailboxId to, MailboxSession session)
-                throws MailboxException {
-            return null;
-        }
-        
-        @Override
-        public List<MessageRange> moveMessages(MessageRange set, MailboxPath from, MailboxPath to, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public List<MailboxMetaData> search(MailboxQuery expression, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public boolean mailboxExists(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
-            return false;
-        }
-
-        @Override
-        public MailboxSession createSystemSession(String userName, Logger log) throws BadCredentialsException, MailboxException {
-            return mailboxSession;
-        }
-
-        @Override
-        public MailboxSession login(String userid, String passwd, Logger log) throws BadCredentialsException, MailboxException {
-            return null;
-        }
-
-        @Override
-        public void logout(MailboxSession session, boolean force) throws MailboxException {
-        }
-
-        @Override
-        public boolean hasRight(MailboxPath mailboxPath, MailboxACLRight right, MailboxSession session) throws MailboxException {
-            return false;
-        }
-
-        @Override
-        public MailboxACLRights myRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public MailboxACLRights[] listRigths(MailboxPath mailboxPath, MailboxACLEntryKey identifier, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public void setRights(MailboxPath mailboxPath, MailboxACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException {
-        }
-
-        @Override
-        public List<MailboxPath> list(MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public EnumSet<MailboxCapabilities> getSupportedMailboxCapabilities() {
-            return null;
-        }
-        
-        @Override
-        public EnumSet<MessageCapabilities> getSupportedMessageCapabilities() {
-            return null;
-        }
-
-        @Override
-        public List<MailboxAnnotation> getAllAnnotations(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public void updateAnnotations(MailboxPath mailboxPath, MailboxSession session, List<MailboxAnnotation> mailboxAnnotations) throws MailboxException {
-            
-        }
-
-        @Override
-        public boolean hasCapability(MailboxCapabilities capability) {
-            return false;
-        }
-
-        @Override
-        public List<MessageId> search(MultimailboxesSearchQuery expression, MailboxSession session, long limit) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath mailboxPath, MailboxSession session,
-                Set<MailboxAnnotationKey> keys) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath mailboxPath, MailboxSession session,
-                Set<MailboxAnnotationKey> keys) throws MailboxException {
-            return null;
-        }
-
-        @Override
-        public boolean hasChildren(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
-            return false;
-        }
-    }
 }
 


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