@Test void filteredForSessionShouldContainOnlyLoggedUserWhenReadWriteAccess() throws UnsupportedRightException { MailboxACL acl = new MailboxACL() .apply(MailboxACL.command().rights(Right.Read, Right.Write).forUser(BOB).asAddition()) .apply(MailboxACL.command().rights(Right.Read, Right.Write, Right.Administer).forUser(CEDRIC).asAddition()); MailboxACL actual = StoreRightManager.filteredForSession( new Mailbox(INBOX_ALICE, UID_VALIDITY, MAILBOX_ID), acl, MailboxSessionUtil.create(BOB)); assertThat(actual.getEntries()).containsKey(MailboxACL.EntryKey.createUserEntryKey(BOB)); }
@VisibleForTesting static MailboxACL filteredForSession(Mailbox mailbox, MailboxACL acl, MailboxSession mailboxSession) throws UnsupportedRightException { if (mailbox.generateAssociatedPath().belongsTo(mailboxSession)) { return acl; } MailboxACL.EntryKey userAsKey = MailboxACL.EntryKey.createUserEntryKey(mailboxSession.getUser()); Rfc4314Rights rights = acl.getEntries().getOrDefault(userAsKey, new Rfc4314Rights()); if (rights.contains(MailboxACL.Right.Administer)) { return acl; } return new MailboxACL(ImmutableMap.of(userAsKey, rights)); }
StoreRightManager implements RightManager { @VisibleForTesting static MailboxACL filteredForSession(Mailbox mailbox, MailboxACL acl, MailboxSession mailboxSession) throws UnsupportedRightException { if (mailbox.generateAssociatedPath().belongsTo(mailboxSession)) { return acl; } MailboxACL.EntryKey userAsKey = MailboxACL.EntryKey.createUserEntryKey(mailboxSession.getUser()); Rfc4314Rights rights = acl.getEntries().getOrDefault(userAsKey, new Rfc4314Rights()); if (rights.contains(MailboxACL.Right.Administer)) { return acl; } return new MailboxACL(ImmutableMap.of(userAsKey, rights)); } }
StoreRightManager implements RightManager { @VisibleForTesting static MailboxACL filteredForSession(Mailbox mailbox, MailboxACL acl, MailboxSession mailboxSession) throws UnsupportedRightException { if (mailbox.generateAssociatedPath().belongsTo(mailboxSession)) { return acl; } MailboxACL.EntryKey userAsKey = MailboxACL.EntryKey.createUserEntryKey(mailboxSession.getUser()); Rfc4314Rights rights = acl.getEntries().getOrDefault(userAsKey, new Rfc4314Rights()); if (rights.contains(MailboxACL.Right.Administer)) { return acl; } return new MailboxACL(ImmutableMap.of(userAsKey, rights)); } @Inject  StoreRightManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
                             MailboxACLResolver aclResolver,
                             GroupMembershipResolver groupMembershipResolver,
                             EventBus eventBus); }
StoreRightManager implements RightManager { @VisibleForTesting static MailboxACL filteredForSession(Mailbox mailbox, MailboxACL acl, MailboxSession mailboxSession) throws UnsupportedRightException { if (mailbox.generateAssociatedPath().belongsTo(mailboxSession)) { return acl; } MailboxACL.EntryKey userAsKey = MailboxACL.EntryKey.createUserEntryKey(mailboxSession.getUser()); Rfc4314Rights rights = acl.getEntries().getOrDefault(userAsKey, new Rfc4314Rights()); if (rights.contains(MailboxACL.Right.Administer)) { return acl; } return new MailboxACL(ImmutableMap.of(userAsKey, rights)); } @Inject  StoreRightManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
                             MailboxACLResolver aclResolver,
                             GroupMembershipResolver groupMembershipResolver,
                             EventBus eventBus); @Override boolean hasRight(MailboxPath mailboxPath, Right right, MailboxSession session); @Override boolean hasRight(MailboxId mailboxId, Right right, MailboxSession session); boolean hasRight(Mailbox mailbox, Right right, MailboxSession session); @Override Rfc4314Rights myRights(MailboxPath mailboxPath, MailboxSession session); @Override Mono<Rfc4314Rights> myRights(MailboxId mailboxId, MailboxSession session); @Override Rfc4314Rights myRights(Mailbox mailbox, MailboxSession session); @Override List<Rfc4314Rights> listRights(MailboxPath mailboxPath, EntryKey key, MailboxSession session); @Override MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session); @Override void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session); @Override void applyRightsCommand(MailboxId mailboxId, ACLCommand mailboxACLCommand, MailboxSession session); boolean isReadWrite(MailboxSession session, Mailbox mailbox, Flags sharedPermanentFlags); @Override void setRights(MailboxId mailboxId, MailboxACL mailboxACL, MailboxSession session); @Override void setRights(MailboxPath mailboxPath, MailboxACL mailboxACL, MailboxSession session); MailboxACL getResolvedMailboxACL(Mailbox mailbox, MailboxSession mailboxSession); }
StoreRightManager implements RightManager { @VisibleForTesting static MailboxACL filteredForSession(Mailbox mailbox, MailboxACL acl, MailboxSession mailboxSession) throws UnsupportedRightException { if (mailbox.generateAssociatedPath().belongsTo(mailboxSession)) { return acl; } MailboxACL.EntryKey userAsKey = MailboxACL.EntryKey.createUserEntryKey(mailboxSession.getUser()); Rfc4314Rights rights = acl.getEntries().getOrDefault(userAsKey, new Rfc4314Rights()); if (rights.contains(MailboxACL.Right.Administer)) { return acl; } return new MailboxACL(ImmutableMap.of(userAsKey, rights)); } @Inject  StoreRightManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
                             MailboxACLResolver aclResolver,
                             GroupMembershipResolver groupMembershipResolver,
                             EventBus eventBus); @Override boolean hasRight(MailboxPath mailboxPath, Right right, MailboxSession session); @Override boolean hasRight(MailboxId mailboxId, Right right, MailboxSession session); boolean hasRight(Mailbox mailbox, Right right, MailboxSession session); @Override Rfc4314Rights myRights(MailboxPath mailboxPath, MailboxSession session); @Override Mono<Rfc4314Rights> myRights(MailboxId mailboxId, MailboxSession session); @Override Rfc4314Rights myRights(Mailbox mailbox, MailboxSession session); @Override List<Rfc4314Rights> listRights(MailboxPath mailboxPath, EntryKey key, MailboxSession session); @Override MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session); @Override void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session); @Override void applyRightsCommand(MailboxId mailboxId, ACLCommand mailboxACLCommand, MailboxSession session); boolean isReadWrite(MailboxSession session, Mailbox mailbox, Flags sharedPermanentFlags); @Override void setRights(MailboxId mailboxId, MailboxACL mailboxACL, MailboxSession session); @Override void setRights(MailboxPath mailboxPath, MailboxACL mailboxACL, MailboxSession session); MailboxACL getResolvedMailboxACL(Mailbox mailbox, MailboxSession mailboxSession); static final boolean GROUP_FOLDER; }