@Test public void shouldHasPermissionWhenUserIsOnlyMemberOfSpaces() { UserACL userACL = mock(UserACL.class); when(userACL.getSuperUser()).thenReturn("root"); when(userACL.getAdminGroups()).thenReturn("/platform/administrators"); GroupVisibilityPlugin plugin = new PermissionsGroupVisibilityPlugin(userACL); Identity userIdentity = new Identity("john", Arrays.asList(new MembershipEntry("/spaces/marketing", "member"), new MembershipEntry("/spaces/sales", "redactor"))); Group groupSpaces = new GroupImpl(); groupSpaces.setId("/spaces"); Group groupSpacesMarketing = new GroupImpl(); groupSpacesMarketing.setId("/spaces/marketing"); Group groupSpacesSales = new GroupImpl(); groupSpacesSales.setId("/spaces/sales"); Group groupSpacesEngineering = new GroupImpl(); groupSpacesEngineering.setId("/spaces/engineering"); boolean hasPermissionOnSpaces = plugin.hasPermission(userIdentity, groupSpaces); boolean hasPermissionOnSpacesMarketing = plugin.hasPermission(userIdentity, groupSpacesMarketing); boolean hasPermissionOnSpacesSales = plugin.hasPermission(userIdentity, groupSpacesSales); boolean hasPermissionOnSpacesEngineering = plugin.hasPermission(userIdentity, groupSpacesEngineering); assertTrue(hasPermissionOnSpaces); assertTrue(hasPermissionOnSpacesMarketing); assertTrue(hasPermissionOnSpacesSales); assertFalse(hasPermissionOnSpacesEngineering); }
public boolean hasPermission(Identity userIdentity, Group group) { Collection<MembershipEntry> userMemberships = userIdentity.getMemberships(); return userACL.getSuperUser().equals(userIdentity.getUserId()) || userMemberships.stream() .anyMatch(userMembership -> userMembership.getGroup().equals(userACL.getAdminGroups()) || ((userMembership.getGroup().equals(group.getId()) || userMembership.getGroup().startsWith(group.getId() + "/")) && (group.getId().equals("/spaces") || group.getId().startsWith("/spaces/") || userMembership.getMembershipType().equals("*") || userMembership.getMembershipType().equals("manager")))); }
PermissionsGroupVisibilityPlugin extends GroupVisibilityPlugin { public boolean hasPermission(Identity userIdentity, Group group) { Collection<MembershipEntry> userMemberships = userIdentity.getMemberships(); return userACL.getSuperUser().equals(userIdentity.getUserId()) || userMemberships.stream() .anyMatch(userMembership -> userMembership.getGroup().equals(userACL.getAdminGroups()) || ((userMembership.getGroup().equals(group.getId()) || userMembership.getGroup().startsWith(group.getId() + "/")) && (group.getId().equals("/spaces") || group.getId().startsWith("/spaces/") || userMembership.getMembershipType().equals("*") || userMembership.getMembershipType().equals("manager")))); } }
PermissionsGroupVisibilityPlugin extends GroupVisibilityPlugin { public boolean hasPermission(Identity userIdentity, Group group) { Collection<MembershipEntry> userMemberships = userIdentity.getMemberships(); return userACL.getSuperUser().equals(userIdentity.getUserId()) || userMemberships.stream() .anyMatch(userMembership -> userMembership.getGroup().equals(userACL.getAdminGroups()) || ((userMembership.getGroup().equals(group.getId()) || userMembership.getGroup().startsWith(group.getId() + "/")) && (group.getId().equals("/spaces") || group.getId().startsWith("/spaces/") || userMembership.getMembershipType().equals("*") || userMembership.getMembershipType().equals("manager")))); } PermissionsGroupVisibilityPlugin(UserACL userACL); }
PermissionsGroupVisibilityPlugin extends GroupVisibilityPlugin { public boolean hasPermission(Identity userIdentity, Group group) { Collection<MembershipEntry> userMemberships = userIdentity.getMemberships(); return userACL.getSuperUser().equals(userIdentity.getUserId()) || userMemberships.stream() .anyMatch(userMembership -> userMembership.getGroup().equals(userACL.getAdminGroups()) || ((userMembership.getGroup().equals(group.getId()) || userMembership.getGroup().startsWith(group.getId() + "/")) && (group.getId().equals("/spaces") || group.getId().startsWith("/spaces/") || userMembership.getMembershipType().equals("*") || userMembership.getMembershipType().equals("manager")))); } PermissionsGroupVisibilityPlugin(UserACL userACL); boolean hasPermission(Identity userIdentity, Group group); }
PermissionsGroupVisibilityPlugin extends GroupVisibilityPlugin { public boolean hasPermission(Identity userIdentity, Group group) { Collection<MembershipEntry> userMemberships = userIdentity.getMemberships(); return userACL.getSuperUser().equals(userIdentity.getUserId()) || userMemberships.stream() .anyMatch(userMembership -> userMembership.getGroup().equals(userACL.getAdminGroups()) || ((userMembership.getGroup().equals(group.getId()) || userMembership.getGroup().startsWith(group.getId() + "/")) && (group.getId().equals("/spaces") || group.getId().startsWith("/spaces/") || userMembership.getMembershipType().equals("*") || userMembership.getMembershipType().equals("manager")))); } PermissionsGroupVisibilityPlugin(UserACL userACL); boolean hasPermission(Identity userIdentity, Group group);  }