Migrate existing users to Alfresco

If you are planning to migrate an existing application to Alfresco, you might want to migrate its existing users to Alfresco as well. If you use LDAP or an NTLM-based security model, you don't have to migrate the existing users to Alfresco. Instead, you can directly connect to those user sources from Alfresco. This model is always preferred, as you can manage users and groups at one centralized location, and can access the user information in many applications.

This is applicable if you are using Alfresco's out of the box security model.

Using command-line scripts for the bulk uploading of users

You can bulk upload users to Alfresco using command-line scripts. In order to bulk upload users, follow the steps given below:

  1. You have to create home folders for the users that you are importing. Create fredb and sues folders inside the User Homes space.
  2. Stop the Alfresco server.
  3. You have to create user data XML files in the /tomcat/webapps/alfresco/WEB-INF folder. Sample files are shown next, for your reference:
    • Person.x ml:
      <view:view xmlns:view="http://www.alfresco.org/view/repository/1.0"
                 xmlns:cm="http://www.alfresco.org/model/content/1.0"
                 xmlns:sys="http://www.alfresco.org/model/system/1.0"
                 xmlns:app="http://www.alfresco.org/model/application/1.0"
                xmlns:usr="http://www.alfresco.org/model/user/1.0" >                
      		<cm:person view:childName="cm:person">
      <cm:userName>fredb</cm:userName>
      <cm:firstName>Fred</cm:firstName>
                           <cm:lastName>Million</cm:lastName>
                           <cm:email>[email protected]</cm:email>
                           <cm:homeFolder>/app:company_home
                                          /app:user_homes/cm:fredb
                            </cm:homeFolder>      
                            <sys:node-uuid>4489977c-25b4-4980-ab2e-6d6307472bfa
                            </sys:node-uuid>
                     </cm:person>
                     <cm:person view:childName="cm:person">
                            <cm:userName>sues</cm:userName>
                            <cm:firstName>Sue</cm:firstName>
                            <cm:lastName>Sanderson</cm:lastName>
                            <cm:email>[email protected]</cm:email>
                            <cm:homeFolder>/app:company_home/
                                            app:user_homes/cm:sues
                            </cm:homeFolder>      
                            <sys:node-uuid>4489977c-25b4-4980-ab2e- 
                            6d6307472bfb
                            </sys:node-uuid>
                     </cm:person>
       </view:view>
    • UserStore.xml:
      <view:view xmlns:view="http://www.alfresco.org/view/repository/1.0"
             xmlns:cm="http://www.alfresco.org/model/content/1.0"
             xmlns:sys="http://www.alfresco.org/model/system/1.0"
             xmlns:app="http://www.alfresco.org/model/application/1.0"
             xmlns:usr="http://www.alfresco.org/model/user/1.0">
             <usr:user view:childName="usr:user">
                  <usr:username>fredb</usr:username>
                  <usr:password>fredb</usr:password>   
                  <usr:enabled>true</usr:enabled>
                  <usr:accountExpires>false</usr:accountExpires>   
                  <usr:credentialsExpire>false</usr:credentialsExpire>
                  usr:accountLocked>false
                  </usr:accountLocked>
            <sys:node-uuid>4489977c-25b4-4980-ab2e-6d6307472bfa
            </sys:node-uuid>
                </usr:user>
                <usr:user view:childName="usr:user">
                      <usr:username>sues</usr:username>
                      <usr:password>sues</usr:password>   
                      <usr:enabled>true</usr:enabled>
                      <usr:accountExpires>false</usr:accountExpires>
                      <usr:credentialsExpire>false
                      </usr:credentialsExpire>
                      <usr:accountLocked>false</usr:accountLocked>
                 <sys:node-uuid>4489977c-25b4-4980-ab2e-  
                       6d6307472bfb
                 </sys:node-uuid>
                      </usr:user> 
      </view:view>
      
  4. Open the repository.properties file from the path: tomcat/webapps/alfresco/web-inf/classes/alfresco/. Modify the properties below to the values that you require:
        dir.root=C:/Alfresco/alf_data<specify the path of alf data>                         
        db.schema.update=true
        db.schema.update.lockRetryCount=24
        db.schema.update.lockRetryWaitSeconds=5
        db.driver=org.gjt.mm.mysql.Driver
    db.name=alfresco <specify your database name>
    db.url=jdbc:mysql:///${db.name}
    db.username=alfresco<specify database username>
    db.password=alfresco<specify database password>
    db.pool.initial=10
    db.pool.max=20
  5. Run a command-line script to upload the users given in the person.xml file and the UserStore.xml file. Change the path to the WEB-INF folder. Run the commands that are given below. The syntax to call the script may change according to the platform of the operating system. Here is a sample script that reads user data from the person.xml file and uploads the data to Alfresco.
                java -classpath classes;libalfresco-repository.jar;libalfresco-linkvalidation.jar;libxercesImpl-2.8.0.jar;libalfresco-remote-api.jar;libalfresco-vti.jar;libalfresco-web-client.jar;libmyfaces-api-1.1.5.jar;libalfresco-rm.jar;libxmlrpc.jar;libjcr-1.0.jar;lib
    hino-js-1.6R7.jar;libspring-ws-1.5.0.jar;libsubetha-smtp.jar;libalfresco-jlan-embed.jar;libJMagick.jar;libalfresco-mbeans.jar;libhibernate-3.2.6-patched.jar;libjbpm-jpdl-3.2.2.jar;libjbpm-identity-3.2.2.jar;libspringmodules-jbpm31.jar;libspring-2.0.6.jar;libalfresco-core.jar;liblucene-analyzers-2.1.0.jar;liblucene-snowball-2.1.0.jar;libalfresco-core.jar;libspring-2.0.2.jar;libjibx-run.jar;libxpp3-1.1.3_8.jar;libcommons-logging-1.1.jar;libehcache-1.4.1-patched.jar;libdom4j-1.6.1.jar;libacegi-security-0.8.2_patched.jar;libhibernate-3.2.1-patched.jar;libquartz-1.6.0.jar;libpdfbox-0.7.3.jar;libpoi-3.1.jar;libjooconverter-2.1.0.jar;libjid3lib-0.5.jar;libfreemarker-2.3.13.jar;liblog4j-1.2.15.jar;libcryptix-jce-provider.jar;libcommons-codec-1.3.jar;libcommons-dbcp-1.2.1.jar;libcommons-pool-1.4.jar;libjta.jar;libmail.jar;libactivation.jar;libjug-lgpl-2.0.0.jar;libalfresco-deployment.jar;libcommons-collections-3.1.jar;libcglib-nodep-2.2_beta1.jar;libantlr-2.7.5H3.jar;lib	m-extractors-1.0.jar;libcommons-io-1.1.jar;lib
    idl.jar;libjuh.jar;libcommons-beanutils-1.7.0.jar;libjut.jar;libsandbox.jar;libjut.jar;liblucene-core-2.1.0.jar;......libmysql-connector-java-5.1.6-bin.jar;......libservlet-api.jar;libsh-1.3.0.jar;libsaxpath.jar;libjaxen-1.1-beta-8.jar;libjson.jar;libcprov-jdk15-137.jar;libderby.jar;libibatis-2.3.0.677.jar;lib	ruezip.jar;libant.jar;lib	ruelicense-1_29.jar;lib	ruexml-1_29.jar;libjoda-time-1.2.1.jar  org.alfresco.tools.Import -user admin -pwd admin -uuidBinding UPDATE_EXISTING  -store workspace://SpacesStore  -path  sys:system/sys:people -verbose person.xml
    
    java -classpath classes;libalfresco-repository.jar;libalfresco-linkvalidation.jar;libxercesImpl-2.8.0.jar;libalfresco-remote-api.jar;libalfresco-vti.jar;libalfresco-web-client.jar;libmyfaces-api-1.1.5.jar;libalfresco-rm.jar;libxmlrpc.jar;libjcr-1.0.jar;lib
    hino-js-1.6R7.jar;libspring-ws-1.5.0.jar;libsubetha-smtp.jar;libalfresco-jlan-embed.jar;libJMagick.jar;libalfresco-mbeans.jar;libhibernate-3.2.6-patched.jar;libjbpm-jpdl-3.2.2.jar;libjbpm-identity-3.2.2.jar;libspringmodules-jbpm31.jar;libspring-2.0.6.jar;libalfresco-core.jar;liblucene-analyzers-2.1.0.jar;liblucene-snowball-2.1.0.jar;libalfresco-core.jar;libspring-2.0.2.jar;libjibx-run.jar;libxpp3-1.1.3_8.jar;libcommons-logging-1.1.jar;libehcache-1.4.1-patched.jar;libdom4j-1.6.1.jar;libacegi-security-0.8.2_patched.jar;libhibernate-3.2.1-patched.jar;libquartz-1.6.0.jar;libpdfbox-0.7.3.jar;libpoi-3.1.jar;libjooconverter-2.1.0.jar;libjid3lib-0.5.jar;libfreemarker-2.3.13.jar;liblog4j-1.2.15.jar;libcryptix-jce-provider.jar;libcommons-codec-1.3.jar;libcommons-dbcp-1.2.1.jar;libcommons-pool-1.4.jar;libjta.jar;libmail.jar;libactivation.jar;libjug-lgpl-2.0.0.jar;libalfresco-deployment.jar;libcommons-collections-3.1.jar;libcglib-nodep-2.2_beta1.jar;libantlr-2.7.5H3.jar;lib	m-extractors-1.0.jar;libcommons-io-1.1.jar;lib
    idl.jar;libjuh.jar;libcommons-beanutils-1.7.0.jar;libjut.jar;libsandbox.jar;libjut.jar;liblucene-core-2.1.0.jar;......libmysql-connector-java-5.1.6-bin.jar;......libservlet-api.jar;libsh-1.3.0.jar;libsaxpath.jar;libjaxen-1.1-beta-8.jar;libjson.jar;libcprov-jdk15-137.jar;libderby.jar;libibatis-2.3.0.677.jar;lib	ruezip.jar;libant.jar;lib	ruelicense-1_29.jar;lib	ruexml-1_29.jar;libjoda-time-1.2.1.jar    org.alfresco.tools.Import -user admin -pwd admin  -uuidBinding UPDATE_EXISTING -store user://alfrescoUserStore -path  sys:system/sys:people -verbose UserStore.xml

Bootstrapping the Alfresco repository with predefined user data

The Alfresco repository supports a bootstrap process, which is initiated whenever the repository is first started. The process populates the repository with the information that is required upon the first login such as system users, data dictionary definitions, and important root folders.

Detailed information about bootstrapping Alfresco repository is provided in Chapter 14.

Using web services API to create users

You may also use the web services API to programmatically create users in Alfresco. This is useful if you already have another software application to manage users and you would like to create users in Alfresco from that application as and when needed.

The following is sample code provided to create a user amiranda, by using the webservice API:

private void createUsers() throws Exception
    {
        this.userName = "amiranda" ;
        this.password ="amiranda";
        Store store = new Store(Constants.WORKSPACE_STORE,"SpacesStore");
        String homeFolder = store.getScheme() + "://" + store.getAddress() + "/app:company_home/app:user_homes"  ;      
        NewUserDetails[] newUsers = new NewUserDetails[] {
                new NewUserDetails(
                        this.userName, 
                        this.password,
                        createPersonProperties(homeFolder, "Amy", "Jane", "Miranda", "[email protected]", "cignex"))};

// Create the new users
        WebServiceFactory.getAdministrationService().createUsers(newUsers);
    }
    
    private NamedValue[] createPersonProperties(
            String homeFolder,
            String firstName, 
            String middleName, 
            String lastName, 
            String email,
            String orgId)
    {
        // Create the new user objects
        return new NamedValue[] {
                new NamedValue(Constants.PROP_USER_HOMEFOLDER, false, homeFolder, null),
                new NamedValue(Constants.PROP_USER_FIRSTNAME, false, firstName, null),
                new NamedValue(Constants.PROP_USER_MIDDLENAME, false, middleName, null),
                new NamedValue(Constants.PROP_USER_LASTNAME, false, lastName, null),
                new NamedValue(Constants.PROP_USER_EMAIL, false, email, null),
                new NamedValue(Constants.PROP_USER_ORGID, false, orgId, null) };
    }

Note

The complete code can be downloaded from the Support section of Packt Publishing's web site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset