@Override protected String applyInternal() throws Exception { // get all users in the system List<PersonInfo> personInfos = _personService .getPeople(null, null, null, new PagingRequest(Integer.MAX_VALUE, null)) .getPage(); Set<NodeRef> people = new HashSet<NodeRef>(personInfos.size()); for (PersonInfo personInfo : personInfos) { people.add(personInfo.getNodeRef()); } int count = 0; // iterate through all the users for (final NodeRef person : people) { // get the username from the node final Serializable username = nodeService.getProperty(person, ContentModel.PROP_USERNAME); // if no username, continue if (username == null) { continue; } // if it's the guest or admin, skip as well if (username.toString().equals("guest") || username.toString().equals("admin")) { continue; } // list all sites that the user is excplicit member in final List<SiteInfo> sites = _siteService.listSites(username.toString()); // the user is member of 1 site or more, continue if (sites.size() > 0) { continue; } // if this point is reached, the user is not a member of any site, so it // should be deleted LOG.error("Deleting user '" + username + "', user is not a member of any site"); _personService.deletePerson(username.toString()); count++; } LOG.error( "Deleted " + count + " of " + people.size() + " users that wasn't a member in any sites."); return I18NUtil.getMessage(MSG_SUCCESS); }