Author: eric
Date: Mon Apr 27 09:28:26 2015
New Revision: 1676230

URL: http://svn.apache.org/r1676230
Log:
ACL interfaces refactor, patch contributed by Tellier Benoit (MAILBOX-223)

Modified:
    
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
    
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MessageManager.java
    
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
    
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/SimpleMailboxACL.java
    
james/mailbox/trunk/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
    
james/mailbox/trunk/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
    
james/mailbox/trunk/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
    
james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
    
james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
    
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
    
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
    
james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
    
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
    
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
    
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java

Modified: 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxManager.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
 (original)
+++ 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
 Mon Apr 27 09:28:26 2015
@@ -25,10 +25,13 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.MailboxACL;
 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.MessageRange;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.slf4j.Logger;
 
 /**
@@ -249,6 +252,66 @@ public interface MailboxManager extends
     void logout(MailboxSession session, boolean force) throws MailboxException;
 
     /**
+     * Tells whether the given {@link MailboxSession}'s user has the given
+     * {@link MailboxACL.MailboxACLRight} for this {@link MessageManager}'s 
mailbox.
+     *
+     * @param session MailboxSession of the user we want to check 
+     * @param right Right we want to check.
+     * @param session Session of the user we want to check this right against.
+     * @return true if the given {@link MailboxSession}'s user has the given
+     *         {@link MailboxACL.MailboxACLRight} for this {@link 
MessageManager}'s
+     *         mailbox; false otherwise.
+     * @throws MailboxException
+     */
+    public boolean hasRight(MailboxPath mailboxPath, 
MailboxACL.MailboxACLRight right, MailboxSession session) throws 
MailboxException;
+
+    /**
+     * Returns the rights applicable to the user who has sent the current
+     * request on the mailbox designated by this mailboxPath.
+     *
+     * @param mailboxPath Path of the mailbox you want to get your rights on.
+     * @param session The session used to determine the user we should 
retrieve the rights of.
+     * @return the rights applicable to the user who has sent the request,
+     *         returns {@link SimpleMailboxACL#NO_RIGHTS} if
+     *         {@code session.getUser()} is null.
+     * @throws UnsupportedRightException
+     */
+    public abstract MailboxACL.MailboxACLRights myRights(MailboxPath 
mailboxPath, MailboxSession session) throws MailboxException;
+
+    /**
+     * Computes a result suitable for the LISTRIGHTS IMAP command. The result 
is
+     * computed for this mailbox and the given {@code identifier}.
+     *
+     * From RFC 4314 section 3.7:
+     * The first element of the resulting array contains the (possibly empty)
+     * set of rights the identifier will always be granted in the mailbox.
+     * Following this are zero or more right sets the identifier can be granted
+     * in the mailbox. Rights mentioned in the same set are tied together. The
+     * server MUST either grant all tied rights to the identifier in the 
mailbox
+     * or grant none.
+     *
+     * The same right MUST NOT be listed more than once in the LISTRIGHTS
+     * command.
+     *
+     * @param mailboxPath Path of the mailbox you want to get the rights list.
+     * @param identifier
+     *            the identifier from the LISTRIGHTS command.
+     * @param session Right of the user performing the request.
+     * @return result suitable for the LISTRIGHTS IMAP command
+     * @throws UnsupportedRightException
+     */
+    public MailboxACL.MailboxACLRights[] listRigths(MailboxPath mailboxPath, 
MailboxACL.MailboxACLEntryKey identifier, MailboxSession session) throws 
MailboxException;
+
+    /**
+     * Update the Mailbox ACL of the designated mailbox. We can either ADD 
REPLACE or REMOVE entries.
+     *
+     * @param mailboxACLCommand Update to perform.
+     * @throws UnsupportedRightException
+     */
+    void setRights(MailboxPath mailboxPath, MailboxACL.MailboxACLCommand 
mailboxACLCommand, MailboxSession session) throws MailboxException;
+
+
+    /**
      * Return a unmodifiable {@link List} of {@link MailboxPath} objects
      * 
      * @param session

Modified: 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MessageManager.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MessageManager.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MessageManager.java
 (original)
+++ 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MessageManager.java
 Mon Apr 27 09:28:26 2015
@@ -169,63 +169,6 @@ public interface MessageManager {
      */
     MessageResultIterator getMessages(MessageRange set, FetchGroup fetchGroup, 
MailboxSession mailboxSession) throws MailboxException;
 
-    /**
-     * Tells whether the given {@link MailboxSession}'s user has the given
-     * {@link MailboxACLRight} for this {@link MessageManager}'s mailbox.
-     * 
-     * @param right
-     * @param session
-     * @return true if the given {@link MailboxSession}'s user has the given
-     *         {@link MailboxACLRight} for this {@link MessageManager}'s
-     *         mailbox; false otherwise.
-     * @throws MailboxException
-     */
-    public boolean hasRight(MailboxACLRight right, MailboxSession session) 
throws MailboxException;
-
-    /**
-     * Returns the rights applicable to the user who has sent the current
-     * request.
-     * 
-     * @param session
-     * @return the rights applicable to the user who has sent the request,
-     *         returns {@link SimpleMailboxACL#NO_RIGHTS} if
-     *         {@code session.getUser()} is null.
-     * @throws UnsupportedRightException
-     */
-    public abstract MailboxACLRights myRights(MailboxSession session) throws 
MailboxException;
-
-    /**
-     * Computes a result suitable for the LISTRIGHTS IMAP command. The result 
is
-     * computed for this mailbox and the given {@code identifier}.
-     * 
-     * From RFC 4314 section 3.7:
-     * The first element of the resulting array contains the (possibly empty)
-     * set of rights the identifier will always be granted in the mailbox.
-     * Following this are zero or more right sets the identifier can be granted
-     * in the mailbox. Rights mentioned in the same set are tied together. The
-     * server MUST either grant all tied rights to the identifier in the 
mailbox
-     * or grant none.
-     * 
-     * The same right MUST NOT be listed more than once in the LISTRIGHTS
-     * command.
-     * 
-     * @param identifier
-     *            the identifier from the LISTRIGHTS command.
-     * @param session
-     * @return
-     * @throws UnsupportedRightException
-     */
-    public MailboxACLRights[] listRigths(MailboxACLEntryKey identifier, 
MailboxSession session) throws UnsupportedRightException;
-
-    /**
-     * TODO setRights.
-     * 
-     * @param identifier
-     * @param editMode
-     * @param mailboxAclRights
-     * @throws UnsupportedRightException
-     */
-    void setRights(MailboxACLEntryKey identifier, EditMode editMode, 
MailboxACLRights mailboxAclRights) throws UnsupportedRightException;
 
     /**
      * Gets current meta data for the mailbox.<br>

Modified: 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
 (original)
+++ 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
 Mon Apr 27 09:28:26 2015
@@ -205,6 +205,15 @@ public interface MailboxACL {
      * Allows distinguishing between users, groups and special names (see
      * {@link SpecialName}).
      */
+
+    public interface MailboxACLCommand {
+        MailboxACLEntryKey getEntryKey();
+
+        EditMode getEditMode();
+
+        MailboxACLRights getRights();
+    };
+
     enum NameType {
         group, special, user
     };
@@ -241,6 +250,15 @@ public interface MailboxACL {
     public static final char REMOVE_RIGHTS_MARKER = '-';
 
     /**
+     * Apply the given ACL update on current ACL and return the result as a 
new ACL.
+     *
+     * @param aclUpdate Update to perform
+     * @return Copy of current ACL updated
+     * @throws UnsupportedRightException
+     */
+    MailboxACL apply(MailboxACLCommand aclUpdate) throws 
UnsupportedRightException;
+
+    /**
      * Performs the set theoretic operation of relative complement of toRemove
      * {@link MailboxACL} in this {@link MailboxACL}.
      * 

Modified: 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/SimpleMailboxACL.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/SimpleMailboxACL.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/SimpleMailboxACL.java
 (original)
+++ 
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/SimpleMailboxACL.java
 Mon Apr 27 09:28:26 2015
@@ -27,7 +27,6 @@ import java.util.Map.Entry;
 import java.util.Properties;
 
 import org.apache.james.mailbox.exception.UnsupportedRightException;
-import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
 
 /**
  * Default implementation of {@link MailboxACL}.
@@ -798,6 +797,54 @@ public class SimpleMailboxACL implements
 
     }
 
+    public static class SimpleMailboxACLCommand implements MailboxACLCommand {
+        private MailboxACLEntryKey key;
+        private EditMode editMode;
+        private MailboxACLRights rights;
+
+        public SimpleMailboxACLCommand(MailboxACLEntryKey key, EditMode 
editMode, MailboxACLRights rights) {
+            this.key = key;
+            this.editMode = editMode;
+            this.rights = rights;
+        }
+
+        @Override
+        public MailboxACLEntryKey getEntryKey() {
+            return key;
+        }
+
+        @Override
+        public EditMode getEditMode() {
+            return editMode;
+        }
+
+        @Override
+        public MailboxACLRights getRights() {
+            return rights;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (!(o instanceof SimpleMailboxACLCommand)) return false;
+
+            SimpleMailboxACLCommand that = (SimpleMailboxACLCommand) o;
+
+            if (key != null ? !key.equals(that.key) : that.key != null) return 
false;
+            if (editMode != that.editMode) return false;
+            return !(rights != null ? !rights.equals(that.rights) : 
that.rights != null);
+
+        }
+
+        @Override
+        public int hashCode() {
+            int result = key != null ? key.hashCode() : 0;
+            result = 31 * result + (editMode != null ? editMode.hashCode() : 
0);
+            result = 31 * result + (rights != null ? rights.hashCode() : 0);
+            return result;
+        }
+    }
+
     public static final MailboxACLEntryKey ANYBODY_KEY;
     public static final MailboxACLEntryKey ANYBODY_NEGATIVE_KEY;
     public static final MailboxACLEntryKey AUTHENTICATED_KEY;
@@ -926,6 +973,19 @@ public class SimpleMailboxACL implements
         return false;
     }
 
+    @Override
+    public MailboxACL apply(MailboxACLCommand aclUpdate) throws 
UnsupportedRightException {
+        switch (aclUpdate.getEditMode()) {
+            case ADD:
+                return union(aclUpdate.getEntryKey(), aclUpdate.getRights());
+            case REMOVE:
+                return except(aclUpdate.getEntryKey(), aclUpdate.getRights());
+            case REPLACE:
+                return replace(aclUpdate.getEntryKey(), aclUpdate.getRights());
+        }
+        throw new RuntimeException("Unknown edit mode");
+    }
+
     /**
      * @see 
org.apache.james.mailbox.MailboxACL#except(org.apache.james.mailbox.MailboxACL)
      */

Modified: 
james/mailbox/trunk/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -3,6 +3,7 @@ import java.util.List;
 
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -77,6 +78,11 @@ public class CachingMailboxMapper<Id> im
                return underlying.list();
        }
 
+       @Override
+       public void updateACL(Mailbox<Id> mailbox, MailboxACL.MailboxACLCommand 
mailboxACLCommand) throws MailboxException {
+               mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
+       }
+
        private void invalidate(Mailbox<Id> mailbox) {
                cache.invalidate(mailbox);
        }

Modified: 
james/mailbox/trunk/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -37,6 +37,7 @@ import java.util.UUID;
 
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -144,4 +145,8 @@ public class CassandraMailboxMapper impl
         return transaction.run();
     }
 
+    @Override
+    public void updateACL(Mailbox<UUID> mailbox, MailboxACL.MailboxACLCommand 
mailboxACLCommand) throws MailboxException {
+        mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
+    }
 }

Modified: 
james/mailbox/trunk/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -54,6 +54,7 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.hbase.HBaseNonTransactionalMapper;
 import org.apache.james.mailbox.hbase.mail.model.HBaseMailbox;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -392,4 +393,9 @@ public class HBaseMailboxMapper extends
 //            IOUtils.closeStream(mailboxes);
         }
     }
+
+    @Override
+    public void updateACL(Mailbox<UUID> mailbox, MailboxACL.MailboxACLCommand 
mailboxACLCommand) throws MailboxException {
+        mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
+    }
 }

Modified: 
james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -39,6 +39,7 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.jcr.AbstractJCRScalingMapper;
 import org.apache.james.mailbox.jcr.MailboxSessionJCRRepository;
 import org.apache.james.mailbox.jcr.mail.model.JCRMailbox;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -232,5 +233,9 @@ public class JCRMailboxMapper extends Ab
             throw new MailboxException("Unable to retrieve the list of 
mailboxes", e);
         }
     }
- 
+
+    @Override
+    public void updateACL(Mailbox<String> mailbox, 
MailboxACL.MailboxACLCommand mailboxACLCommand) throws MailboxException {
+        mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
+    }
 }

Modified: 
james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.jpa.JPATransactionalMapper;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -167,4 +168,9 @@ public class JPAMailboxMapper extends JP
             throw new MailboxException("Delete of mailboxes failed", e);
         } 
     }
+
+    @Override
+    public void updateACL(Mailbox<Long> mailbox, MailboxACL.MailboxACLCommand 
mailboxACLCommand) throws MailboxException {
+        mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
+    }
 }

Modified: 
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
 (original)
+++ 
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirStore.java
 Mon Apr 27 09:28:26 2015
@@ -26,13 +26,13 @@ import org.apache.james.mailbox.MailboxP
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
-import org.apache.james.mailbox.maildir.mail.model.MaildirMailbox;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 
 public class MaildirStore implements UidProvider<Integer>, 
ModSeqProvider<Integer>{
 
@@ -125,7 +125,9 @@ public class MaildirStore implements Uid
         MaildirFolder folder = new 
MaildirFolder(mailboxFile.getAbsolutePath(), mailboxPath, locker);
         folder.setMessageNameStrictParse(isMessageNameStrictParse());
         try {
-            return new MaildirMailbox<Integer>(session, mailboxPath, folder);
+            Mailbox<Integer> loadedMailbox = new 
SimpleMailbox<Integer>(mailboxPath, folder.getUidValidity());
+            loadedMailbox.setACL(folder.getACL(session));
+            return loadedMailbox;
         } catch (IOException e) {
             throw new MailboxException("Unable to load Mailbox " + 
mailboxPath, e);
         }

Modified: 
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.maildir.MaildirFolder;
 import org.apache.james.mailbox.maildir.MaildirMessageName;
 import org.apache.james.mailbox.maildir.MaildirStore;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
@@ -193,6 +194,7 @@ public class MaildirMailboxMapper extend
                                 new IOException("Could not rename folder " + 
originalFolder));
                 }
             }
+            folder.setACL(session, mailbox.getACL());
         } catch (MailboxNotFoundException e) {
             // it cannot be found and is thus new
             MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
@@ -214,6 +216,7 @@ public class MaildirMailboxMapper extend
                 throw new MailboxException("Failed to save Mailbox " + 
mailbox, ioe);
 
             }
+            folder.setACL(session, mailbox.getACL());
         }
         
     }
@@ -320,4 +323,11 @@ public class MaildirMailboxMapper extend
         
     }
 
+    @Override
+    public void updateACL(Mailbox<Integer> mailbox, 
MailboxACL.MailboxACLCommand mailboxACLCommand) throws MailboxException {
+        MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
+        MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
+        folder.setACL(session, newACL);
+        mailbox.setACL(newACL);
+    }
 }

Modified: 
james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -128,5 +129,9 @@ public class InMemoryMailboxMapper imple
     public <T> T execute(Transaction<T> transaction) throws MailboxException {
         return transaction.run();
     }
-    
+
+    @Override
+    public void updateACL(Mailbox<Long> mailbox, MailboxACL.MailboxACLCommand 
mailboxACLCommand) throws MailboxException{
+        mailbox.setACL(mailbox.getACL().apply(mailboxACLCommand));
+    }
 }

Modified: 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
 (original)
+++ 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
 Mon Apr 27 09:28:26 2015
@@ -34,12 +34,14 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxMetaData.Selectability;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -590,4 +592,46 @@ public class StoreMailboxManager<Id> imp
     public void removeGlobalListener(MailboxListener listener, MailboxSession 
session) throws MailboxException {
         delegatingListener.removeGlobalListener(listener, session);
     }
+
+    @Override
+    public boolean hasRight(MailboxPath mailboxPath, 
MailboxACL.MailboxACLRight right, MailboxSession session) throws 
MailboxException {
+        MailboxMapper<Id> mapper = 
mailboxSessionMapperFactory.getMailboxMapper(session);
+        Mailbox<Id> mailbox = mapper.findMailboxByPath(mailboxPath);
+        MailboxSession.User user = session.getUser();
+        String userName = user != null ? user.getUserName() : null;
+        return aclResolver.hasRight(userName, groupMembershipResolver, right, 
mailbox.getACL(), mailbox.getUser(), new 
GroupFolderResolver(session).isGroupFolder(mailbox));
+    }
+
+    @Override
+    public MailboxACL.MailboxACLRights myRights(MailboxPath mailboxPath, 
MailboxSession session) throws MailboxException {
+        MailboxMapper<Id> mapper = 
mailboxSessionMapperFactory.getMailboxMapper(session);
+        Mailbox<Id> mailbox = mapper.findMailboxByPath(mailboxPath);
+        MailboxSession.User user = session.getUser();
+        if (user != null) {
+            return aclResolver.resolveRights(user.getUserName(), 
groupMembershipResolver, mailbox.getACL(), mailbox.getUser(), new 
GroupFolderResolver(session).isGroupFolder(mailbox));
+        } else {
+            return SimpleMailboxACL.NO_RIGHTS;
+        }
+    }
+
+    public MailboxACL.MailboxACLRights[] listRigths(MailboxPath mailboxPath, 
final MailboxACL.MailboxACLEntryKey key, MailboxSession session) throws 
MailboxException {
+        final MailboxMapper<Id> mapper = 
mailboxSessionMapperFactory.getMailboxMapper(session);
+        Mailbox<Id> mailbox = mapper.findMailboxByPath(mailboxPath);
+        return aclResolver.listRights(key, groupMembershipResolver, 
mailbox.getUser(), new GroupFolderResolver(session).isGroupFolder(mailbox));
+    }
+
+    @Override
+    public void setRights(MailboxPath mailboxPath, final 
MailboxACL.MailboxACLCommand mailboxACLCommand, MailboxSession session) throws 
MailboxException {
+        final MailboxMapper<Id> mapper = 
mailboxSessionMapperFactory.getMailboxMapper(session);
+        final Mailbox<Id> mailbox = mapper.findMailboxByPath(mailboxPath);
+        mapper.execute(
+            new Mapper.VoidTransaction() {
+                @Override
+                public void runVoid() throws MailboxException {
+                    mapper.updateACL(mailbox, mailboxACLCommand);
+                }
+            }
+        );
+    }
+
 }

Modified: 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
 (original)
+++ 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
 Mon Apr 27 09:28:26 2015
@@ -786,64 +786,16 @@ public class StoreMessageManager<Id> imp
         return messageMapper.findFirstUnseenMessageUid(getMailboxEntity());
     }
 
-    /**
-     * @see 
org.apache.james.mailbox.MessageManager#hasRight(org.apache.james.mailbox.MailboxACL.MailboxACLRight,
-     *      org.apache.james.mailbox.MailboxSession)
-     */
-    public boolean hasRight(MailboxACLRight right, MailboxSession session) 
throws UnsupportedRightException {
-        User user = session.getUser();
-        String userName = user != null ? user.getUserName() : null;
-
-        return aclResolver.hasRight(userName, groupMembershipResolver, right, 
mailbox.getACL(), mailbox.getUser(), isGroupFolder(session));
-    }
-
-    /**
-     * @see 
org.apache.james.mailbox.MessageManager#myRights(org.apache.james.mailbox.MailboxSession)
-     */
-    @Override
-    public MailboxACLRights myRights(MailboxSession session) throws 
MailboxException {
+    private MailboxACLRights myRights(MailboxSession session) throws 
MailboxException {
         User user = session.getUser();
         if (user != null) {
-            return aclResolver.resolveRights(user.getUserName(), 
groupMembershipResolver, mailbox.getACL(), mailbox.getUser(), 
isGroupFolder(session));
+            return aclResolver.resolveRights(user.getUserName(), 
groupMembershipResolver, mailbox.getACL(), mailbox.getUser(), new 
GroupFolderResolver(session).isGroupFolder(mailbox));
         } else {
             return SimpleMailboxACL.NO_RIGHTS;
         }
     }
 
     /**
-     * @see 
org.apache.james.mailbox.MessageManager#listRigths(java.lang.String, 
org.apache.james.mailbox.MailboxSession)
-     */
-    public MailboxACLRights[] listRigths(final MailboxACLEntryKey key, 
MailboxSession session) throws UnsupportedRightException {
-        return aclResolver.listRights(key, groupMembershipResolver, 
mailbox.getUser(), isGroupFolder(session));
-    }
-
-    /**
-     * @throws UnsupportedRightException 
-     * @see 
org.apache.james.mailbox.MessageManager#setRights(java.lang.String, 
org.apache.james.mailbox.model.MailboxACL.EditMode, 
org.apache.james.mailbox.model.MailboxACL.MailboxACLRights)
-     */
-    @Override
-    public void setRights(MailboxACLEntryKey mailboxACLEntryKey, EditMode 
editMode, MailboxACLRights mailboxAclRights) throws UnsupportedRightException {
-        MailboxACL acl = mailbox.getACL();
-        if (acl == null) {
-            acl = SimpleMailboxACL.EMPTY;
-        }
-        switch (editMode) {
-        case ADD:
-            acl = acl.union(mailboxACLEntryKey, mailboxAclRights);
-            break;
-        case REMOVE:
-            acl = acl.except(mailboxACLEntryKey, mailboxAclRights);
-            break;
-        case REPLACE:
-            acl = acl.replace(mailboxACLEntryKey, mailboxAclRights);
-            break;
-        default:
-            throw new IllegalStateException("Unexpected "+ 
EditMode.class.getName() +"."+ editMode);
-        }
-        mailbox.setACL(acl);
-    }
-
-    /**
      * Applies the global ACL (if there are any) to the mailbox ACL.
      * 
      * @param mailboxSession
@@ -852,19 +804,6 @@ public class StoreMessageManager<Id> imp
      * @throws UnsupportedRightException
      */
     protected MailboxACL getResolvedMailboxACL(MailboxSession mailboxSession) 
throws UnsupportedRightException {
-        return aclResolver.applyGlobalACL(mailbox.getACL(), 
isGroupFolder(mailboxSession));
+        return aclResolver.applyGlobalACL(mailbox.getACL(), new 
GroupFolderResolver(mailboxSession).isGroupFolder(mailbox));
     }
-
-    /**
-     * Returns true if the current mailbox does not reside neither in private
-     * nor other users' namespace.
-     * 
-     * @param session
-     * @return
-     */
-    protected boolean isGroupFolder(MailboxSession session) {
-        final String ns = mailbox.getNamespace();
-        return ns == null || (!ns.equals(session.getPersonalSpace()) && 
!ns.equals(session.getOtherUsersSpace()));
-    }
-
 }

Modified: 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java?rev=1676230&r1=1676229&r2=1676230&view=diff
==============================================================================
--- 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
 (original)
+++ 
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
 Mon Apr 27 09:28:26 2015
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.transaction.Mapper;
@@ -82,7 +83,15 @@ public interface MailboxMapper<Id> exten
      */
     boolean hasChildren(Mailbox<Id> mailbox, char delimiter)
             throws MailboxException, MailboxNotFoundException;
-    
+
+    /**
+     * Update the ACL of the stored mailbox.
+     *
+     * @param mailbox Mailbox for whom we want to update ACL
+     * @param mailboxACLCommand Update to perform
+     */
+    void updateACL(Mailbox<Id> mailbox, MailboxACL.MailboxACLCommand 
mailboxACLCommand) throws MailboxException;
+
     /**
      * Return a unmodifable {@link List} of all {@link Mailbox} 
      * 



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

Reply via email to