Listing people uses the listPeople method of the PeopleApi.
For more information about this ReST API endpoint, see List People (Users).
For a description of the common parameters, such as fields, see Common Parameters.
import org.alfresco.core.handler.PeopleApi; import org.alfresco.core.model.PersonEntry; import org.alfresco.core.model.PersonPaging; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.List; @Component public class ListPeopleCmd { static final Logger LOGGER = LoggerFactory.getLogger(ListPeopleCmd.class); @Autowired PeopleApi peopleApi; public void execute() throws IOException { Integer skipCount = 0; Integer maxItems = 100; List<String> orderBy = null; List<String> include = null; List<String> fields = null; LOGGER.info("Listing people in the repository"); PersonPaging people = peopleApi.listPeople(skipCount, maxItems, orderBy, include, fields).getBody(); for (PersonEntry personEntry: people.getList().getEntries()) { LOGGER.info(" {} ({})", personEntry.getEntry().getDisplayName(), personEntry.getEntry().getId()); } } }
Executing this code will list all users in the repository (note, if connected to LDAP this could be a lot of users…):
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar list-people 2021-05-05 13:42:15.547 INFO 18327 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.426 seconds (JVM running for 3.96) 2021-05-05 13:42:15.549 INFO 18327 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: list-people 2021-05-05 13:42:15.550 INFO 18327 --- [ main] o.a.tutorial.restapi.ListPeopleCmd : Listing people in the repository 2021-05-05 13:42:15.879 INFO 18327 --- [ main] o.a.tutorial.restapi.ListPeopleCmd : Alice Beecher (abeecher) 2021-05-05 13:42:15.880 INFO 18327 --- [ main] o.a.tutorial.restapi.ListPeopleCmd : Administrator (admin) 2021-05-05 13:42:15.880 INFO 18327 --- [ main] o.a.tutorial.restapi.ListPeopleCmd : Guest (guest) 2021-05-05 13:42:15.880 INFO 18327 --- [ main] o.a.tutorial.restapi.ListPeopleCmd : Mike Jackson (mjackson) 2021-05-05 13:42:15.880 INFO 18327 --- [ main] o.a.tutorial.restapi.ListPeopleCmd : Test User (test)