************************************** Synchronize from CSV to LDAP directory ************************************** This tutorial explains how you can synchronize a CSV file to an LDAP directory. The idea is to use a database source service based on a HSQLDB instance (database in files or in memory). This HSQLDB instance will be first populated with data contained in the CSV file. .. tip:: To run a sample CSV to LDAP connector out of the box, you can follow the :doc:`quickstart tutorial `. .. note:: Another way to synchronize from CSV to LDAP is to use `Executable plugin `__ and `Perl wrappers for CSV `__. Step 1: Populate the HSQLDB database from CSV ============================================= CSV file -------- First, get a CSV file, or create one from this tutorial. This file will be called ``tutorial.csv`` and contains the following sample data: .. code-block:: uid;sn;givenName;cn;mail jdoe;Doe;John;John Doe;jdoe@example.com HSQLDB script ------------- LSC provides a wrapper to manage the packaged HSQLDB database, see :doc:`HSQLDB ` to get more details. Start HSQLDB ------------ Start HSQLB with the following command: .. code-block:: console $ bin/hsqldb --start You can then check the status: .. code-block:: console $ bin/hsqldb --status HSQLDB Server is running (PID 7020) Import CSV data --------------- Load the data with this command: .. code-block:: console $ bin/hsqldb --import tutorial.csv 1 lines imported into table csvdata Check imported data: .. code-block:: console $ bin/hsqldb --show UID SN GIVENNAME CN MAIL ---- --- --------- -------- ---------------- jdoe Doe John John Doe jdoe@example.com Step 2: Configure LSC ===================== .. note:: We just provide here the specific configuration items for this tutorial. For a complete overview of LSC configuration, please read :ref:`configuration `. HSQLDB source connector ----------------------- First of all, configure your :doc:`database connection `: .. code-block:: XML src-jdbc jdbc:hsqldb:hsql://localhost/lscdb sa org.hsqldb.jdbcDriver Then configure your service by referencing the previous connection ("reference" attribute is pointing to the connection node): .. code-block:: XML user-src getInetOrgPersonList getInetOrgPerson getInetOrgPersonClean We now need to use IBatis to get data from HSQLDB. First, create or update the SQL map configuration: .. code-block:: console $ vi etc/sql-map-config.xml .. code-block:: XML Then declare SQL queries: .. code-block:: console $ vi etc/sql-map-config.d/InetOrgPerson.xml .. code-block:: XML LDAP destination connector ========================== .. tip:: We suppose you have a running LDAP server on localhost. If not, you can use the sample LDAP directory from the :doc:`quickstart `. First of all, configure your :doc:`ldap connection `: .. code-block:: XML dst-ldap ldap://localhost:33389/dc=lsc-project,dc=org cn=Directory Manager secret SIMPLE IGNORE NEVER VERSION_3 -1 com.sun.jndi.ldap.LdapCtxFactory false false Then configure LDAP destination service: .. code-block:: XML user-dst ou=Sample,dc=lsc-project,dc=org uid cn sn gn uid userPassword objectClass mail (objectClass=inetOrgPerson) (&(objectClass=inetOrgPerson)(uid={uid})) Set synchronization rules ========================= As usual, define also how the synchronized objects are going to be identified and how you want to force or leave current attributes: .. code-block:: XML "uid=" + srcBean.getDatasetFirstValueById("uid") + ",ou=Sample,dc=lsc-project,dc=org" ; FORCE objectClass FORCE "inetOrgPerson" "organizationalPerson" "person" "top" , userPassword KEEP "changethis" Here the rules are quite simple: * Create the objectClass attribute (class inetOrgPerson) * Create the password with the default value "changethis" * Copy all other attributes from source to destination (uid, cn, sn, givenname and mail) Check configuration =================== Check your configuration: .. code-block:: console $ bin/lsc -v Launch synchronization ====================== Finally launch the synchronization: .. code-block:: console $ bin/lsc -s all -c all You should see the following result: .. code-block:: avr. 23 22:38:35 - DEBUG - Loading XML configuration from: /home/clement/tmp/lsc-2.0-SNAPSHOT/bin/../etc/lsc.xml avr. 23 22:38:35 - INFO - Logging configuration successfully loaded from /home/clement/tmp/lsc-2.0-SNAPSHOT/bin/../etc/logback.xml avr. 23 22:38:35 - INFO - LSC configuration successfully loaded from /home/clement/tmp/lsc-2.0-SNAPSHOT/bin/../etc/ avr. 23 22:38:35 - INFO - Connecting to LDAP server ldap://localhost:33389/dc=lsc-project,dc=org as cn=Directory Manager avr. 23 22:38:36 - INFO - Starting sync for user avr. 23 22:38:36 - INFO - # Adding new object uid=jdoe,ou=Sample,dc=lsc-project,dc=org for user dn: uid=jdoe,ou=Sample,dc=lsc-project,dc=org changetype: add uid: jdoe mail: jdoe@example.com sn: Doe cn: John Doe userPassword: changethis objectClass: organizationalPerson objectClass: person objectClass: inetOrgPerson objectClass: top avr. 23 22:38:36 - INFO - All entries: 1, to modify entries: 1, modified entries: 1, errors: 0 avr. 23 22:38:36 - INFO - Starting clean for user avr. 23 22:38:36 - INFO - All entries: 1, to modify entries: 0, successfully modified entries: 0, errors: 0 .. tip:: For further synchronizations, you will need to reimport fresh data from a CSV file into HSQLDB and launch the connector again.