@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);
  }
  public void traiteGroupAgentSHD(Integer idAgent, String nameFolderAgent) {

    List<PersonInfo> listPersonSHD = new ArrayList<PersonInfo>();
    List<Integer> listeSuperieurHierarchique = sirhWsConsumer.getListSuperieurOfAgent(idAgent);
    String groupSHD = PREFIXE_GROUP + nameFolderAgent + SHD;
    for (Integer idSup : listeSuperieurHierarchique) {

      if (null != idSup) {
        PersonInfo personSHD = alfrescoUtilsService.getPersonInfoByIdAgent(idSup);

        // AJOUT
        if (null != personSHD) {
          Set<String> listGroup = authorityService.getAuthoritiesForUser(personSHD.getUserName());
          if (!alfrescoUtilsService.isExistGroupForUser(listGroup, groupSHD)
              && authorityService.authorityExists(personSHD.getUserName())) {
            authorityService.addAuthority(groupSHD, personSHD.getUserName());
            if (!listPersonSHD.contains(personSHD)) {
              listPersonSHD.add(personSHD);
            }
            logger.debug("User " + personSHD.getUserName() + " adding in Group " + groupSHD);
          } else if (alfrescoUtilsService.isExistGroupForUser(listGroup, groupSHD)
              && authorityService.authorityExists(personSHD.getUserName())) {
            if (!listPersonSHD.contains(personSHD)) {
              listPersonSHD.add(personSHD);
            }
            logger.debug("User " + personSHD.getUserName() + " existing in Group " + groupSHD);
          }
        }
      }
    }

    // SUPPRESSION
    Set<String> listUsersGoupSHD =
        authorityService.getContainedAuthorities(AuthorityType.USER, groupSHD, true);
    if (null != listUsersGoupSHD) {

      for (String userGroupSHD : listUsersGoupSHD) {
        if (!alfrescoUtilsService.isExistUserInListPersonInfo(listPersonSHD, userGroupSHD)) {
          authorityService.removeAuthority(groupSHD, userGroupSHD);
          logger.debug("User " + userGroupSHD + " deleted in Group " + groupSHD);
        }
      }
    }
  }