Extracting Data from LDAP
home
Learn how to connect to an LDAP directory using Mule and retrieve a list of users.
Screenshot of the main flow in Anypoint Studio, view full image here
Description
This example illustrates how to connect to an LDAP directory in Mule and retrieve a list of users stored in it.
Example Use Case
The example application connects to the LDAP directory and retrieves a list of LDAP users. This list is then split into individual rows, logged and then aggregated back to a single list. We use Flow control Components such as the Collection Splitter and the Collection Aggregator to do so.
Set Up and Run the Example
Setup 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 rootpw in 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 succesful, 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 then 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 to finish the import process.
If you click on ROOT DSE in the panel LDAP browser, you should 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 ]