JAMES-1838 Deny shared mailbox accesses

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1bafdc17
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1bafdc17
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1bafdc17

Branch: refs/heads/master
Commit: 1bafdc175ed69a6a6fe0f3c6479011e55853fc3d
Parents: 9843187
Author: Benoit Tellier <[email protected]>
Authored: Wed Oct 19 17:17:26 2016 +0200
Committer: Benoit Tellier <[email protected]>
Committed: Fri Oct 21 17:01:08 2016 +0200

----------------------------------------------------------------------
 .../DeniedAccessOnSharedMailboxException.java   | 23 ++++++++++++++++++++
 .../apache/james/imap/main/PathConverter.java   |  3 +++
 .../james/imap/main/PathConverterTest.java      | 15 +++++++++++++
 3 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1bafdc17/protocols/imap/src/main/java/org/apache/james/imap/main/DeniedAccessOnSharedMailboxException.java
----------------------------------------------------------------------
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/main/DeniedAccessOnSharedMailboxException.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/main/DeniedAccessOnSharedMailboxException.java
new file mode 100644
index 0000000..da71a70
--- /dev/null
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/main/DeniedAccessOnSharedMailboxException.java
@@ -0,0 +1,23 @@
+/****************************************************************
+ * 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.imap.main;
+
+public class DeniedAccessOnSharedMailboxException extends RuntimeException {
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bafdc17/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
----------------------------------------------------------------------
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java 
b/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
index 5866ee9..d348fbc 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
@@ -86,6 +86,9 @@ public class PathConverter {
     }
 
     private MailboxPath buildMailboxPath(String namespace, String user, String 
mailboxName) {
+        if (!namespace.equals(MailboxConstants.USER_NAMESPACE)) {
+            throw new DeniedAccessOnSharedMailboxException();
+        }
         return new MailboxPath(namespace, user, 
sanitizeMailboxName(mailboxName));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bafdc17/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
----------------------------------------------------------------------
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
index 0f6bae1..11515d4 100644
--- 
a/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
@@ -29,7 +29,10 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 public class PathConverterTest {
 
@@ -39,6 +42,7 @@ public class PathConverterTest {
     private ImapSession imapSession;
     private MailboxSession mailboxSession;
     private PathConverter pathConverter;
+    @Rule public ExpectedException expectedException = 
ExpectedException.none();
 
     @Before
     public void setUp() {
@@ -71,6 +75,7 @@ public class PathConverterTest {
             .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USERNAME, mailboxName));
     }
 
+    @Ignore("Shared mailbox is not supported yet")
     @Test
     public void buildFullPathShouldAcceptNamespacePrefix() {
         assertThat(pathConverter.buildFullPath("#"))
@@ -83,6 +88,7 @@ public class PathConverterTest {
             .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USERNAME, ""));
     }
 
+    @Ignore("Shared mailbox is not supported yet")
     @Test
     public void buildFullPathShouldAcceptNamespaceAlone() {
         String namespace = "#any";
@@ -96,6 +102,7 @@ public class PathConverterTest {
             .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USERNAME, ""));
     }
 
+    @Ignore("Shared mailbox is not supported yet")
     @Test
     public void buildFullPathShouldAcceptNamespaceAndDelimiter() {
         String namespace = "#any";
@@ -110,6 +117,7 @@ public class PathConverterTest {
             .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USERNAME, mailboxName));
     }
 
+    @Ignore("Shared mailbox is not supported yet")
     @Test
     public void buildFullPathShouldAcceptFullAbsolutePath() {
         String namespace = "#any";
@@ -132,6 +140,7 @@ public class PathConverterTest {
             .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USERNAME, mailboxName));
     }
 
+    @Ignore("Shared mailbox is not supported yet")
     @Test
     public void buildFullPathShouldAcceptAbsolutePathWithSubFolder() {
         String namespace = "#any";
@@ -139,4 +148,10 @@ public class PathConverterTest {
         assertThat(pathConverter.buildFullPath(namespace + PATH_DELIMITER + 
mailboxName))
             .isEqualTo(new MailboxPath(namespace, null, mailboxName));
     }
+
+    @Test
+    public void buildFullPathShouldDenyMailboxPathNotBelongingToTheUser() {
+        expectedException.expect(DeniedAccessOnSharedMailboxException.class);
+        pathConverter.buildFullPath("#any");
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to