private static Rfc4314Rights[] toListRightsArray(Rfc4314Rights implicitRights) throws UnsupportedRightException { List<Rfc4314Rights> result = new ArrayList<>(); result.add(implicitRights); for (Right right : MailboxACL.FULL_RIGHTS.list()) { if (!implicitRights.contains(right)) { result.add(new Rfc4314Rights(right)); } } return result.toArray(new Rfc4314Rights[result.size()]); }
private Rfc4314Rights toMailboxAclRights(Collection<Right> rights) { BinaryOperator<Rfc4314Rights> union = Throwing.binaryOperator(Rfc4314Rights::union); return rights.stream() .map(Right::toMailboxRight) .map(Throwing.function(Rfc4314Rights::new)) .reduce(new Rfc4314Rights(), union); }
private Rfc4314Rights union(Collection<Rfc4314Rights> rights) { return rights.stream() .reduce( new Rfc4314Rights(), Throwing.binaryOperator(Rfc4314Rights::union)); }
@Test public void allExceptShouldReturnAllButProvidedRights() throws UnsupportedRightException { assertThat(Rfc4314Rights.allExcept(Lookup, Read)) .isEqualTo(new Rfc4314Rights( DeleteMessages, Insert, Administer, Write, WriteSeenFlag, PerformExpunge, CreateMailbox, Post, DeleteMailbox)); }
public static Rfc4314Rights deserialize(String serialized) throws UnsupportedRightException { return new Rfc4314Rights(serialized); }
public static Rfc4314Rights fromSerializedRfc4314Rights(String serializedRfc4314Rights) throws UnsupportedRightException { return new Rfc4314Rights(rightListFromSerializedRfc4314Rights(serializedRfc4314Rights)); }
public Builder noRights() { this.rights = new Rfc4314Rights(); return this; }
public static Rfc4314Rights allExcept(Right... rights) throws UnsupportedRightException { return MailboxACL.FULL_RIGHTS .except(new Rfc4314Rights(rights)); }
@Test void twoConcurrentUpdatesWhenNoACEStoredShouldReturnACEWithTwoEntries(CassandraCluster cassandra) throws Exception { CountDownLatch countDownLatch = new CountDownLatch(2); MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); MailboxACL.EntryKey keyAlice = new MailboxACL.EntryKey("alice", MailboxACL.NameType.user, false); Future<Boolean> future1 = performACLUpdateInExecutor(cassandra, executor, keyBob, rights, countDownLatch::countDown); Future<Boolean> future2 = performACLUpdateInExecutor(cassandra, executor, keyAlice, rights, countDownLatch::countDown); awaitAll(future1, future2); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(keyBob, rights).union(keyAlice, rights)); }
@Test void modifyACLWhenStoredShouldReturnUpdatedACL() throws MailboxException { MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); 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, MailboxACL.command().key(keyAlice).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(keyBob, rights).union(keyAlice, rights)); }
@Test void updateInvalidACLShouldBeBasedOnEmptyACL(CassandraCluster cassandra) throws Exception { cassandra.getConf().execute( insertInto(CassandraACLTable.TABLE_NAME) .value(CassandraACLTable.ID, MAILBOX_ID.asUuid()) .value(CassandraACLTable.ACL, "{\"entries\":{\"bob\":invalid}}") .value(CassandraACLTable.VERSION, 1)); MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(new MailboxACL().union(key, rights)); }
@Test void replaceForSingleKeyWithNullRightsWhenSingleKeyStoredShouldReturnEmptyACL() throws MailboxException { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); 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); }
@Test void removeWhenStoredShouldReturnUpdatedACL() throws MailboxException { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); 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); }
@Test void addACLWhenNoneStoredShouldReturnUpdatedACL() throws Exception { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()) .isEqualTo(new MailboxACL().union(key, rights)); }
@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); }
public Builder rights(Right... rights) throws UnsupportedRightException { this.rights = Optional.ofNullable(this.rights) .orElse(new Rfc4314Rights()) .union(new Rfc4314Rights(rights)); return this; }
@Test void deSerializeShouldAcceptEmptyRight() { assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( "{\"oldACL\":{\"$any\":\"\"},\"newACL\":{}}")) .get().toJava()) .isEqualTo(new ACLDiff(new MailboxACL(ImmutableMap.of( new MailboxACL.EntryKey("any", MailboxACL.NameType.group, false), new MailboxACL.Rfc4314Rights())), new MailboxACL())); }
@Test void deSerializeShouldAcceptDoubleRight() { assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( "{\"oldACL\":{\"$any\":\"aa\"},\"newACL\":{}}")) .get().toJava()) .isEqualTo(new ACLDiff(new MailboxACL(ImmutableMap.of( new MailboxACL.EntryKey("any", MailboxACL.NameType.group, false), new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer))), new MailboxACL())); }
@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 void replaceWhenNotStoredShouldUpdateACLEntry() throws MailboxException { MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false); MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read); cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asReplacement()); assertThat(cassandraACLMapper.getACL(MAILBOX_ID).join()).isEqualTo(new MailboxACL().union(key, rights)); }