JAMES-2169 introduce MailboxACL.command() to ease ACLCommand usage
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d5bb0b4e Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d5bb0b4e Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d5bb0b4e Branch: refs/heads/master Commit: d5bb0b4e07fac875142f5171a99323c935adb39f Parents: af0aab6 Author: Matthieu Baechler <matth...@apache.org> Authored: Fri Sep 29 16:14:01 2017 +0200 Committer: benwa <btell...@linagora.com> Committed: Wed Oct 4 16:19:58 2017 +0700 ---------------------------------------------------------------------- .../apache/james/mailbox/model/MailboxACL.java | 81 ++++++++++++++++++- .../james/mailbox/model/MailboxACLTest.java | 2 +- .../cassandra/mail/CassandraACLMapperTest.java | 23 +++--- .../store/mail/model/MailboxMapperACLTest.java | 84 +++++--------------- .../imap/processor/DeleteACLProcessor.java | 7 +- .../james/imap/processor/SetACLProcessor.java | 3 +- .../imap/processor/DeleteACLProcessorTest.java | 2 +- .../imap/processor/SetACLProcessorTest.java | 2 +- .../org/apache/james/modules/ACLProbeImpl.java | 8 +- 9 files changed, 123 insertions(+), 89 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java index a831302..569eeae 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java @@ -52,6 +52,10 @@ import com.google.common.collect.ImmutableMap; */ public class MailboxACL { + public static ACLCommand.Builder command() { + return new ACLCommand.Builder(); + } + private static EnumSet<Right> copyOf(Collection<Right> collection) { if (collection.isEmpty()) { return EnumSet.noneOf(Right.class); @@ -503,11 +507,85 @@ public class MailboxACL { public static class ACLCommand { + + public static class Builder { + + private EntryKey key; + private EditMode editMode; + private Rfc4314Rights rights; + + private Builder() { + } + + public Builder forUser(String user) { + key = EntryKey.createUser(user); + return this; + } + + public Builder forGroup(String group) { + key = EntryKey.createGroup(group); + return this; + } + + + public Builder key(EntryKey key) { + this.key = key; + return this; + } + + public Builder rights(Rfc4314Rights rights) { + this.rights = rights; + return this; + } + + public Builder rights(Right... rights) throws UnsupportedRightException { + this.rights = + Optional.ofNullable(this.rights) + .orElse(new Rfc4314Rights()) + .union(new Rfc4314Rights(rights)); + return this; + } + + public Builder noRights() { + this.rights = new Rfc4314Rights(); + return this; + } + + + public Builder mode(EditMode mode) { + editMode = mode; + return this; + } + + public ACLCommand asReplacement() { + editMode = EditMode.REPLACE; + return build(); + } + + public ACLCommand asAddition() { + editMode = EditMode.ADD; + return build(); + } + + public ACLCommand asRemoval() { + editMode = EditMode.REMOVE; + return build(); + } + + public ACLCommand build() { + Preconditions.checkState(key != null); + Preconditions.checkState(editMode != null); + Preconditions.checkState(rights != null); + return new ACLCommand(key, editMode, rights); + } + + } + private final EntryKey key; private final EditMode editMode; private final Rfc4314Rights rights; - public ACLCommand(EntryKey key, EditMode editMode, Rfc4314Rights rights) { + private ACLCommand(EntryKey key, EditMode editMode, Rfc4314Rights rights) { this.key = key; this.editMode = editMode; this.rights = rights; @@ -744,6 +822,7 @@ public class MailboxACL { .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue))); } else { return Optional.ofNullable(replacement) + .filter(rights -> !rights.isEmpty()) .map(replacementValue -> new MailboxACL( ImmutableMap.<EntryKey, Rfc4314Rights>builder() .putAll(entries) http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java index 16734d5..7bbb4eb 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java @@ -220,7 +220,7 @@ public class MailboxACLTest { @Test public void applyShouldNotThrowWhenRemovingANonExistingEntry() throws Exception{ assertThat(MailboxACL.EMPTY - .apply(new MailboxACL.ACLCommand(EntryKey.createUser("bob"), MailboxACL.EditMode.REPLACE, null))) + .apply(MailboxACL.command().forUser("bob").noRights().asReplacement())) .isEqualTo(MailboxACL.EMPTY); } http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java ---------------------------------------------------------------------- diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java index 063651c..bc5a7e7 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java @@ -38,6 +38,7 @@ import org.apache.james.mailbox.cassandra.modules.CassandraAclModule; import org.apache.james.mailbox.cassandra.table.CassandraACLTable; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MailboxACL; +import org.apache.james.mailbox.store.mail.model.Mailbox; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -89,7 +90,7 @@ public class CassandraACLMapperTest { MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, - new MailboxACL.ACLCommand(key, MailboxACL.EditMode.ADD, rights)); + MailboxACL.command().key(key).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(key, rights)); @@ -100,9 +101,9 @@ public class CassandraACLMapperTest { MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(keyBob, MailboxACL.EditMode.ADD, rights)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBob).rights(rights).asAddition()); MailboxACL.EntryKey keyAlice = new MailboxACL.EntryKey("alice", MailboxACL.NameType.user, false); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(keyAlice, MailboxACL.EditMode.ADD, rights)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyAlice).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(keyBob, rights).union(keyAlice, rights)); @@ -113,8 +114,8 @@ public class CassandraACLMapperTest { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.ADD, rights)); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.REMOVE, rights)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asRemoval()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(MailboxACL.EMPTY); } @@ -124,8 +125,8 @@ public class CassandraACLMapperTest { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.ADD, rights)); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.REPLACE, null)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).noRights().asReplacement()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(MailboxACL.EMPTY); } @@ -135,7 +136,7 @@ public class CassandraACLMapperTest { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.REPLACE, rights)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asReplacement()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(new MailboxACL().union(key, rights)); } @@ -150,7 +151,7 @@ public class CassandraACLMapperTest { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.ADD, rights)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(new MailboxACL().union(key, rights)); } @@ -174,7 +175,7 @@ public class CassandraACLMapperTest { CountDownLatch countDownLatch = new CountDownLatch(2); MailboxACL.EntryKey keyBenwa = new MailboxACL.EntryKey("benwa", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); - cassandraACLMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(keyBenwa, MailboxACL.EditMode.ADD, rights)); + cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBenwa).rights(rights).asAddition()); MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.EntryKey keyAlice = new MailboxACL.EntryKey("alice", MailboxACL.NameType.user, false); @@ -200,7 +201,7 @@ public class CassandraACLMapperTest { CassandraConfiguration.DEFAULT_CONFIGURATION, runnable); try { - aclMapper.updateACL(MAILBOX_ID, new MailboxACL.ACLCommand(key, MailboxACL.EditMode.ADD, rights)); + aclMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); } catch (MailboxException exception) { throw Throwables.propagate(exception); } http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java index adf7dba..321fd75 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java @@ -76,10 +76,7 @@ public abstract class MailboxMapperACLTest { public void updateAclShouldSaveAclWhenReplace() throws MailboxException { EntryKey key = new EntryKey("user", NameType.user, NEGATIVE); Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -94,14 +91,9 @@ public abstract class MailboxMapperACLTest { EntryKey key = new EntryKey("user", NameType.user, NEGATIVE); Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - newRights)); + + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asReplacement()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -117,14 +109,8 @@ public abstract class MailboxMapperACLTest { EntryKey key2 = new EntryKey("user", NameType.user, POSITIVE); Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key1, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key2, - MailboxACL.EditMode.REPLACE, - newRights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key1).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key2).rights(newRights).asReplacement()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -141,14 +127,8 @@ public abstract class MailboxMapperACLTest { EntryKey key2 = new EntryKey("user", NameType.group, NEGATIVE); Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key1, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key2, - MailboxACL.EditMode.REPLACE, - newRights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key1).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key2).rights(newRights).asReplacement()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -164,14 +144,8 @@ public abstract class MailboxMapperACLTest { EntryKey key = new EntryKey("user", NameType.user, NEGATIVE); Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights newRights = new Rfc4314Rights(); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - newRights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asReplacement()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -186,14 +160,8 @@ public abstract class MailboxMapperACLTest { Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages); Rfc4314Rights bothRights = new Rfc4314Rights(Right.Administer, Right.WriteSeenFlag, Right.PerformExpunge, Right.Write, Right.CreateMailbox, Right.DeleteMessages); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.ADD, - newRights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asAddition()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -209,14 +177,8 @@ public abstract class MailboxMapperACLTest { Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights removedRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.PerformExpunge); Rfc4314Rights finalRights = new Rfc4314Rights(Right.Administer, Right.Write); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REMOVE, - removedRights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(removedRights).asRemoval()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -232,14 +194,8 @@ public abstract class MailboxMapperACLTest { Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights removedRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.PerformExpunge, Right.Lookup); Rfc4314Rights finalRights = new Rfc4314Rights(Right.Administer, Right.Write); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REMOVE, - removedRights)); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(removedRights).asRemoval()); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) @@ -254,12 +210,8 @@ public abstract class MailboxMapperACLTest { EntryKey key = new EntryKey("user", NameType.user, NEGATIVE); Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag); Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages); - mailboxMapper.updateACL(benwaInboxMailbox, - new MailboxACL.ACLCommand(key, - MailboxACL.EditMode.REPLACE, - rights)); - mailboxMapper.setACL(benwaInboxMailbox, - new MailboxACL(ImmutableMap.of(key, newRights))); + mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()); + mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(ImmutableMap.of(key, newRights))); assertThat( mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()) http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java index 36286f1..0394a05 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java @@ -112,8 +112,11 @@ public class DeleteACLProcessor extends AbstractMailboxProcessor<DeleteACLReques // Note that Section 6 recommends additional identifierâs verification // steps. - mailboxManager.applyRightsCommand(mailboxPath, - new MailboxACL.ACLCommand(key, EditMode.REPLACE, null), mailboxSession); + mailboxManager.applyRightsCommand( + mailboxPath, + MailboxACL.command().key(key).noRights().asReplacement(), + mailboxSession + ); okComplete(command, tag, responder); // FIXME should we send unsolicited responses here? http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java index f03c6f6..eb22c1d 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java @@ -130,7 +130,8 @@ public class SetACLProcessor extends AbstractMailboxProcessor<SetACLRequest> imp // steps. mailboxManager.applyRightsCommand(mailboxPath, - new MailboxACL.ACLCommand(key, editMode, mailboxAclRights), mailboxSession); + MailboxACL.command().key(key).mode(editMode).rights(mailboxAclRights).build(), + mailboxSession); okComplete(command, tag, responder); // FIXME should we send unsolicited responses here? http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java index b6c79cb..73f3bf3 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java @@ -199,7 +199,7 @@ public class DeleteACLProcessorTest { expectations.allowing(mailboxManagerStub).hasRight(expectations.with(path), expectations.with(Expectations.equal(MailboxACL.Right.Administer)), expectations.with(Expectations.same(mailboxSessionStub))); expectations.will(Expectations.returnValue(true)); - expectations.allowing(mailboxManagerStub).applyRightsCommand(expectations.with(path), expectations.with(new MailboxACL.ACLCommand(user1Key, EditMode.REPLACE, null)), expectations.with(mailboxSessionStub)); + expectations.allowing(mailboxManagerStub).applyRightsCommand(expectations.with(path), expectations.with(MailboxACL.command().key(user1Key).noRights().asReplacement()), expectations.with(mailboxSessionStub)); expectations.allowing(metaDataStub).getACL(); expectations.will(Expectations.returnValue(acl)); http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java index ab4d8e8..b09a8ae 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java @@ -229,7 +229,7 @@ public class SetACLProcessorTest { expectations.allowing(mailboxManagerStub).hasRight(expectations.with(path), expectations.with(Expectations.equal(MailboxACL.Right.Administer)), expectations.with(Expectations.same(mailboxSessionStub))); expectations.will(Expectations.returnValue(true)); - expectations.allowing(mailboxManagerStub).applyRightsCommand(expectations.with(path), expectations.with(Expectations.equal(new MailboxACL.ACLCommand(user1Key, editMode, setRights))), expectations.with(mailboxSessionStub)); + expectations.allowing(mailboxManagerStub).applyRightsCommand(expectations.with(path), expectations.with(Expectations.equal(MailboxACL.command().key(user1Key).mode(editMode).rights(setRights).build())), expectations.with(mailboxSessionStub)); expectations.allowing(metaDataStub).getACL(); expectations.will(Expectations.returnValue(acl)); http://git-wip-us.apache.org/repos/asf/james-project/blob/d5bb0b4e/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java index a25c4d9..0435e37 100644 --- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java +++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/ACLProbeImpl.java @@ -24,9 +24,8 @@ import javax.inject.Inject; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxACL; import org.apache.james.mailbox.model.MailboxACL.ACLCommand; -import org.apache.james.mailbox.model.MailboxACL.EditMode; -import org.apache.james.mailbox.model.MailboxACL.EntryKey; import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.store.probe.ACLProbe; @@ -44,8 +43,7 @@ public class ACLProbeImpl implements GuiceProbe, ACLProbe { public void replaceRights(MailboxPath mailboxPath, String targetUser, Rfc4314Rights rights) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); - EntryKey key = EntryKey.createUser(targetUser); - ACLCommand mailboxACLCommand = new ACLCommand(key, EditMode.REPLACE, rights); - mailboxManager.applyRightsCommand(mailboxPath, mailboxACLCommand, mailboxSession); + ACLCommand command = MailboxACL.command().forUser(targetUser).rights(rights).asReplacement(); + mailboxManager.applyRightsCommand(mailboxPath, command, mailboxSession); } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org