private Stream<CassandraId> toAuthorizedMailboxIds(Map<CassandraId, MailboxACL.Rfc4314Rights> map, Right right) { return map.entrySet() .stream() .filter(Throwing.predicate(entry -> entry.getValue().contains(right))) .map(Map.Entry::getKey); }
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 Boolean hasRightOn(Mailbox mailbox, String userName, Right right) { return Optional.ofNullable( mailbox.getACL() .ofPositiveNameType(NameType.user) .get(MailboxACL.EntryKey.createUserEntryKey(userName))) .map(rights -> rights.contains(right)) .orElse(false); } }
public boolean isReadWrite(MailboxSession session, Mailbox mailbox, Flags sharedPermanentFlags) throws UnsupportedRightException { Rfc4314Rights rights = myRights(mailbox, session); /* * then go through shared flags. RFC 4314 section 4: * Changing flags: STORE * - the server MUST check if the user has "t" (expunge) right * - when the user modifies \Deleted flag "s" (seen) right * - when the user modifies \Seen flag "w" (write) - for all other message flags. */ return rights.contains(Right.Insert) || rights.contains(Right.PerformExpunge) || checkDeleteFlag(rights, sharedPermanentFlags) || checkSeenFlag(rights, sharedPermanentFlags) || checkWriteFlag(rights, sharedPermanentFlags); }
private boolean checkSeenFlag(Rfc4314Rights rights, Flags sharedPermanentFlags) { return sharedPermanentFlags.contains(Flags.Flag.SEEN) && rights.contains(Right.WriteSeenFlag); }
private boolean checkDeleteFlag(Rfc4314Rights rights, Flags sharedPermanentFlags) { return sharedPermanentFlags.contains(Flags.Flag.DELETED) && rights.contains(Right.DeleteMessages); }
@Test public void containsShouldReturnTrueWhenNonRightsPresent() throws UnsupportedRightException { assertThat(lprs.contains()).isTrue(); }
@Test public void containsShouldReturnFalseWhenAtLeastOneRightNotPresent() throws UnsupportedRightException { assertThat(lprs.contains(Lookup, Write)).isFalse(); }
@Test public void containsShouldReturnTrueWhenMatching() throws UnsupportedRightException { assertThat(aeik.contains('e')).isTrue(); }
@Test public void containsShouldReturnFalseWhenNotMatching() throws UnsupportedRightException { assertThat(aeik.contains('x')).isFalse(); }
public boolean hasRight(Mailbox mailbox, Right right, MailboxSession session) throws MailboxException { return myRights(mailbox, session).contains(right); }
/** * Tells whether the implementation supports the given right. * * @param right * @return true if this supports the given right. */ public boolean isSupported(Right right) { try { contains(right.asCharacter()); return true; } catch (UnsupportedRightException e) { return false; } }
@Test public void containsShouldReturnTrueWhenAllRightsPresent() throws UnsupportedRightException { assertThat(lprs.contains(Lookup, Post)).isTrue(); }
@Test public void containsShouldReturnFalseWhenRightNotPresent() throws UnsupportedRightException { assertThat(lprs.contains(Write)).isFalse(); }
private Predicate<MailboxId> hasRightsOnMailbox(MailboxSession session, Right... rights) { return Throwing.predicate((MailboxId mailboxId) -> mailboxManager.myRights(mailboxId, session).contains(rights)) .fallbackTo(any -> false); }
@Override public boolean hasRight(MailboxId mailboxId, Right right, MailboxSession session) throws MailboxException { return myRights(mailboxId, session).contains(right); }
@Override public boolean hasRight(MailboxPath mailboxPath, Right right, MailboxSession session) throws MailboxException { return myRights(mailboxPath, session).contains(right); }
/** * Tells whether this contains the given right. * * @throws UnsupportedRightException if the given right is not supported. */ public boolean contains(char flag) throws UnsupportedRightException { return contains(Right.forChar(flag)); }
private boolean checkWriteFlag(Rfc4314Rights rights, Flags sharedPermanentFlags) { return rights.contains(Right.Write) && (sharedPermanentFlags.contains(Flags.Flag.ANSWERED) || sharedPermanentFlags.contains(Flags.Flag.DRAFT) || sharedPermanentFlags.contains(Flags.Flag.FLAGGED) || sharedPermanentFlags.contains(Flags.Flag.RECENT) || sharedPermanentFlags.contains(Flags.Flag.USER)); }
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)); }