0

我正在使用 Alfresco 5.1 社区,并且我正在尝试获取当前登录人员的属性值,例如,在我拥有的用户中:

 "{http://www.someco.org/model/people/1.0}customProperty"

我怎样才能在java中获得这个?

是自定义属性,因此在http://localhost:8080/alfresco/service/api/people中不会出现。我怎样才能做到这一点?

我尝试这样做至少获得nodeRef:

protected ServiceRegistry getServiceRegistry() {
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null) {
            // Fetch the registry that is injected in the activiti spring-configuration
            ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);

            if (registry == null) {
                throw new RuntimeException("Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" + ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
            }

            return registry;
        }
        throw new IllegalStateException("No ProcessEngineConfiguration found in active context");
    }

    public void writeToCatalina() {
        PersonService personService = getServiceRegistry().getPersonService();
        System.out.println("test");
        String name = AuthenticationUtil.getFullyAuthenticatedUser();
        System.out.println(name);
        NodeRef personRef = personService.getPerson(name);
        System.out.println(personRef);
    }

但我得到了:

在活动上下文中找不到 ProcessEngineConfiguration

帮我 !

4

4 回答 4

2

您可以使用 CMIS 查询 Alfresco 并调用 API:

GET /alfresco/service/api/people/{userName}.

首先,您可以定义创建会话 CmisSession 的方法:

public Session getCmisSession() {

    logger.debug("Starting: getCmisSession()");

    // default factory implementation
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();

    // connection settings
    parameter.put(SessionParameter.ATOMPUB_URL, url + ATOMPUB_URL);
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    parameter.put(SessionParameter.AUTH_HTTP_BASIC, "true");
    parameter.put(SessionParameter.USER, username);
    parameter.put(SessionParameter.PASSWORD, password);
    parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

    List<Repository> repositories = factory.getRepositories(parameter);

    return repositories.get(0).createSession();
}

然后执行查询(此方法返回多个结果,您可能需要更改它):

public void doQuery(String cql, int maxItems) {

    Session cmisSession = getCmisSession();

    OperationContext oc = new OperationContextImpl();
    oc.setMaxItemsPerPage(maxItems);

    ItemIterable<QueryResult> results = cmisSession.query(cql, false, oc);

    for (QueryResult result : results) {
        for (PropertyData<?> prop : result.getProperties()) {
            logger.debug(prop.getQueryName() + ": " + prop.getFirstValue());
        }

    }

}

如果您需要获取令牌,请使用以下命令:

public String getAuthenticationTicket() {

    try {   

        logger.info("ALFRESCO: Starting connection...");

        RestTemplate restTemplate = new RestTemplate();
        Map<String, String> params = new HashMap<String, String>();
        params.put("user", username);
        params.put("password", password);
        Source result = restTemplate.getForObject(url + AFMConstants.URL_LOGIN_PARAM, Source.class, params);

        logger.info("ALFRESCO: CONNECTED!");

        XPathOperations xpath = new Jaxp13XPathTemplate();          
        return xpath.evaluateAsString("//ticket", result);
    }
    catch (RestClientException ex) {
        logger.error("FATAL ERROR - Alfresco Authentication failed - getAuthenticationTicket() - "  + ex );
        return null;
    }       
    catch (Exception ex) {          
        logger.error("FATAL ERROR - Alfresco Authentication failed - getAuthenticationTicket() - "  + ex );
        return null;
    }

}
于 2016-03-25T17:42:34.047 回答
1

您需要使用此 API获取您的用户 noderef,然后以这种方式访问​​其属性!


编辑:您需要在您的 bean 上注入服务注册表!

于 2016-03-25T16:14:18.137 回答
0

这将为您提供当前登录的用户名和详细信息。

        String name = AuthenticationUtil.getFullyAuthenticatedUser();
        System.out.println("Current user:"+name);
        PersonService personService=serviceRegistry.getPersonService();
        NodeRef node=personService.getPerson(name);
        NodeService nodeService=serviceRegistry.getNodeService();
        Map<QName, Serializable> props=nodeService.getProperties(node);

        for (Entry<QName, Serializable> entry : props.entrySet())
        {
            System.out.println(entry.getKey() + "/" + entry.getValue());
        }
于 2017-07-23T03:35:52.867 回答
0
String name = AuthenticationUtil.getFullyAuthenticatedUser()

你可以使用这个。让我知道它是否有效。

于 2016-03-26T10:38:04.110 回答