Cherry
Cherry

Reputation: 33534

Is there a simple way to create user/group in alfresco at startup?

Here is alfresco-demo-data, they create user, group and some pieces of repository. But if you look a little deeper into code and examine PeopleUsersGroupAcpExporter, you see that to create some users you need:

  1. acp archive with xml file with about 10-15 properties for one user
  2. every user must have password hash, passwprd2 hash and salt, e.g. it is unclear how to create user with test 123 password.
  3. create several classes: PeopleUsersGroupAcpExporter, DynamicBootstrapPatchPostProcessor, ResourcesResolver, UsersImporterPatch, GroupsImporterPatch with a lot of code.

And finally this classes wrap (put) some data into spring bean definition.

Definitely there are must much simpler way to create/import user and group at alfresco start up.

Note 1

Here is very similar question, but they used authenticationService, whithout telling what type it is. There is org.jbpm.security.AuthenticationService and org.alfresco.service.cmr.security.AuthenticationService but both do not have any *create* methods

Note 2

Alfresco already has a feature csv import/expport user, but it is about users only. It do not provides attaching imported users to group automatically.

Upvotes: 0

Views: 686

Answers (2)

Md Noorshid
Md Noorshid

Reputation: 107

Yes you can here is the code

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: 1

Jeff Potts
Jeff Potts

Reputation: 10538

If you define your users and groups in an LDAP directory such as OpenLDAP or Apache Directory Server then you can simply add about ten lines of config to your alfresco-global.properties file, and all your users and groups will be sync'd into Alfresco on every startup. This has the added advantages of:

  1. allowing you to easily manage users and groups via widely-available tools,
  2. not requiring any custom code or extra setup,
  3. working for every instance of Alfresco you might have on your machine (if this is a dev setup), and
  4. working for other applications in your environment (if this is a prod setup).

Upvotes: 1

Related Questions