获取JAVA中person Alfresco的属性
我使用的是Alfresco 5.1社区,我试图获取当前登录用户的属性值,例如,在我拥有的用户中:获取JAVA中person Alfresco的属性,alfresco,alfresco-share,alfresco-webscripts,Alfresco,Alfresco Share,Alfresco Webscripts,我使用的是Alfresco 5.1社区,我试图获取当前登录用户的属性值,例如,在我拥有的用户中: "{http://www.someco.org/model/people/1.0}customProperty" 如何在java中获取此信息 是自定义属性,因此,在中不会显示。我该怎么做 我尝试此操作以至少获得nodeRef: protected ServiceRegistry getServiceRegistry() { ProcessEngineConfigurationIm
"{http://www.someco.org/model/people/1.0}customProperty"
如何在java中获取此信息
是自定义属性,因此,在中不会显示。我该怎么做
我尝试此操作以至少获得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
救救我 您需要使用获取用户节点ref,然后访问其属性
编辑:您需要在bean上注入服务注册表 您需要使用获取用户节点ref,然后访问其属性
编辑:您需要在bean上注入服务注册表 您可以使用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();
}
公共会话getCmisSession(){
debug(“启动:getCmisSession()”);
//默认工厂实现
SessionFactory工厂=SessionFactoryImpl.newInstance();
Map参数=new HashMap();
//连接设置
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,用户名);
parameter.put(SessionParameter.PASSWORD,PASSWORD);
parameter.put(SessionParameter.OBJECT\u FACTORY\u类,“org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl”);
List repositories=factory.getRepositories(参数);
返回repositories.get(0.createSession();
}
然后执行查询(此方法返回多个结果,您可能需要更改):
public void doQuery(字符串cql,int maxItems){
会话cmisSession=getCmisSession();
OperationContext oc=新的OperationContextImpl();
oc.setMaxItemsPerPage(maxItems);
ItemIterable results=cmisSession.query(cql,false,oc);
对于(查询结果:结果){
for(PropertyData属性:result.getProperties()){
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;
}
}
公共字符串getAuthenticationTicket(){
试试{
logger.info(“露天:开始连接…”);
RestTemplate RestTemplate=新RestTemplate();
Map params=新的HashMap();
参数put(“用户”,用户名);
参数put(“密码”,密码);
Source result=restemplate.getForObject(url+AFMConstants.url\u LOGIN\u PARAM,Source.class,params);
logger.info(“ALFRESCO:CONNECTED!”);
XPathOperations xpath=新的Jaxp13XPathTemplate();
返回xpath.evaluateAsString(“//票证”,结果);
}
捕获(RestClientException例外){
logger.error(“致命错误-Alfresco身份验证失败-getAuthenticationTicket()-”+ex);
返回null;
}
捕获(例外情况除外){
logger.error(“致命错误-Alfresco身份验证失败-getAuthenticationTicket()-”+ex);
返回null;
}
}
您可以使用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();
}
公共会话getCmisSession(){
debug(“启动:getCmisSession()”);
//默认工厂实现
SessionFactory工厂=SessionFactoryImpl.newInstance();
Map参数=new HashMap();
//连接设置
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,用户名);
parameter.put(SessionParameter.PASSWORD,PASSWORD);
parameter.put(SessionParameter.OBJECT\u FACTORY\u类,“org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl”);
List repositories=factory.getRepositories(参数);
返回repositories.get(0.createSession();
}
然后执行查询(此方法返回多个结果,您可能需要更改):
public void doQuery(字符串cql,int maxItems){
会话cmisSession=getCmisSession();
OperationContext oc=新的OperationContextImpl();
oc.setMaxItemsPerPage(maxItems);
ItemIterable results=cmisSession.query(cql,false,oc);
对于(查询结果:结果){
for(PropertyData属性:result.getProperties()){
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;
}
}
公共字符串getAuthenticationTicket(){
试试{
logger.info(“露天:开始连接…”);
RestTemplate RestTemplate=新RestTemplate();
Map params=新的HashMap();
参数put(“用户”,用户名);
参数put(“密码”,密码);
Source result=restemplate.getForObject(url+AFMConstants.url\u LOGIN\u PARAM,Source.class,params);
logger.info(“ALFRESCO:CONNECTED!”);
XPathOperations xpath=新的Jaxp13XPathTemplate();
返回xpath.evaluateAsString(“//票证”,结果);
}
捕获(RestClientException例外){
logger.error(“致命错误-Alfresco身份验证失败-getAuthenticationTicket()-”+ex);
返回null;
}
捕获(例外情况除外){
logger.error(“致命错误-Alfresco身份验证失败-getAuthenticationTicket()-”+ex);
返回null;
}
}
你可以用这个。让我知道它是否有效
你可以用这个。让我知道它是否有效。这将为您提供当前登录的用户名和详细信息
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());
}
String name=AuthenticationUtil.getFullyAuthenticatedUser();
System.out.p