james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppal...@apache.org
Subject svn commit: r1292019 [3/3] - in /james: imap/trunk/api/src/main/java/org/apache/james/imap/api/ imap/trunk/api/src/main/java/org/apache/james/imap/api/display/ imap/trunk/message/src/main/java/org/apache/james/imap/decode/parser/ imap/trunk/message/src...
Date Tue, 21 Feb 2012 21:05:03 GMT
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=1292019&r1=1292018&r2=1292019&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 Tue Feb 21 21:05:02 2012
@@ -27,6 +27,7 @@ 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}.
@@ -57,7 +58,7 @@ public class SimpleMailboxACL implements
 
             @Override
             public boolean hasNext() {
-                return (value | (1 << position)) != 0;
+                return position < FIELD_COUNT;
             }
 
             @Override
@@ -65,13 +66,16 @@ public class SimpleMailboxACL implements
                 if (!hasNext()) {
                     throw new IndexOutOfBoundsException("No next element at position " + position + " from " + FIELD_COUNT + " in " + Rfc4314RightsIterator.class.getName());
                 }
-                return indexRightLookup[position];
+                MailboxACLRight result = indexRightLookup[position];
+                position++;
+                nextPostion();
+                return result;
             }
 
             /**
              */
             private void nextPostion() {
-                while (position < FIELD_COUNT && (value | (1 << position)) != 0) {
+                while (position < FIELD_COUNT && (value & (1 << position)) == 0) {
                     position++;
                 }
             }
@@ -271,12 +275,16 @@ public class SimpleMailboxACL implements
 
         }
 
-        private Rfc4314Rights(int value) throws UnsupportedRightException {
+        public Rfc4314Rights(int value) throws UnsupportedRightException {
             if ((value >> FIELD_COUNT) != 0) {
                 throw new UnsupportedRightException();
             }
             this.value = value;
         }
+        
+        public Rfc4314Rights(MailboxACLRight right) throws UnsupportedRightException {
+            this.value = flagMaskLookup(right.getValue());
+        }
 
         public Rfc4314Rights(String serializedRfc4314Rights) throws UnsupportedRightException {
             int v = 0;
@@ -386,7 +394,7 @@ public class SimpleMailboxACL implements
          */
         @Override
         public MailboxACLRights except(MailboxACLRights toRemove) throws UnsupportedRightException {
-            if (this.value == EMPTY_MASK) {
+            if (this.value == EMPTY_MASK || toRemove == null || toRemove.isEmpty()) {
                 /* nothing to remove */
                 return this;
             } else if (toRemove instanceof Rfc4314Rights) {
@@ -416,9 +424,15 @@ public class SimpleMailboxACL implements
             return value;
         }
 
-        /*
-         * (non-Javadoc)
-         * 
+        /**
+         * @see org.apache.james.mailbox.model.MailboxACL.MailboxACLRights#isEmpty()
+         */
+        @Override
+        public boolean isEmpty() {
+            return value == EMPTY_MASK;
+        }
+
+        /** 
          * @see
          * org.apache.james.mailbox.MailboxACL.MailboxACLRights#isSupported(
          * org.apache.james.mailbox.MailboxACL.MailboxACLRight)
@@ -510,6 +524,9 @@ public class SimpleMailboxACL implements
             this.key = key;
             this.value = value;
         }
+        public SimpleMailboxACLEntry(String key, String value) throws UnsupportedRightException {
+            this(new SimpleMailboxACLEntryKey(key), new Rfc4314Rights(value));
+        }
 
         /*
          * (non-Javadoc)
@@ -555,14 +572,6 @@ public class SimpleMailboxACL implements
             return new SimpleMailboxACLEntryKey(name, NameType.group, negative);
         }
 
-        public static SimpleMailboxACLEntryKey createSpecial(SpecialName name) {
-            return new SimpleMailboxACLEntryKey(name.name(), NameType.special, false);
-        }
-
-        public static SimpleMailboxACLEntryKey createSpecial(SpecialName name, boolean negative) {
-            return new SimpleMailboxACLEntryKey(name.name(), NameType.special, negative);
-        }
-
         public static SimpleMailboxACLEntryKey createUser(String name) {
             return new SimpleMailboxACLEntryKey(name, NameType.user, false);
         }
@@ -593,13 +602,13 @@ public class SimpleMailboxACL implements
                 throw new IllegalStateException("Cannot parse an empty string to a " + getClass().getName());
             }
             int start = 0;
-            if (serialized.charAt(0) == DEFAULT_NEGATIVE_MARKER) {
+            if (serialized.charAt(start) == DEFAULT_NEGATIVE_MARKER) {
                 negative = true;
                 start++;
             } else {
-                negative = true;
+                negative = false;
             }
-            if (serialized.charAt(0) == DEFAULT_GROUP_MARKER) {
+            if (serialized.charAt(start) == DEFAULT_GROUP_MARKER) {
                 nameType = NameType.group;
                 start++;
                 name = serialized.substring(start);
@@ -790,7 +799,9 @@ public class SimpleMailboxACL implements
     }
 
     public static final MailboxACLEntryKey ANYBODY_KEY;
+    public static final MailboxACLEntryKey ANYBODY_NEGATIVE_KEY;
     public static final MailboxACLEntryKey AUTHENTICATED_KEY;
+    public static final MailboxACLEntryKey AUTHENTICATED_NEGATIVE_KEY;
     public static final MailboxACL EMPTY;
 
     public static final MailboxACLRights FULL_RIGHTS;
@@ -800,21 +811,26 @@ public class SimpleMailboxACL implements
     public static final MailboxACL OWNER_FULL_EXCEPT_ADMINISTRATION_ACL;
 
     public static final MailboxACLEntryKey OWNER_KEY;
+    public static final MailboxACLEntryKey OWNER_NEGATIVE_KEY;
 
     static {
         try {
             ANYBODY_KEY = new SimpleMailboxACLEntryKey(SpecialName.anybody.name(), NameType.special, false);
+            ANYBODY_NEGATIVE_KEY = new SimpleMailboxACLEntryKey(SpecialName.anybody.name(), NameType.special, true);
             AUTHENTICATED_KEY = new SimpleMailboxACLEntryKey(SpecialName.authenticated.name(), NameType.special, false);
+            AUTHENTICATED_NEGATIVE_KEY = new SimpleMailboxACLEntryKey(SpecialName.authenticated.name(), NameType.special, true);
             EMPTY = new SimpleMailboxACL();
             FULL_RIGHTS =  new Rfc4314Rights(true, true, true, true, true, true, true, true, true, true, true);
             NO_RIGHTS = new Rfc4314Rights();
             OWNER_KEY = new SimpleMailboxACLEntryKey(SpecialName.owner.name(), NameType.special, false);
+            OWNER_NEGATIVE_KEY = new SimpleMailboxACLEntryKey(SpecialName.owner.name(), NameType.special, true);
             OWNER_FULL_ACL = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.FULL_RIGHTS) });
             OWNER_FULL_EXCEPT_ADMINISTRATION_ACL = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.FULL_RIGHTS.except(new Rfc4314Rights(Rfc4314Rights.a_Administer_MASK))) });
         } catch (UnsupportedRightException e) {
             throw new RuntimeException(e);
         }
     }
+    
     private final Map<MailboxACLEntryKey, MailboxACLRights> entries;
 
     /**
@@ -897,7 +913,7 @@ public class SimpleMailboxACL implements
         entries = Collections.unmodifiableMap(m);
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
@@ -910,26 +926,58 @@ public class SimpleMailboxACL implements
         return false;
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.james.mailbox.MailboxACL#except(org.apache.james.mailbox.MailboxACL)
      */
     @Override
-    public MailboxACL except(MailboxACL other) {
+    public MailboxACL except(MailboxACL other) throws UnsupportedRightException {
         if (entries.size() == 0) {
             return this;
         } else {
             Map<MailboxACLEntryKey, MailboxACLRights> otherEntries = other.getEntries();
-            int cnt = entries.size();
-            Map<MailboxACLEntryKey, MailboxACLRights> resultEntries = new HashMap<MailboxACLEntryKey, MailboxACLRights>(cnt + cnt / 2 + 1);
+            Map<MailboxACLEntryKey, MailboxACLRights> resultEntries = new HashMap<MailboxACLEntryKey, MailboxACLRights>(this.entries);
             for (Entry<MailboxACLEntryKey, MailboxACLRights> otherEntry : otherEntries.entrySet()) {
                 MailboxACLEntryKey key = otherEntry.getKey();
-                entries.remove(key);
+                MailboxACLRights thisRights = resultEntries.get(key);
+                if (thisRights == null) {
+                    /* nothing to diff */
+                } else {
+                    /* diff */
+                    MailboxACLRights resultRights = thisRights.except(otherEntry.getValue());
+                    if (!resultRights.isEmpty()) {
+                        resultEntries.put(key, resultRights);
+                    }
+                    else {
+                        resultEntries.remove(key);
+                    }
+                }
             }
             return new SimpleMailboxACL(Collections.unmodifiableMap(resultEntries), true);
         }
     }
+    
+    /**
+     * @see org.apache.james.mailbox.model.MailboxACL#except(org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey, org.apache.james.mailbox.model.MailboxACL.MailboxACLRights)
+     */
+    public MailboxACL except(MailboxACLEntryKey key, MailboxACLRights mailboxACLRights) throws UnsupportedRightException {
+        Map<MailboxACLEntryKey, MailboxACLRights> resultEntries = new HashMap<MailboxACLEntryKey, MailboxACLRights>(this.entries);
+        MailboxACLRights thisRights = resultEntries.get(key);
+        if (thisRights == null) {
+            /* nothing to diff */
+        } else {
+            /* diff */
+            MailboxACLRights resultRights = thisRights.except(mailboxACLRights);
+            if (!resultRights.isEmpty()) {
+                resultEntries.put(key, resultRights);
+            }
+            else {
+                resultEntries.remove(key);
+            }
+        }
+        return new SimpleMailboxACL(Collections.unmodifiableMap(resultEntries), true);
+    }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.james.mailbox.MailboxACL#getEntries()
      */
     @Override
@@ -937,7 +985,7 @@ public class SimpleMailboxACL implements
         return entries;
     }
 
-    /* (non-Javadoc)
+    /**
      * @see java.lang.Object#hashCode()
      */
     @Override
@@ -945,7 +993,21 @@ public class SimpleMailboxACL implements
         return entries == null ? 0 : entries.hashCode();
     }
 
-    /* (non-Javadoc)
+    /**
+     * @see org.apache.james.mailbox.model.MailboxACL#replace(org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey, org.apache.james.mailbox.model.MailboxACL.MailboxACLRights)
+     */
+    @Override
+    public MailboxACL replace(MailboxACLEntryKey key, MailboxACLRights replacement) throws UnsupportedRightException {
+        Map<MailboxACLEntryKey, MailboxACLRights> resultEntries = new HashMap<MailboxACLEntryKey, MailboxACLRights>(this.entries);
+        if (replacement == null || replacement.isEmpty()) {
+            resultEntries.remove(key);
+        } else {
+            resultEntries.put(key, replacement);
+        }
+        return new SimpleMailboxACL(Collections.unmodifiableMap(resultEntries), true);
+    }
+
+    /**
      * @see java.lang.Object#toString()
      */
     @Override
@@ -953,7 +1015,7 @@ public class SimpleMailboxACL implements
         return entries == null ? "" : entries.toString();
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.james.mailbox.MailboxACL#union(org.apache.james.mailbox.MailboxACL)
      */
     @Override
@@ -987,5 +1049,21 @@ public class SimpleMailboxACL implements
             return new SimpleMailboxACL(Collections.unmodifiableMap(resultEntries), true);
         }
     }
+    
+    /**
+     * @see org.apache.james.mailbox.model.MailboxACL#union(org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey, org.apache.james.mailbox.model.MailboxACL.MailboxACLRights)
+     */
+    public MailboxACL union(MailboxACLEntryKey key, MailboxACLRights mailboxACLRights) throws UnsupportedRightException {
+        Map<MailboxACLEntryKey, MailboxACLRights> resultEntries = new HashMap<MailboxACLEntryKey, MailboxACLRights>(this.entries);
+        MailboxACLRights thisRights = resultEntries.get(key);
+        if (thisRights == null) {
+            /* nothing to union */
+            resultEntries.put(key, mailboxACLRights);
+        } else {
+            /* union */
+            resultEntries.put(key, thisRights.union(mailboxACLRights));
+        }
+        return new SimpleMailboxACL(Collections.unmodifiableMap(resultEntries), true);
+    }
 
 }

Modified: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/acl/UnionMailboxACLResolverTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/acl/UnionMailboxACLResolverTest.java?rev=1292019&r1=1292018&r2=1292019&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/acl/UnionMailboxACLResolverTest.java (original)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/acl/UnionMailboxACLResolverTest.java Tue Feb 21 21:05:02 2012
@@ -20,13 +20,10 @@
 
 package org.apache.james.mailbox.acl;
 
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.NameType;
-import org.apache.james.mailbox.model.MailboxACL.SpecialName;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
 import org.apache.james.mailbox.model.SimpleMailboxACL.SimpleMailboxACLEntryKey;
 import org.junit.Assert;
@@ -60,9 +57,18 @@ public class UnionMailboxACLResolverTest
     private MailboxACL ownerReadNegative;
     private MailboxACL user1Read;
     private MailboxACL user1ReadNegative;
+    private SimpleMailboxACLEntryKey user1Key;
+    private SimpleMailboxACLEntryKey user2Key;
+    private SimpleMailboxACLEntryKey group1Key;
+    private SimpleMailboxACLEntryKey group2Key;
 
     @Before
     public void setUp() throws Exception {
+        user1Key = SimpleMailboxACLEntryKey.createUser(USER_1);
+        user2Key = SimpleMailboxACLEntryKey.createUser(USER_2);
+        group1Key = SimpleMailboxACLEntryKey.createGroup(GROUP_1);
+        group2Key = SimpleMailboxACLEntryKey.createGroup(GROUP_2);
+        
         MailboxACL acl = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.AUTHENTICATED_KEY, SimpleMailboxACL.FULL_RIGHTS) });
         authenticatedReadListWriteGlobal = new UnionMailboxACLResolver(acl, acl);
         acl = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.ANYBODY_KEY, new Rfc4314Rights("rl")) });
@@ -77,72 +83,81 @@ public class UnionMailboxACLResolverTest
         groupMembershipResolver.addMembership(GROUP_1, USER_1);
         groupMembershipResolver.addMembership(GROUP_2, USER_2);
 
-        user1Read = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createUser(USER_1), new Rfc4314Rights("r")) });
+        user1Read = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(user1Key, new Rfc4314Rights("r")) });
         user1ReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createUser(USER_1, true), new Rfc4314Rights("r")) });
 
-        group1Read = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createGroup(GROUP_1), new Rfc4314Rights("r")) });
+        group1Read = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(group1Key, new Rfc4314Rights("r")) });
         group1ReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createGroup(GROUP_1, true), new Rfc4314Rights("r")) });
 
-        anybodyRead = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody), new Rfc4314Rights("r")) });
-        anybodyReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody, true), new Rfc4314Rights("r")) });
+        anybodyRead = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.ANYBODY_KEY, new Rfc4314Rights("r")) });
+        anybodyReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.ANYBODY_NEGATIVE_KEY, new Rfc4314Rights("r")) });
 
-        authenticatedRead = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated), new Rfc4314Rights("r")) });
-        authenticatedReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated, true), new Rfc4314Rights("r")) });
+        authenticatedRead = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.AUTHENTICATED_KEY, new Rfc4314Rights("r")) });
+        authenticatedReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.AUTHENTICATED_NEGATIVE_KEY, new Rfc4314Rights("r")) });
 
-        ownerRead = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner), new Rfc4314Rights("r")) });
-        ownerReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner, true), new Rfc4314Rights("r")) });
+        ownerRead = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.OWNER_KEY, new Rfc4314Rights("r")) });
+        ownerReadNegative = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(SimpleMailboxACL.OWNER_NEGATIVE_KEY, new Rfc4314Rights("r")) });
 
     }
 
     @Test
     public void testAppliesNullUser() throws UnsupportedRightException {
 
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_1), null, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_2), null, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_1), null, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_2), null, groupMembershipResolver, USER_1, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody), null, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated), null, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner), null, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user1Key, null, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user2Key, null, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group1Key, null, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group2Key, null, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.ANYBODY_KEY, null, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(SimpleMailboxACL.AUTHENTICATED_KEY, null, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(SimpleMailboxACL.OWNER_KEY, null, groupMembershipResolver, USER_1, false));
     }
 
     @Test
     public void testAppliesUser() throws UnsupportedRightException {
-        /* requester unequal to owner */
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_1), USER_1, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_2), USER_1, groupMembershipResolver, USER_1, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_1), USER_1, groupMembershipResolver, USER_1, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_2), USER_1, groupMembershipResolver, USER_1, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody), USER_1, groupMembershipResolver, USER_1, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated), USER_1, groupMembershipResolver, USER_1, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner), USER_1, groupMembershipResolver, USER_1, false));
-
-        /* requester unequal to owner user */
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_1), USER_1, groupMembershipResolver, USER_2, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_2), USER_1, groupMembershipResolver, USER_2, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_1), USER_1, groupMembershipResolver, USER_2, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_2), USER_1, groupMembershipResolver, USER_2, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody), USER_1, groupMembershipResolver, USER_2, false));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated), USER_1, groupMembershipResolver, USER_2, false));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner), USER_1, groupMembershipResolver, USER_2, false));
+        /* requester is the resource owner */
+        Assert.assertTrue(UnionMailboxACLResolver.applies(user1Key, user1Key, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user2Key, user1Key, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(group1Key, user1Key, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group2Key, user1Key, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.ANYBODY_KEY, user1Key, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.AUTHENTICATED_KEY, user1Key, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.OWNER_KEY, user1Key, groupMembershipResolver, USER_1, false));
+
+        /* requester is not the resource user */
+        Assert.assertTrue(UnionMailboxACLResolver.applies(user1Key, user1Key, groupMembershipResolver, USER_2, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user2Key, user1Key, groupMembershipResolver, USER_2, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(group1Key, user1Key, groupMembershipResolver, USER_2, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group2Key, user1Key, groupMembershipResolver, USER_2, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.ANYBODY_KEY, user1Key, groupMembershipResolver, USER_2, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.AUTHENTICATED_KEY, user1Key, groupMembershipResolver, USER_2, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(SimpleMailboxACL.OWNER_KEY, user1Key, groupMembershipResolver, USER_2, false));
 
         /* requester member of owner group */
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_1), USER_1, groupMembershipResolver, GROUP_1, true));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_2), USER_1, groupMembershipResolver, GROUP_1, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_1), USER_1, groupMembershipResolver, GROUP_1, true));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_2), USER_1, groupMembershipResolver, GROUP_1, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody), USER_1, groupMembershipResolver, GROUP_1, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated), USER_1, groupMembershipResolver, GROUP_1, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner), USER_1, groupMembershipResolver, GROUP_1, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(user1Key, user1Key, groupMembershipResolver, GROUP_1, true));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user2Key, user1Key, groupMembershipResolver, GROUP_1, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(group1Key, user1Key, groupMembershipResolver, GROUP_1, true));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group2Key, user1Key, groupMembershipResolver, GROUP_1, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.ANYBODY_KEY, user1Key, groupMembershipResolver, GROUP_1, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.AUTHENTICATED_KEY, user1Key, groupMembershipResolver, GROUP_1, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.OWNER_KEY, user1Key, groupMembershipResolver, GROUP_1, true));
 
         /* requester not member of owner group */
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_1), USER_1, groupMembershipResolver, GROUP_2, true));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createUser(USER_2), USER_1, groupMembershipResolver, GROUP_2, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_1), USER_1, groupMembershipResolver, GROUP_2, true));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createGroup(GROUP_2), USER_1, groupMembershipResolver, GROUP_2, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.anybody), USER_1, groupMembershipResolver, GROUP_2, true));
-        Assert.assertTrue(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.authenticated), USER_1, groupMembershipResolver, GROUP_2, true));
-        Assert.assertFalse(anyoneReadListGlobal.applies(SimpleMailboxACLEntryKey.createSpecial(SpecialName.owner), USER_1, groupMembershipResolver, GROUP_2, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(user1Key, user1Key, groupMembershipResolver, GROUP_2, true));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user2Key, user1Key, groupMembershipResolver, GROUP_2, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(group1Key, user1Key, groupMembershipResolver, GROUP_2, true));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group2Key, user1Key, groupMembershipResolver, GROUP_2, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.ANYBODY_KEY, user1Key, groupMembershipResolver, GROUP_2, true));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.AUTHENTICATED_KEY, user1Key, groupMembershipResolver, GROUP_2, true));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(SimpleMailboxACL.OWNER_KEY, user1Key, groupMembershipResolver, GROUP_2, true));
+
+        /* owner query */
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user1Key, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(user2Key, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group1Key, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
+        Assert.assertFalse(UnionMailboxACLResolver.applies(group2Key, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.ANYBODY_KEY, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.AUTHENTICATED_KEY, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
+        Assert.assertTrue(UnionMailboxACLResolver.applies(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.OWNER_KEY, groupMembershipResolver, USER_1, false));
 
     }
 

Modified: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java?rev=1292019&r1=1292018&r2=1292019&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java (original)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java Tue Feb 21 21:05:02 2012
@@ -23,6 +23,7 @@ package org.apache.james.mailbox.model;
 import static org.junit.Assert.assertEquals;
 
 import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
 import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
 import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
@@ -36,10 +37,10 @@ import org.junit.Test;
 public class Rfc4314RightsTest {
     
     private Rfc4314Rights aeik;
-    private Rfc4314Rights lprs;
-    private Rfc4314Rights twx;
     private MailboxACLRights full;
+    private Rfc4314Rights lprs;
     private MailboxACLRights none;
+    private Rfc4314Rights twx;
     
     @Before
     public void setUp() throws Exception {
@@ -50,29 +51,24 @@ public class Rfc4314RightsTest {
         none = SimpleMailboxACL.NO_RIGHTS;
     }
     @Test
-    public void test() throws UnsupportedRightException {
-        assertEquals(aeik.getValue(), Rfc4314Rights.a_Administer_MASK | Rfc4314Rights.e_PerformExpunge_MASK | Rfc4314Rights.i_Insert_MASK | Rfc4314Rights.k_CreateMailbox_MASK);
-        assertEquals(lprs.getValue(), Rfc4314Rights.l_Lookup_MASK | Rfc4314Rights.p_Post_MASK | Rfc4314Rights.s_WriteSeenFlag_MASK | Rfc4314Rights.r_Read_MASK);
-        assertEquals(twx.getValue(), Rfc4314Rights.t_DeleteMessages_MASK | Rfc4314Rights.w_Write_MASK | Rfc4314Rights.x_DeleteMailbox_MASK);
+    public void testExceptFull() throws UnsupportedRightException {
+        assertEquals(none, full.except(aeik).except(lprs).except(twx));
     }
     
     @Test
-    public void testSerialize() throws UnsupportedRightException {
-        assertEquals("aeik", aeik.serialize());
-        assertEquals("lprs", lprs.serialize());
-        assertEquals("twx", twx.serialize());
-        assertEquals("aeiklprstwx", full.serialize());
-        assertEquals("", none.serialize());
+    public void testExceptNonExistent() throws UnsupportedRightException {
+        assertEquals(aeik, aeik.except(lprs));
     }
 
     @Test
-    public void testUnionFull() throws UnsupportedRightException {
-        assertEquals(full, aeik.union(lprs).union(twx));
-    }
-    
-    @Test
-    public void testUnionZero() throws UnsupportedRightException {
-        assertEquals(lprs, lprs.union(none));
+    public void testExceptUnsupportedFlag() {
+        try {
+            String unsupportedFlag = "z";
+            new SimpleMailboxACL.Rfc4314Rights(unsupportedFlag );
+            Assert.fail(UnsupportedRightException.class.getName() +" expected for unsupported right flag '"+ unsupportedFlag +"'.");
+        } catch (UnsupportedRightException e) {
+            /* OK */
+        }
     }
     
     @Test
@@ -81,24 +77,48 @@ public class Rfc4314RightsTest {
     }
     
     @Test
-    public void testExceptNonExistent() throws UnsupportedRightException {
-        assertEquals(aeik, aeik.except(lprs));
+    public void testIterable() {
+        testIterable(full);
+        testIterable(none);
+        testIterable(aeik);
+        testIterable(lprs);
+        testIterable(twx);
+    }
+    
+    private static void testIterable(MailboxACLRights rights) {
+        String stringRights = rights.serialize();
+        int i = 0;
+        for (MailboxACLRight r : rights) {
+            assertEquals(stringRights.charAt(i++), r.getValue());
+        }
+        assertEquals(stringRights.length(), i);
+
     }
 
     @Test
-    public void testExceptFull() throws UnsupportedRightException {
-        assertEquals(none, full.except(aeik).except(lprs).except(twx));
+    public void testParse() throws UnsupportedRightException {
+        assertEquals(aeik.getValue(), Rfc4314Rights.a_Administer_MASK | Rfc4314Rights.e_PerformExpunge_MASK | Rfc4314Rights.i_Insert_MASK | Rfc4314Rights.k_CreateMailbox_MASK);
+        assertEquals(lprs.getValue(), Rfc4314Rights.l_Lookup_MASK | Rfc4314Rights.p_Post_MASK | Rfc4314Rights.s_WriteSeenFlag_MASK | Rfc4314Rights.r_Read_MASK);
+        assertEquals(twx.getValue(), Rfc4314Rights.t_DeleteMessages_MASK | Rfc4314Rights.w_Write_MASK | Rfc4314Rights.x_DeleteMailbox_MASK);
     }
 
     @Test
-    public void testExceptUnsupportedFlag() {
-        try {
-            String unsupportedFlag = "z";
-            new SimpleMailboxACL.Rfc4314Rights(unsupportedFlag );
-            Assert.fail(UnsupportedRightException.class.getName() +" expected for unsupported right flag '"+ unsupportedFlag +"'.");
-        } catch (UnsupportedRightException e) {
-            /* OK */
-        }
+    public void testSerialize() throws UnsupportedRightException {
+        assertEquals("aeik", aeik.serialize());
+        assertEquals("lprs", lprs.serialize());
+        assertEquals("twx", twx.serialize());
+        assertEquals("aeiklprstwx", full.serialize());
+        assertEquals("", none.serialize());
+    }
+    
+    @Test
+    public void testUnionFull() throws UnsupportedRightException {
+        assertEquals(full, aeik.union(lprs).union(twx));
+    }
+    @Test
+    public void testUnionZero() throws UnsupportedRightException {
+        assertEquals(lprs, lprs.union(none));
     }
 
+
 }

Added: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLEntryKeyTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLEntryKeyTest.java?rev=1292019&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLEntryKeyTest.java (added)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLEntryKeyTest.java Tue Feb 21 21:05:02 2012
@@ -0,0 +1,143 @@
+/*
+ *   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.mailbox.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
+import org.apache.james.mailbox.model.MailboxACL.NameType;
+import org.apache.james.mailbox.model.MailboxACL.SpecialName;
+import org.apache.james.mailbox.model.SimpleMailboxACL.SimpleMailboxACLEntryKey;
+import org.junit.Test;
+
+/**
+ * @author Peter Palaga
+ */
+public class SimpleMailboxACLEntryKeyTest {
+    
+    private static final String GROUP_1 = "group1";
+
+    private static final String USER_1 = "user1";
+    
+    @Test
+    public void testUser() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(USER_1);
+        assertEquals(k.isNegative(), false);
+        assertEquals(k.getNameType(), NameType.user);
+        assertEquals(k.getName(), USER_1);
+        
+    }
+    
+    @Test
+    public void testNegativeUser() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1);
+        assertEquals(k.isNegative(), true);
+        assertEquals(k.getNameType(), NameType.user);
+        assertEquals(k.getName(), USER_1);
+        
+    }
+    
+
+    @Test
+    public void testGroup() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1);
+        assertEquals(k.isNegative(), false);
+        assertEquals(k.getNameType(), NameType.group);
+        assertEquals(k.getName(), GROUP_1);
+        
+    }
+    
+    @Test
+    public void testNegativeGroup() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey("" + MailboxACL.DEFAULT_NEGATIVE_MARKER + MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1);
+        assertEquals(k.isNegative(), true);
+        assertEquals(k.getNameType(), NameType.group);
+        assertEquals(k.getName(), GROUP_1);
+        
+    }
+    
+
+    @Test
+    public void testOwner() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(SpecialName.owner.toString());
+        assertEquals(k.isNegative(), false);
+        assertEquals(k.getNameType(), NameType.special);
+        assertEquals(k.getName(), SpecialName.owner.toString());
+        
+    }
+    
+    @Test
+    public void testNegativeOwner() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.owner.toString());
+        assertEquals(k.isNegative(), true);
+        assertEquals(k.getNameType(), NameType.special);
+        assertEquals(k.getName(), SpecialName.owner.toString());
+        
+    }
+
+    @Test
+    public void testAnybody() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(SpecialName.anybody.toString());
+        assertEquals(k.isNegative(), false);
+        assertEquals(k.getNameType(), NameType.special);
+        assertEquals(k.getName(), SpecialName.anybody.toString());
+        
+    }
+    
+    @Test
+    public void testNegativeAnybody() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.anybody.toString());
+        assertEquals(k.isNegative(), true);
+        assertEquals(k.getNameType(), NameType.special);
+        assertEquals(k.getName(), SpecialName.anybody.toString());
+        
+    }
+    
+
+    @Test
+    public void testAuthenticated() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(SpecialName.authenticated.toString());
+        assertEquals(k.isNegative(), false);
+        assertEquals(k.getNameType(), NameType.special);
+        assertEquals(k.getName(), SpecialName.authenticated.toString());
+        
+    }
+    
+    @Test
+    public void testNegativeAuthenticated() throws UnsupportedRightException {
+        
+        MailboxACLEntryKey k = new SimpleMailboxACLEntryKey(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.authenticated.toString());
+        assertEquals(k.isNegative(), true);
+        assertEquals(k.getNameType(), NameType.special);
+        assertEquals(k.getName(), SpecialName.authenticated.toString());
+        
+    }
+}

Added: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLTest.java?rev=1292019&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLTest.java (added)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/SimpleMailboxACLTest.java Tue Feb 21 21:05:02 2012
@@ -0,0 +1,214 @@
+/*
+ *   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.mailbox.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
+import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
+import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
+import org.apache.james.mailbox.model.SimpleMailboxACL.SimpleMailboxACLEntryKey;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Peter Palaga
+ */
+public class SimpleMailboxACLTest {
+
+    private static final String USER_1 = "user1";
+    private static final String USER_2 = "user2";
+
+    private static final String ae = "ae";
+    private static final String ik = "ik";
+    private static final String aeik = "aeik";
+    private static final String lprs = "lprs";
+    private static final String twx = "twx";
+
+    private Properties u1u2g1g2Properties;
+
+    private MailboxACL u1u2g1g2ACL;
+
+    @Before
+    public void setUp() throws Exception {
+
+        u1u2g1g2Properties = new Properties();
+
+        u1u2g1g2Properties.setProperty(USER_1, aeik);
+        u1u2g1g2Properties.setProperty(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1, lprs);
+        u1u2g1g2Properties.setProperty(USER_2, lprs);
+        u1u2g1g2Properties.setProperty(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_2, twx);
+
+        u1u2g1g2ACL = new SimpleMailboxACL(u1u2g1g2Properties);
+
+    }
+
+    @Test
+    public void testUnionACLNew() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.put(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.FULL_RIGHTS);
+
+        MailboxACL toAdd = SimpleMailboxACL.OWNER_FULL_ACL;
+        MailboxACL result = u1u2g1g2ACL.union(toAdd);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testUnionEntryNew() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.put(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.FULL_RIGHTS);
+
+        MailboxACL result = u1u2g1g2ACL.union(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.FULL_RIGHTS);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testUnionACLExisting() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.put(new SimpleMailboxACLEntryKey(USER_1), new Rfc4314Rights(aeik + lprs));
+
+        MailboxACL toAdd = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(USER_1, lprs) });
+        MailboxACL result = u1u2g1g2ACL.union(toAdd);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testUnionEntryExisting() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.put(new SimpleMailboxACLEntryKey(USER_1), new Rfc4314Rights(aeik + lprs));
+
+        MailboxACL result = u1u2g1g2ACL.union(new SimpleMailboxACLEntryKey(USER_1), new Rfc4314Rights(lprs));
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testUnionACLZero() throws UnsupportedRightException {
+
+    }
+
+    @Test
+    public void testUnionEntryZero() throws UnsupportedRightException {
+
+    }
+
+    @Test
+    public void testExceptACLNew() throws UnsupportedRightException {
+
+        /* actually no change expected */
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+
+        MailboxACL toRemove = SimpleMailboxACL.OWNER_FULL_ACL;
+        MailboxACL result = u1u2g1g2ACL.except(toRemove);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testExceptEntryNew() throws UnsupportedRightException {
+
+        /* actually no change expected */
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+
+        MailboxACL result = u1u2g1g2ACL.except(SimpleMailboxACL.OWNER_KEY, SimpleMailboxACL.FULL_RIGHTS);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testExceptACLExisting() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.put(new SimpleMailboxACLEntryKey(USER_1), new Rfc4314Rights(ik));
+
+        MailboxACL toRemove = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(USER_1, ae) });
+        MailboxACL result = u1u2g1g2ACL.except(toRemove);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testExceptEntryExisting() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.put(new SimpleMailboxACLEntryKey(USER_1), new Rfc4314Rights(ik));
+
+        MailboxACL result = u1u2g1g2ACL.except(new SimpleMailboxACLEntryKey(USER_1), new Rfc4314Rights(ae));
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(foundEntries, expectedEntries);
+    }
+
+    @Test
+    public void testExceptACLFull() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.remove(new SimpleMailboxACLEntryKey(USER_1));
+
+        MailboxACL toRemove = new SimpleMailboxACL(new SimpleMailboxACL.SimpleMailboxACLEntry[] { new SimpleMailboxACL.SimpleMailboxACLEntry(USER_1, SimpleMailboxACL.FULL_RIGHTS.serialize()) });
+        MailboxACL result = u1u2g1g2ACL.except(toRemove);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(expectedEntries, foundEntries);
+    }
+
+    @Test
+    public void testExceptEntryFull() throws UnsupportedRightException {
+
+        Map<MailboxACLEntryKey, MailboxACLRights> expectedEntries = new HashMap<MailboxACL.MailboxACLEntryKey, MailboxACL.MailboxACLRights>(u1u2g1g2ACL.getEntries());
+        expectedEntries.remove(new SimpleMailboxACLEntryKey(USER_1));
+
+        MailboxACL result = u1u2g1g2ACL.except(new SimpleMailboxACLEntryKey(USER_1), SimpleMailboxACL.FULL_RIGHTS);
+
+        Map<MailboxACLEntryKey, MailboxACLRights> foundEntries = result.getEntries();
+
+        assertEquals(expectedEntries, foundEntries);
+    }
+
+}

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=1292019&r1=1292018&r2=1292019&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 Tue Feb 21 21:05:02 2012
@@ -50,6 +50,8 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.exception.ReadOnlyException;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxACL.EditMode;
+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.MessageMetaData;
@@ -732,34 +734,49 @@ public class StoreMessageManager<Id> imp
     }
 
     /**
-     * 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
+     * @see org.apache.james.mailbox.MessageManager#myRights(org.apache.james.mailbox.MailboxSession)
      */
+    @Override
     public MailboxACLRights myRights(MailboxSession session) throws MailboxException {
         User user = session.getUser();
         if (user != null) {
-            return listRigths(user.getUserName(), session);
+            return aclResolver.resolveRights(user.getUserName(), groupMembershipResolver, mailbox.getACL(), mailbox.getUser(), isGroupFolder(session));
         } else {
             return SimpleMailboxACL.NO_RIGHTS;
         }
     }
 
     /**
-     * Returns the rights applicable to the given user.
-     * 
-     * @param user
-     * @param session
-     * @return
-     * @throws UnsupportedRightException
+     * @see org.apache.james.mailbox.MessageManager#listRigths(java.lang.String, org.apache.james.mailbox.MailboxSession)
      */
-    public MailboxACLRights listRigths(String user, MailboxSession session) throws UnsupportedRightException {
-        return aclResolver.listRights(user, groupMembershipResolver, mailbox.getACL(), mailbox.getUser(), isGroupFolder(session));
+    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);
     }
 
     /**

Modified: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java?rev=1292019&r1=1292018&r2=1292019&view=diff
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java (original)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java Tue Feb 21 21:05:02 2012
@@ -46,9 +46,13 @@ import org.apache.james.mailbox.MailboxS
 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.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.Content;
 import org.apache.james.mailbox.model.Headers;
+import org.apache.james.mailbox.model.MailboxACL.EditMode;
+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.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
@@ -296,12 +300,22 @@ public class MailboxEventAnalyserTest {
 
                 }
                 
-                
                 public boolean hasRight(MailboxACLRight right, MailboxSession session) throws MailboxException {
-                    //FIXME: somebody should approve that always true is the proper result here
                     return true;
                 }
 
+                public MailboxACLRights myRights(MailboxSession session) throws MailboxException {
+                    throw new UnsupportedOperationException("Not implemented");
+                }
+
+                public MailboxACLRights[] listRigths(MailboxACLEntryKey identifier, MailboxSession session) throws UnsupportedRightException {
+                    throw new UnsupportedOperationException("Not implemented");
+                }
+
+                public void setRights(MailboxACLEntryKey mailboxACLEntryKey, EditMode editMode, MailboxACLRights mailboxAclRights) throws UnsupportedRightException {
+                    throw new UnsupportedOperationException("Not implemented");
+                }
+
             };
         }
         



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


Mime
View raw message