ResourcePermissionService { public void revokePermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects) { revokePermission(resource, (resource1 -> alienDAO.save(resource1)), subjectType, subjects); }  void grantPermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects); void grantPermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects); void revokePermission(ISecurityEnabledResource resource, Subject subjectType, String... subjects); void revokePermission(ISecurityEnabledResource resource, IResourceSaver saver, Subject subjectType, String... subjects); boolean anyHasPermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects); boolean allHavePermission(ISecurityEnabledResource resource, Map<Subject, Set<String>> subjects); List<User> getAuthorizedUsers(AbstractSecurityEnabledResource resource); List<Group> getAuthorizedGroups(AbstractSecurityEnabledResource resource); void revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToDelete,
                                                                              String[] environmentsToDelete, String[] environmentTypesToDelete); void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd,
                                                                     String[] environmentTypesToAdd);  }
@Test public void when_permission_revoked_the_resource_is_saved() throws Exception { service.revokePermission(resourceSecured, resourceSaver, Subject.APPLICATION); verify(resourceSaver).save(resourceSecured); }
@Test public void check_revoked_permissions_have_been_removed_from_resource() { resourceSecured = new AbstractSecurityEnabledResource() { @Override public String getId() { return "id"; } }; HashSet<Permission> permissions = new HashSet<>(); permissions.add(Permission.READ); permissions.add(Permission.ADMIN); resourceSecured.addPermissions(Subject.APPLICATION, "subject1", new HashSet<>(permissions)); resourceSecured.addPermissions(Subject.APPLICATION, "subject3", new HashSet<>(permissions)); service.revokePermission(resourceSecured, resourceSaver, Subject.APPLICATION, "subject1", "subject2"); verify(resourceSaver).save(resourceSecuredCaptor.capture()); ISecurityEnabledResource resourceSecuredSaved = resourceSecuredCaptor.getValue(); assertThat(resourceSecuredSaved.getPermissions(Subject.APPLICATION, "subject1")).containsExactly(Permission.READ); assertThat(resourceSecuredSaved.getPermissions(Subject.APPLICATION, "subject2")).isEmpty(); assertThat(resourceSecuredSaved.getPermissions(Subject.APPLICATION, "subject3")).containsExactlyInAnyOrder(Permission.ADMIN, Permission.READ); }