MAILBOX-316 New JMAP listener for adding lookup right to parent mailbox when child mailbox has 'l' right
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/75622f7b Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/75622f7b Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/75622f7b Branch: refs/heads/master Commit: 75622f7b13c73b745f8bb812e206d83ce36ed0a2 Parents: ef4b79c Author: quynhn <[email protected]> Authored: Mon Nov 6 16:04:21 2017 +0700 Committer: quynhn <[email protected]> Committed: Wed Nov 15 09:33:58 2017 +0700 ---------------------------------------------------------------------- .../modules/mailbox/CassandraMailboxModule.java | 4 + .../modules/mailbox/MemoryMailboxModule.java | 4 + server/protocols/jmap/pom.xml | 4 + .../event/PropagateLookupRightListener.java | 128 +++++++ .../event/PropagateLookupRightListenerTest.java | 340 +++++++++++++++++++ 5 files changed, 480 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/75622f7b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java index 220f351..35e524c 100644 --- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java +++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -28,6 +28,7 @@ import org.apache.james.mailbox.BlobManager; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxPathLocker; import org.apache.james.mailbox.MessageIdManager; +import org.apache.james.mailbox.RightManager; import org.apache.james.mailbox.SubscriptionManager; import org.apache.james.mailbox.cassandra.CassandraMailboxManager; import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory; @@ -59,6 +60,7 @@ import org.apache.james.mailbox.store.NoMailboxPathLocker; import org.apache.james.mailbox.store.StoreAttachmentManager; import org.apache.james.mailbox.store.StoreBlobManager; import org.apache.james.mailbox.store.StoreMessageIdManager; +import org.apache.james.mailbox.store.StoreRightManager; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.AttachmentMapperFactory; import org.apache.james.mailbox.store.mail.MailboxMapperFactory; @@ -107,6 +109,7 @@ public class CassandraMailboxModule extends AbstractModule { bind(CassandraUserMailboxRightsDAO.class).in(Scopes.SINGLETON); bind(CassandraACLMapper.class).in(Scopes.SINGLETON); bind(StoreBlobManager.class).in(Scopes.SINGLETON); + bind(StoreRightManager.class).in(Scopes.SINGLETON); bind(BlobManager.class).to(StoreBlobManager.class); bind(MessageMapperFactory.class).to(CassandraMailboxSessionMapperFactory.class); @@ -125,6 +128,7 @@ public class CassandraMailboxModule extends AbstractModule { bind(MessageId.Factory.class).to(CassandraMessageId.Factory.class); bind(MessageIdManager.class).to(StoreMessageIdManager.class); bind(AttachmentManager.class).to(StoreAttachmentManager.class); + bind(RightManager.class).to(StoreRightManager.class); Multibinder<CassandraModule> cassandraDataDefinitions = Multibinder.newSetBinder(binder(), CassandraModule.class); cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.modules.CassandraAclModule.class); http://git-wip-us.apache.org/repos/asf/james-project/blob/75622f7b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java index 204dbf3..32349e8 100644 --- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java +++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java @@ -28,6 +28,7 @@ import org.apache.james.mailbox.BlobManager; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxPathLocker; import org.apache.james.mailbox.MessageIdManager; +import org.apache.james.mailbox.RightManager; import org.apache.james.mailbox.SubscriptionManager; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.extractor.TextExtractor; @@ -49,6 +50,7 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory; import org.apache.james.mailbox.store.StoreAttachmentManager; import org.apache.james.mailbox.store.StoreBlobManager; import org.apache.james.mailbox.store.StoreMessageIdManager; +import org.apache.james.mailbox.store.StoreRightManager; import org.apache.james.mailbox.store.StoreSubscriptionManager; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.AttachmentMapperFactory; @@ -99,6 +101,7 @@ public class MemoryMailboxModule extends AbstractModule { bind(MessageSearchIndex.class).to(SimpleMessageSearchIndex.class); bind(TextExtractor.class).to(JsoupTextExtractor.class); + bind(RightManager.class).to(StoreRightManager.class); bind(StoreBlobManager.class).in(Scopes.SINGLETON); bind(InMemoryMailboxSessionMapperFactory.class).in(Scopes.SINGLETON); @@ -113,6 +116,7 @@ public class MemoryMailboxModule extends AbstractModule { bind(StoreMessageIdManager.class).in(Scopes.SINGLETON); bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON); bind(StoreAttachmentManager.class).in(Scopes.SINGLETON); + bind(StoreRightManager.class).in(Scopes.SINGLETON); Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class) .addBinding() http://git-wip-us.apache.org/repos/asf/james-project/blob/75622f7b/server/protocols/jmap/pom.xml ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml index 5cebbd0..f03b6e4 100644 --- a/server/protocols/jmap/pom.xml +++ b/server/protocols/jmap/pom.xml @@ -45,6 +45,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-store</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>apache-james-mailbox-memory</artifactId> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/75622f7b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java new file mode 100644 index 0000000..fe12d68 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java @@ -0,0 +1,128 @@ +/**************************************************************** + * 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.jmap.event; + +import java.util.stream.Stream; + +import javax.inject.Inject; + +import org.apache.james.mailbox.MailboxListener; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.RightManager; +import org.apache.james.mailbox.acl.ACLDiff; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxACL; +import org.apache.james.mailbox.model.MailboxACL.Entry; +import org.apache.james.mailbox.model.MailboxACL.Right; +import org.apache.james.mailbox.model.MailboxPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Throwables; + +public class PropagateLookupRightListener implements MailboxListener { + private static final Logger LOGGER = LoggerFactory.getLogger(PropagateLookupRightListener.class); + + private final RightManager rightManager; + + @Inject + public PropagateLookupRightListener(RightManager rightManager) { + this.rightManager = rightManager; + } + + @Override + public ListenerType getType() { + return ListenerType.ONCE; + } + + @Override + public ExecutionMode getExecutionMode() { + return ExecutionMode.SYNCHRONOUS; + } + + @Override + public void event(Event event) { + MailboxSession mailboxSession = event.getSession(); + + if (event instanceof MailboxACLUpdated) { + MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event; + + updateLookupRightOnParent(mailboxSession, event.getMailboxPath(), aclUpdateEvent.getAclDiff()); + } else if (event instanceof MailboxRenamed) { + MailboxRenamed renamedEvent = (MailboxRenamed) event; + updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath()); + } + } + + private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) { + try { + MailboxACL acl = rightManager.listRights(path, session); + listAncestors(session, path) + .forEach(parentMailboxPath -> + updateLookupRight( + session, + parentMailboxPath, + acl.getEntries() + .entrySet() + .stream() + .map(entry -> new Entry(entry.getKey(), entry.getValue())) + )); + } catch (MailboxException e) { + Throwables.propagate(e); + } + } + + private void updateLookupRightOnParent(MailboxSession mailboxSession, MailboxPath mailboxPath, ACLDiff aclDiff) { + listAncestors(mailboxSession, mailboxPath) + .forEach(path -> + updateLookupRight( + mailboxSession, path, + Stream.concat(aclDiff.addedEntries(), aclDiff.changedEntries()) + )); + } + + private void updateLookupRight(MailboxSession session, MailboxPath mailboxPath, Stream<Entry> entries) { + entries + .filter(entry -> !entry.getKey().isNegative()) + .filter(entry -> entry.getValue().contains(Right.Lookup)) + .forEach(entry -> applyLookupRight(session, mailboxPath, entry)); + } + + private Stream<MailboxPath> listAncestors(MailboxSession mailboxSession, MailboxPath mailboxPath) { + return mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter()) + .stream() + .filter(hierarchyMailboxPath -> !hierarchyMailboxPath.equals(mailboxPath)); + } + + private void applyLookupRight(MailboxSession session, MailboxPath mailboxPath, Entry entry) { + try { + rightManager.applyRightsCommand(mailboxPath, + MailboxACL.command() + .rights(Right.Lookup) + .key(entry.getKey()) + .asAddition(), + session); + } catch (MailboxException e) { + LOGGER.error(String.format("Mailbox '%s' does not exist, user '%s' cannot share mailbox", + mailboxPath, + session.getUser().getUserName()), e); + } + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/75622f7b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java new file mode 100644 index 0000000..4cf96ad --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java @@ -0,0 +1,340 @@ +/**************************************************************** + * 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.jmap.event; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.MailboxListener; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.MessageManager; +import org.apache.james.mailbox.acl.GroupMembershipResolver; +import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; +import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; +import org.apache.james.mailbox.mock.MockMailboxSession; +import org.apache.james.mailbox.model.MailboxACL; +import org.apache.james.mailbox.model.MailboxACL.Entry; +import org.apache.james.mailbox.model.MailboxACL.EntryKey; +import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights; +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.mailbox.store.MailboxSessionMapperFactory; +import org.apache.james.mailbox.store.StoreMailboxManager; +import org.apache.james.mailbox.store.StoreRightManager; +import org.apache.james.mailbox.store.mail.model.Mailbox; +import org.junit.Before; +import org.junit.Test; + +public class PropagateLookupRightListenerTest { + private static final boolean RESET_RECENT = false; + private static final String OWNER_USER = "user"; + private static final String SHARED_USER = "sharee"; + private static final EntryKey SHARED_USER_KEY = EntryKey.createUserEntryKey(SHARED_USER); + + private static final MailboxPath PARENT_MAILBOX = MailboxPath.forUser(OWNER_USER, "shared"); + private static final MailboxPath CHILD_MAILBOX = MailboxPath.forUser(OWNER_USER, "shared.sub1"); + + private static final MailboxPath PARENT_MAILBOX1 = MailboxPath.forUser(OWNER_USER, "shared1"); + private static final MailboxPath CHILD_MAILBOX1 = MailboxPath.forUser(OWNER_USER, "shared1.sub1"); + + private static final MailboxPath GRAND_CHILD_MAILBOX = MailboxPath.forUser(OWNER_USER, "shared.sub1.sub2"); + + private StoreRightManager storeRightManager; + private StoreMailboxManager storeMailboxManager; + private PropagateLookupRightListener testee; + + private MailboxSession mailboxSession = new MockMailboxSession(OWNER_USER); + + private MailboxId parentMailboxId; + private MailboxId parentMailboxId1; + private MailboxId childMailboxId; + private MailboxId childMailboxId1; + private MailboxId grandChildMailboxId; + private Entry lookupEntry; + + private MailboxSessionMapperFactory mailboxMapper; + + @Before + public void setup() throws Exception { + GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver(); + storeMailboxManager = new InMemoryIntegrationResources() + .createMailboxManager(groupMembershipResolver); + storeRightManager = storeMailboxManager.getStoreRightManager(); + mailboxMapper = storeMailboxManager.getMapperFactory(); + + testee = new PropagateLookupRightListener(storeRightManager); + storeMailboxManager.addGlobalListener(testee, mailboxSession); + + parentMailboxId = storeMailboxManager.createMailbox(PARENT_MAILBOX, mailboxSession).get(); + parentMailboxId1 = storeMailboxManager.createMailbox(PARENT_MAILBOX1, mailboxSession).get(); + childMailboxId = storeMailboxManager.createMailbox(CHILD_MAILBOX, mailboxSession).get(); + childMailboxId1 = storeMailboxManager.createMailbox(CHILD_MAILBOX1, mailboxSession).get(); + grandChildMailboxId = storeMailboxManager.createMailbox(GRAND_CHILD_MAILBOX, mailboxSession).get(); + + lookupEntry = new Entry(SHARED_USER, "l"); + } + + @Test + public void getTypeShouldReturnOnce() throws Exception { + assertThat(testee.getType()).isEqualTo(MailboxListener.ListenerType.ONCE); + } + + @Test + public void getExecutionModeShouldReturnAsynchronous() throws Exception { + assertThat(testee.getExecutionMode()).isEqualTo(MailboxListener.ExecutionMode.SYNCHRONOUS); + } + + @Test + public void eventShouldDoNothingWhenEmptyNewRights() throws Exception { + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(SHARED_USER_KEY) + .rights() + .asAddition(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .doesNotContainKeys(SHARED_USER_KEY); + } + + @Test + public void eventShouldDoNothingWhenNewACLIsTheSameAsTheOldOne() throws Exception { + Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup)))); + + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(SHARED_USER_KEY) + .rights(Right.Lookup) + .asAddition(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .doesNotContainKeys(SHARED_USER_KEY); + } + + @Test + public void eventShouldUpdateParentWhenMailboxACLAddLookupRight() throws Exception { + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(SHARED_USER_KEY) + .rights(Right.Lookup) + .asAddition(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .hasSize(2) + .contains(lookupEntry); + } + + @Test + public void eventShouldUpdateParentWhenMailboxACLUpdateLookupRight() throws Exception { + Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); + + storeRightManager.setRights( + GRAND_CHILD_MAILBOX, + new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup))), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .hasSize(2) + .contains(lookupEntry); + } + + @Test + public void eventShouldUpdateAllParentWhenMailboxACLUpdateLookupRight() throws Exception { + Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); + + storeRightManager.setRights( + GRAND_CHILD_MAILBOX, + new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup))), + mailboxSession); + + MailboxACL actualParentACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + MailboxACL actualChildACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualParentACL.getEntries()) + .contains(lookupEntry); + assertThat(actualChildACL.getEntries()) + .contains(lookupEntry); + } + + @Test + public void eventShouldDoNothingWhenMailboxACLRemoveLookupRight() throws Exception { + Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); + + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(SHARED_USER_KEY) + .rights(Right.Lookup) + .asRemoval(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .doesNotContainKeys(SHARED_USER_KEY); + } + + @Test + public void eventShouldDoNothingWhenMailboxACLButNoLookupRight() throws Exception { + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(SHARED_USER_KEY) + .rights(Right.Administer) + .asAddition(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .doesNotContainKeys(SHARED_USER_KEY); + } + + @Test + public void eventShouldDoNothingWhenMailboxACLUpdatedButNoLookupRight() throws Exception { + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(SHARED_USER_KEY) + .rights(Right.Administer) + .asReplacement(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .doesNotContainKeys(SHARED_USER_KEY); + } + + @Test + public void eventShouldUpdateNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception { + Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); + + storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .contains(lookupEntry); + } + + @Test + public void eventShouldNotUpdateNewParentWhenRenameMailboxWhichDoesContainLookupRight() throws Exception { + Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); + + storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .doesNotContainKeys(SHARED_USER_KEY); + } + + @Test + public void eventShouldUpdateAllNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception { + Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); + mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( + new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); + + storeMailboxManager.renameMailbox(GRAND_CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1.sub2"), mailboxSession); + + MailboxACL parentActualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + MailboxACL childActualACL = storeMailboxManager.getMailbox(childMailboxId1, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(parentActualACL.getEntries()) + .contains(lookupEntry); + assertThat(childActualACL.getEntries()) + .contains(lookupEntry); + } + + @Test + public void eventShouldDoNothingWhenNegativeACLEntry() throws Exception { + EntryKey negativeUserKey = EntryKey.createUserEntryKey(SHARED_USER, true); + storeRightManager.applyRightsCommand( + GRAND_CHILD_MAILBOX, + MailboxACL.command() + .key(negativeUserKey) + .rights(Right.Lookup) + .asAddition(), + mailboxSession); + + MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) + .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) + .getACL(); + + assertThat(actualACL.getEntries()) + .hasSize(1) + .doesNotContainKeys(negativeUserKey); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
