获取所有Alfresco用户(来自Java AMP)

时间:2017-04-21 06:37:12

标签: alfresco

我想获得Alfresco中所有用户的用户名(字符串)。

我的代码在Alfresco本身作为AMP运行。

怎么做?

我尝试使用PersonService但它没有输出结果,即使我在Alfresco中有多个用户(通过共享管理界面创建):

RunAsWork runAsWork = new RunAsWork() {
    @Override
    public Object doWork() throws Exception {
        return personService.getPeople("*", null, null, new PagingRequest(1000));
    }
};
PagingResults<PersonInfo> results =
    (PagingResults<PersonInfo>) AuthenticationUtil.runAsSystem(runAsWork);

System.out.println("Number of users: " + results.getTotalResultCount());
while (results.hasMoreItems()) {
    for (PersonInfo info : results.getPage()) {
        System.out.println("User: " + info.getUserName());
    }
}

3 个答案:

答案 0 :(得分:1)

PersonService personService = documentService.serviceRegistry.getPersonService();
PagingResults<PersonInfo> users = personService.getPeople("*", new ArrayList<QName>(), new ArrayList<Pair<QName,Boolean>>(), new PagingRequest(personService.countPeople()));
logger.info("The number of users in the system" + personService.countPeople());
do {
        List<PersonInfo> personInfos = users.getPage();
        for(PersonInfo personInfo : personInfos) {
            logger.info("User Name: " + personInfo.getUserName());
        }
} while(users.hasMoreItems());

此代码将记录alfresco中的所有用户

答案 1 :(得分:0)

人员api返回用户列表

http://server:port/alfresco/service/api/people

或者通过注射尝试这个    serviceRegistry

try {


                    Set<String> authorities = serviceRegistry.getAuthorityService().getAllAuthorities(AuthorityType.USER);


                    for (String authority : authorities) {
                        NodeRef person = serviceRegistry.getPersonService().getPerson(authority);

                        Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(person);

                        String fullName=properties.get(ContentModel.PROP_FIRSTNAME) +" "+properties.get(ContentModel.PROP_LASTNAME); 
                        System.out.println("User Full Name "+fullName);

                    }       

            } catch (Exception e) {
            e.printStackTrace();
        }

希望这会对你有所帮助。

答案 2 :(得分:0)

您的放大器验证可能存在问题,您可以尝试这样做: (PagingResults)AuthenticationUtil.runAs(runAsWork,AuthenticationUtil.getSystemUserName());

这和你做的一样,但我之前在旧的回购上遇到了runAsSystem问题。此外,还有更多方法可以搞乱人员服务PersonService.PersonInfo