Extracting Data from LDAP
home
Illustrates how to connect to an LDAP directory in Mule and retrieve a list of users stored in it.
Example
This example application connects to the LDAP directory and retrieves a list of LDAP users. This list is split into individual rows, logged, and aggregated back to a single list. The example uses Flow control Components such as the Collection Splitter and the Collection Aggregator.
Set Up and Run the Example
Set up LDAP on your machine.
- For Windows: Install OpenLDAP.
- For MacOS: OpenLDAP comes bundled with MacOS, so no need to download LDAP.
Install Apache Directory Studio.
Navigate to etc\openldap\slapd.conf in your OpenLDAP installation directory and set the rootpw in the BDB database definitions section to root.
Start the LDAP server.
- For Windows: Enter libexec\StartLDAP.cmd in the command line.
- For MacOS: Enter sudo /usr/libexec/slapd -d 255.
Start Apache Directory Studio and create a new connection, File > New > LDAP Connection using following setup:
name local LDAP hostname localhost port 389
Click Check network parameter. if the test is not successful, your LDAP server is not running, otherwise click Next.
Set Bind dn or user to
cn=Manager,dc=my-domain,dc=com
and Bind password to root. Click Check Authentication to verify the connection. Click Finish.Click File > Import > LDIF into LDAP, and click Next.
Set a path to ldap.ldif located in the scr/test/resources directory of this project. Set Import into to local LDAP. Click Finish.
Click ROOT DSE in the panel LDAP browser to see the imported data structure.
Create the example application in Anypoint Studio.
Double-click on ldap.xml under src/main/app directory and open Global Elements tab. Open LDAP configuration and fill in these values if you strictly followed the instructions:
Principal DN cn=Manager,dc=my-domain,dc=com Password root URL ldap://localhost:389/dc=my-domain,dc=com
Run it as Mule Application.
Open your browser and type http://localhost:8081/ in the address bar.
You should see three user records logged in the console output similar to this one:
[dn: cn=mmc,ou=people uid: mmc sn: mmc userPassword:: bW1jMTIz cn: mmc objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson , dn: cn=testuser1,ou=people uid: testuser1 sn: testuser1 userPassword:: dGVzdHVzZXIxMTIz cn: testuser1 objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson , dn: cn=admin,ou=people uid: admin sn: admin userPassword:: bW1jYWRtaW4= cn: admin objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson ]