******************************************************
Synchronize OpenLDAP groups to Active Directory groups
******************************************************
Presentation
============
It is often needed to synchronize groups from one repository to another.
The difficulty is that the user identifier in the source repository is different from the one in the destination. So simply copying the values of the "member" attribute is not enough: you need to search for each value in the source member attribute the correct value for the destination. That is where the JNDI utilities of LSC can help you.
.. note::
Be sure to know how ``lsc.xml`` file works before using this tutorial.
Let's go
========
This tutorial explain how to synchronize groups from an OpenLDAP directory to Active Directory. It should be easy to adapt to your own needs.
Task
----
Create a task "group" as a standard LSC task:
.. code-block:: XML
group
org.lsc.beans.SimpleBean
...
Services
--------
We define here a source service that will read OpenLDAP groups, and a destination service that will manage AD groups. OpenLDAP groups are ``groupsOfUniqueNames`` with ``uniqueMember`` attribute, AD groups are ``group`` with ``member`` attribute. We choose to keep ``cn`` as RDN on both sides:
.. code-block:: XML
group-source-service
ou=groups,dc=example,dc=com
cn
cn
description
uniqueMember
OpenLDAP
group-dst-service
OU=groups,OU=demo,DC=example,DC=com
cn
cn
description
member
objectClass
Properties
----------
We will now define properties:
.. code-block:: XML
...
Main properties
^^^^^^^^^^^^^^^
We define mainIdentifier and conditions:
.. code-block:: XML
js:"cn=" + javax.naming.ldap.Rdn.escapeValue(srcBean.getDatasetFirstValueById("cn")) + ",OU=groups,OU=demo,DC=example,DC=com"
;
FORCE
true
true
true
true
Object Class
^^^^^^^^^^^^
We force the values of objectClass attribute in AD:
.. code-block:: XML
objectclass
KEEP
"group"
"top"
member
^^^^^^
Here is the tricky part: a javascript code that will parse source members and transform them into destination members:
.. code-block:: XML
member
FORCE
1) {
continue;
}
var destMemberDn = destDn.get(0) + "," + ldap.getContextDn();
membersDstDn.push(destMemberDn);
}
membersDstDn
]]>
Some explanations on this script:
- We get DN of members in source in ``membersSrcDn``
- For each value, a search is done in source LDAP (``srcLdap``) to get its uid
- A search is done on destination LDAP (``ldap``) on sAMAccountName to get the DN corresponding to the uid value (sAMAccountName and uid are the pivot values of the user task)
- The DN found is computed with context DN (``ldap.getContextDn``) to get the real DN
- The DN is inserted into ``membersDstDn`` array
- The ``membersDstDn`` array is returned to LSC