0

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.

Community
  • 1
  • 1
Cherry
  • 31,309
  • 66
  • 224
  • 364
  • 1
    http://josh-barrett.blogspot.com/2013/04/bootstraping-users-with-alfresco.html – kinjelom Oct 23 '16 at 17:38
  • Create a bunch of users in an existing Alfresco instance, export them, and import them into the new one with an ACP? Also note that the sample site bootstrap (as used by the demo site amongst others) supports adding users to groups – Gagravarr Oct 23 '16 at 19:13
  • 2**imagine** blog is good, but hashgeneration is too old. `cryptix` is 2005 and no longer supported. When I try to use it I got `Netscape security model is no longer supported. Please migrate to the Java 2 security model instead.` – Cherry Oct 24 '16 at 04:47
  • 2**Gagravarr** I think about it, but alfresco community edition do not supported it out-of-the-box. Anyway I did not found how to acp import/export in alfresco community. – Cherry Oct 24 '16 at 04:50

2 Answers2

1

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);
}
Stanislav Mekhonoshin
  • 4,276
  • 2
  • 20
  • 25
Md Noorshid
  • 107
  • 12
1

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).
Jeff Potts
  • 10,468
  • 17
  • 40