@Test public void shouldHasPermissionWhenUserIsPlatformAdministrator() { 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("/platform/administrators", "manager"))); Group groupPlatform = new GroupImpl(); groupPlatform.setId("/platform"); Group groupPlatformUsers = new GroupImpl(); groupPlatformUsers.setId("/platform/users"); boolean hasPermissionOnPlatform = plugin.hasPermission(userIdentity, groupPlatform); boolean hasPermissionOnPlatformUsers = plugin.hasPermission(userIdentity, groupPlatformUsers); assertTrue(hasPermissionOnPlatform); assertTrue(hasPermissionOnPlatformUsers); }
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);  }