String userName;
userName = user.getLogin();
String passwd = user.getPassword();
String firstName = user.getFirstName();
String lastName = user.getLastName();
String email = user.getEmailAddress();
QName firstNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}firstName");
QName lastNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}lastName");
QName passwordQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}password");
QName emailQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}email");
QName homeFolderQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}homeFolder");
Map<QName, Serializable> props = null;
props = new HashMap<QName, Serializable>(5);
// homeFolder value must be a nodeRef
props.put(firstNameQName, firstName);
props.put(lastNameQName, lastName);
props.put(passwordQName, passwd);
props.put(emailQName, email);
try{
configurationApplicationContext=WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
authenticationService = (AuthenticationServiceImpl) configurationApplicationContext.getBean("authenticationService");
peopleService = (PeopleServiceImpl) configurationApplicationContext.getBean("peopleService");
nodeService = (NodeServiceImpl) configurationApplicationContext.getBean("nodeService");
ticket = authenticationService.authenticate(repositoryUri, userid, password.toCharArray());
NodeRef rootNode = nodeService.getRootNode(ticket, new StoreRef("workspace://SpacesStore"));
//NodeRef homeFolder = nodeService.getChildByName(ticket, rootNode, QName.createQName(
"{http://www.alfresco.org/model/content/1.0}folder" ), "app:company_home");
props.put(homeFolderQName, rootNode );
System.out.println("Creating the user called pruebaLray");
NodeRef userRef = peopleService.createPerson(ticket, userName, passwd.toCharArray(), props);
//Get "Company Home" NodeRef
String queryStr = String.format(FORMAT_QUERY, "/app:company_home");
/**
* Return a maximum of 100 nodes inside the given folder path
*/
List<Node> results = searchService.query(ticket, new StoreRef("workspace://SpacesStore"),
SearchService.QueryLanguage.lucene, queryStr,
new Vector<QName>(QUERY_PROPERTIES), false, false, false, false,
null, 100, null);
NodeRef homeFolder = null;
for(int i=0;i<results.size();i++){
Map<QName, Serializable> properties = null;
properties = results.get(i).getProperties();
if(properties.containsValue(space)){
homeFolder = results.get(i).getNodeRef();
}
}
//NodeRef homeFolder = results.get(0).getNodeRef();
props.put(ContentModel.PROP_HOMEFOLDER, homeFolder);
//Create the user in Alfresco and add it to the convenient groups
System.out.println("Creating the user called " + userName);
NodeRef userRef = peopleService.createPerson(ticket, userName, passwd.toCharArray(), props);
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.