@Test void testAppliesNullUser() throws UnsupportedRightException { assertThat(UnionMailboxACLResolver.applies(user1Key, null, groupMembershipResolver, USER_1.asString(), false)).isFalse(); assertThat(UnionMailboxACLResolver.applies(user2Key, null, groupMembershipResolver, USER_1.asString(), false)).isFalse(); assertThat(UnionMailboxACLResolver.applies(group1Key, null, groupMembershipResolver, USER_1.asString(), false)).isFalse(); assertThat(UnionMailboxACLResolver.applies(group2Key, null, groupMembershipResolver, USER_1.asString(), false)).isFalse(); assertThat(UnionMailboxACLResolver.applies(MailboxACL.ANYBODY_KEY, null, groupMembershipResolver, USER_1.asString(), false)).isTrue(); assertThat(UnionMailboxACLResolver.applies(MailboxACL.AUTHENTICATED_KEY, null, groupMembershipResolver, USER_1.asString(), false)).isFalse(); assertThat(UnionMailboxACLResolver.applies(MailboxACL.OWNER_KEY, null, groupMembershipResolver, USER_1.asString(), false)).isFalse(); }
protected static boolean applies(EntryKey aclKey, EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup) { final String aclKeyName = aclKey.getName(); final NameType aclKeyNameType = aclKey.getNameType(); if (SpecialName.anybody.name().equals(aclKeyName)) { return true; } else if (queryKey != null) { String queryUserOrGroupName = queryKey.getName(); switch (queryKey.getNameType()) { case user: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return (!resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner)) || (resourceOwnerIsGroup && groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), resourceOwner)); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return aclKeyName.equals(queryUserOrGroupName); case group: return groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), aclKeyName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case group: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return false; case group: return aclKeyName.equals(queryUserOrGroupName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case special: switch (aclKeyNameType) { case special: if (aclKeyName.equals(queryUserOrGroupName)) { return true; } else if (SpecialName.owner.name().equals(queryUserOrGroupName) && SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else { return false; } case user: case group: return false; default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + queryKey.getNameType()); } } else { return false; } }
UnionMailboxACLResolver implements MailboxACLResolver { protected static boolean applies(EntryKey aclKey, EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup) { final String aclKeyName = aclKey.getName(); final NameType aclKeyNameType = aclKey.getNameType(); if (SpecialName.anybody.name().equals(aclKeyName)) { return true; } else if (queryKey != null) { String queryUserOrGroupName = queryKey.getName(); switch (queryKey.getNameType()) { case user: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return (!resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner)) || (resourceOwnerIsGroup && groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), resourceOwner)); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return aclKeyName.equals(queryUserOrGroupName); case group: return groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), aclKeyName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case group: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return false; case group: return aclKeyName.equals(queryUserOrGroupName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case special: switch (aclKeyNameType) { case special: if (aclKeyName.equals(queryUserOrGroupName)) { return true; } else if (SpecialName.owner.name().equals(queryUserOrGroupName) && SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else { return false; } case user: case group: return false; default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + queryKey.getNameType()); } } else { return false; } } }
UnionMailboxACLResolver implements MailboxACLResolver { protected static boolean applies(EntryKey aclKey, EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup) { final String aclKeyName = aclKey.getName(); final NameType aclKeyNameType = aclKey.getNameType(); if (SpecialName.anybody.name().equals(aclKeyName)) { return true; } else if (queryKey != null) { String queryUserOrGroupName = queryKey.getName(); switch (queryKey.getNameType()) { case user: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return (!resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner)) || (resourceOwnerIsGroup && groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), resourceOwner)); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return aclKeyName.equals(queryUserOrGroupName); case group: return groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), aclKeyName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case group: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return false; case group: return aclKeyName.equals(queryUserOrGroupName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case special: switch (aclKeyNameType) { case special: if (aclKeyName.equals(queryUserOrGroupName)) { return true; } else if (SpecialName.owner.name().equals(queryUserOrGroupName) && SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else { return false; } case user: case group: return false; default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + queryKey.getNameType()); } } else { return false; } } UnionMailboxACLResolver();  UnionMailboxACLResolver(MailboxACL userGlobalACL, MailboxACL groupGlobalACL); }
UnionMailboxACLResolver implements MailboxACLResolver { protected static boolean applies(EntryKey aclKey, EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup) { final String aclKeyName = aclKey.getName(); final NameType aclKeyNameType = aclKey.getNameType(); if (SpecialName.anybody.name().equals(aclKeyName)) { return true; } else if (queryKey != null) { String queryUserOrGroupName = queryKey.getName(); switch (queryKey.getNameType()) { case user: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return (!resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner)) || (resourceOwnerIsGroup && groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), resourceOwner)); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return aclKeyName.equals(queryUserOrGroupName); case group: return groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), aclKeyName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case group: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return false; case group: return aclKeyName.equals(queryUserOrGroupName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case special: switch (aclKeyNameType) { case special: if (aclKeyName.equals(queryUserOrGroupName)) { return true; } else if (SpecialName.owner.name().equals(queryUserOrGroupName) && SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else { return false; } case user: case group: return false; default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + queryKey.getNameType()); } } else { return false; } } UnionMailboxACLResolver();  UnionMailboxACLResolver(MailboxACL userGlobalACL, MailboxACL groupGlobalACL); @Override MailboxACL applyGlobalACL(MailboxACL resourceACL, boolean resourceOwnerIsGroup); @Override List<Rfc4314Rights> listRights(EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup); @Override Rfc4314Rights resolveRights(Username requestUser, GroupMembershipResolver groupMembershipResolver, MailboxACL resourceACL, String resourceOwner, boolean resourceOwnerIsGroup); }
UnionMailboxACLResolver implements MailboxACLResolver { protected static boolean applies(EntryKey aclKey, EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup) { final String aclKeyName = aclKey.getName(); final NameType aclKeyNameType = aclKey.getNameType(); if (SpecialName.anybody.name().equals(aclKeyName)) { return true; } else if (queryKey != null) { String queryUserOrGroupName = queryKey.getName(); switch (queryKey.getNameType()) { case user: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return (!resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner)) || (resourceOwnerIsGroup && groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), resourceOwner)); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return aclKeyName.equals(queryUserOrGroupName); case group: return groupMembershipResolver.isMember(Username.of(queryUserOrGroupName), aclKeyName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case group: switch (aclKeyNameType) { case special: if (SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else if (SpecialName.owner.name().equals(aclKeyName)) { return resourceOwnerIsGroup && queryUserOrGroupName.equals(resourceOwner); } else { throw new IllegalStateException("Unexpected " + SpecialName.class.getName() + "." + aclKeyName); } case user: return false; case group: return aclKeyName.equals(queryUserOrGroupName); default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } case special: switch (aclKeyNameType) { case special: if (aclKeyName.equals(queryUserOrGroupName)) { return true; } else if (SpecialName.owner.name().equals(queryUserOrGroupName) && SpecialName.authenticated.name().equals(aclKeyName)) { return true; } else { return false; } case user: case group: return false; default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + aclKeyNameType); } default: throw new IllegalStateException("Unexpected " + NameType.class.getName() + "." + queryKey.getNameType()); } } else { return false; } } UnionMailboxACLResolver();  UnionMailboxACLResolver(MailboxACL userGlobalACL, MailboxACL groupGlobalACL); @Override MailboxACL applyGlobalACL(MailboxACL resourceACL, boolean resourceOwnerIsGroup); @Override List<Rfc4314Rights> listRights(EntryKey queryKey, GroupMembershipResolver groupMembershipResolver, String resourceOwner, boolean resourceOwnerIsGroup); @Override Rfc4314Rights resolveRights(Username requestUser, GroupMembershipResolver groupMembershipResolver, MailboxACL resourceACL, String resourceOwner, boolean resourceOwnerIsGroup); static final MailboxACL DEFAULT_GLOBAL_GROUP_ACL; static final MailboxACL DEFAULT_GLOBAL_USER_ACL; }