Reputation: 345
I build web applications using alfresco-community-4.0.e, OpenCMIS, and primefaces as user interface.
I need to create users in alfresco programmatically. I tried to create a user using the following code:
Blockquote
if (!personService.personExists("tuser1")) {
personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
}
if (!personService.personExists("tuser1")) {
personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
}
Blockquote
But I am facing problem with the authentication.
I made a class for alfresco authentication that throws the openCMIS and it works fine for creating my custom content and some other custom actions.
Any idea why it is now working with creating user or any other code to build the user programmatically?
Upvotes: 1
Views: 2999
Reputation: 48326
Your code is almost there, but missing one crucial line. As well as creating the person, you also need to create the associated Authentication for them
You probably want something like
if (this.authenticationService.authenticationExists(userName) == false)
{
this.authenticationService.createAuthentication(userName, password.toCharArray());
PropertyMap ppOne = new PropertyMap(4);
ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
ppOne.put(ContentModel.PROP_EMAIL, userName+"@example.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
this.personService.createPerson(ppOne);
}
Upvotes: 7