JAMES-2186 refactoring remove MailboxACL::hasRight

I removed this long and complicated method and replace it's use by
resolveRight(..).hasRight(..)


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

Branch: refs/heads/master
Commit: b44dc56f498ce19e2cc7c6001041ad4e60872fe7
Parents: 7c0099f
Author: Luc DUZAN <[email protected]>
Authored: Mon Oct 23 11:22:32 2017 +0700
Committer: Raphael Ouazana <[email protected]>
Committed: Wed Oct 25 17:40:11 2017 +0200

----------------------------------------------------------------------
 .../org/apache/james/mailbox/RightManager.java  |   15 +
 .../james/mailbox/acl/MailboxACLResolver.java   |   30 -
 .../mailbox/acl/UnionMailboxACLResolver.java    |   44 -
 .../acl/UnionMailboxACLResolverTest.java        | 1591 +++++++++++++-----
 .../james/mailbox/store/StoreRightManager.java  |   40 +-
 5 files changed, 1215 insertions(+), 505 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b44dc56f/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
index 7700a86..0d2fc79 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
@@ -20,10 +20,12 @@
 package org.apache.james.mailbox;
 
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mime4j.dom.address.Mailbox;
 
 public interface RightManager {
     /**
@@ -41,6 +43,19 @@ public interface RightManager {
     boolean hasRight(MailboxPath mailboxPath, Right right, MailboxSession 
session) throws MailboxException;
 
     /**
+     * Tells whether the given {@link MailboxSession}'s user has the given
+     * {@link MailboxACL.Right} for this {@link MessageManager}'s mailbox.
+     *
+     * @param mailboxId MailboxId of the mailbox 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.Right} for this {@link MessageManager}'s
+     *         mailbox; false otherwise.
+     * @throws MailboxException in case of unknown mailbox or unsupported right
+     */
+    boolean hasRight(MailboxId mailboxId, Right right, 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}.
      *

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44dc56f/mailbox/api/src/main/java/org/apache/james/mailbox/acl/MailboxACLResolver.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/MailboxACLResolver.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/MailboxACLResolver.java
index f858756..88f7e39 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/MailboxACLResolver.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/MailboxACLResolver.java
@@ -56,36 +56,6 @@ public interface MailboxACLResolver {
     MailboxACL applyGlobalACL(MailboxACL resourceACL, boolean 
resourceOwnerIsGroup) throws UnsupportedRightException;
 
     /**
-     * Tells whether the given user has the given right granted on the basis of
-     * the given resourceACL. Global ACL (if there is any) should be applied
-     * within this method.
-     * 
-     * @param requestUser
-     *            the user for whom the given right is tested, possibly
-     *            <code>null</code> when there is no authenticated user in the
-     *            given context.
-     * @param groupMembershipResolver
-     *            this resolver is used when checking whether any group rights
-     *            contained in resourceACL are applicable for the requestUser.
-     * @param right
-     *            the right which will be proven to apply for the given
-     *            requestUser.
-     * @param resourceACL
-     *            the ACL defining the access right for the resource in
-     *            question.
-     * @param resourceOwner
-     *            this user name is used as a replacement for the "owner" place
-     *            holder in the resourceACL.
-     * @param resourceOwnerIsGroup
-     *            true if the resourceOwner is a group of users, false
-     *            otherwise.
-     * @return true if the given user has the given right for the given
-     *         resource; false otherwise.
-     * @throws UnsupportedRightException
-     */
-    boolean hasRight(String requestUser, GroupMembershipResolver 
groupMembershipResolver, MailboxACL.Right right, MailboxACL resourceACL, String 
resourceOwner, boolean resourceOwnerIsGroup) throws UnsupportedRightException;
-
-    /**
      * Maps the given {@code mailboxACLRights} to READ-WRITE and READ-ONLY
      * response codes.
      * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44dc56f/mailbox/api/src/main/java/org/apache/james/mailbox/acl/UnionMailboxACLResolver.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/UnionMailboxACLResolver.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/UnionMailboxACLResolver.java
index 8f51b1a..528d6d5 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/UnionMailboxACLResolver.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/UnionMailboxACLResolver.java
@@ -235,50 +235,6 @@ public class UnionMailboxACLResolver implements 
MailboxACLResolver {
     }
 
     /**
-     * @see 
org.apache.james.mailbox.store.mail.MailboxACLResolver#hasRight(java.
-     *      lang.String, 
org.apache.james.mailbox.store.mail.MailboxACLResolver.
-     *      GroupMembershipResolver,
-     *      org.apache.james.mailbox.MailboxACL.Right,
-     *      org.apache.james.mailbox.MailboxACL, java.lang.String)
-     */
-    @Override
-    public boolean hasRight(String requestUser, GroupMembershipResolver 
groupMembershipResolver, Right right, MailboxACL resourceACL, String 
resourceOwner, boolean resourceOwnerIsGroup) throws UnsupportedRightException {
-        final EntryKey queryKey = requestUser == null ? null : new 
EntryKey(requestUser, NameType.user, false);
-        boolean result = false;
-        Map<EntryKey, Rfc4314Rights> entries = resourceOwnerIsGroup ? 
groupGlobalACL.getEntries() : userGlobalACL.getEntries();
-        if (entries != null) {
-            for (Entry<EntryKey, Rfc4314Rights> entry : entries.entrySet()) {
-                final EntryKey key = entry.getKey();
-                if (applies(key, queryKey, groupMembershipResolver, 
resourceOwner, resourceOwnerIsGroup) && entry.getValue().contains(right)) {
-                    if (key.isNegative()) {
-                        return false;
-                    } else {
-                        result = true;
-                    }
-                }
-            }
-        }
-
-        if (resourceACL != null) {
-            entries = resourceACL.getEntries();
-            if (entries != null) {
-                for (Entry<EntryKey, Rfc4314Rights> entry : 
entries.entrySet()) {
-                    final EntryKey key = entry.getKey();
-                    if (applies(key, queryKey, groupMembershipResolver, 
resourceOwner, resourceOwnerIsGroup) && entry.getValue().contains(right)) {
-                        if (key.isNegative()) {
-                            return false;
-                        } else {
-                            result = true;
-                        }
-                    }
-                }
-            }
-        }
-
-        return result;
-    }
-
-    /**
      * @see 
org.apache.james.mailbox.acl.MailboxACLResolver#isReadWrite(org.apache.james.mailbox.model.Rfc4314Rights,
      *      javax.mail.Flags)
      */


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

Reply via email to