@Test void applyRightsCommandShouldThrowWhenDomainsAreDifferent() { MailboxPath mailboxPath = MailboxPath.forUser(Username.of("user@domain.org"), "mailbox"); ACLCommand aclCommand = MailboxACL.command() .forUser(Username.of("otherUser@otherdomain.org")) .rights(MailboxACL.FULL_RIGHTS) .asAddition(); assertThatThrownBy(() -> storeRightManager.applyRightsCommand(mailboxPath, aclCommand, aliceSession)) .isInstanceOf(DifferentDomainException.class); }
@Override public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); block(mapper.findMailboxByPath(mailboxPath) .flatMap(Throwing.<Mailbox, Mono<Void>>function(mailbox -> { assertHaveAccessTo(mailbox, session); return mapper.updateACL(mailbox, mailboxACLCommand) .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated() .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) .build(), new MailboxIdRegistrationKey(mailbox.getMailboxId()))); }).sneakyThrow())); }
StoreRightManager implements RightManager { @Override public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); block(mapper.findMailboxByPath(mailboxPath) .flatMap(Throwing.<Mailbox, Mono<Void>>function(mailbox -> { assertHaveAccessTo(mailbox, session); return mapper.updateACL(mailbox, mailboxACLCommand) .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated() .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) .build(), new MailboxIdRegistrationKey(mailbox.getMailboxId()))); }).sneakyThrow())); } }
StoreRightManager implements RightManager { @Override public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); block(mapper.findMailboxByPath(mailboxPath) .flatMap(Throwing.<Mailbox, Mono<Void>>function(mailbox -> { assertHaveAccessTo(mailbox, session); return mapper.updateACL(mailbox, mailboxACLCommand) .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated() .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) .build(), new MailboxIdRegistrationKey(mailbox.getMailboxId()))); }).sneakyThrow())); } @Inject  StoreRightManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
                             MailboxACLResolver aclResolver,
                             GroupMembershipResolver groupMembershipResolver,
                             EventBus eventBus); }
StoreRightManager implements RightManager { @Override public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); block(mapper.findMailboxByPath(mailboxPath) .flatMap(Throwing.<Mailbox, Mono<Void>>function(mailbox -> { assertHaveAccessTo(mailbox, session); return mapper.updateACL(mailbox, mailboxACLCommand) .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated() .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) .build(), new MailboxIdRegistrationKey(mailbox.getMailboxId()))); }).sneakyThrow())); } @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 { @Override public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException { assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand); MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); block(mapper.findMailboxByPath(mailboxPath) .flatMap(Throwing.<Mailbox, Mono<Void>>function(mailbox -> { assertHaveAccessTo(mailbox, session); return mapper.updateACL(mailbox, mailboxACLCommand) .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated() .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) .build(), new MailboxIdRegistrationKey(mailbox.getMailboxId()))); }).sneakyThrow())); } @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; }