As we all know, the Lightweight Directory Access Protocol (LDAP) is an open, vendor-neutral, industry standard application protocol for accessing and maintaining distributed directory information services over an Internet Protocol (IP) network. A common use of LDAP is to provide a central place to store usernames and passwords. This allows many different applications and services to connect to the LDAP server to validate users. This has a major benefit that allows a central place to update and change user passwords.
With MuleSoft’s LDAP Connector, we can access and maintain directory information services over an IP network by connecting to any LDAP server. LDAP Connector is developed by MuleSoft's developer community and it is categorized as Community Connectors. Latest LDAP Connector documentation is available here. Unfortunately, the information and examples of this connector are limited and scattered all over the web.
Today, I am trying to cover as many details as possible, of course with an example, and right from installing LDAP Connector in Anypoint Studio. First, let's see the LDAP server that we are going to use for this example. We will be using "Online LDAP Test Server" as we do not have to setup any LDAP server locally. This will eliminate the need for us to download, install and configure an LDAP server for testing as it has some test data as well.
Connection Details LDAP Connector - Online LDAP Test Server | |
---|---|
Principal DN | cn=read-only-admin,dc=example,dc=com |
Password | password |
URL | ldap://ldap.forumsys.com |
Base DN | dc=example,dc=com |
JXplorer is a cross platform LDAP browser and editor. This wonderful LDAP client can be used to search, read and edit any standard LDAP directory. Connecting to "Online LDAP Test Server" from this client is very easy. Below details can be used for connection:
Connection Details - JXplorer Client | |
---|---|
User DN | cn=read-only-admin,dc=example,dc=com |
Password | password |
Host | ldap://ldap.forumsys.com |
Base DN | dc=example,dc=com |
Let's now see how to install LDAP Connector in Anypoint Studio and create a sample project to search the data from "Online LDAP Test Server".
Step 1. Install LDAP Connector in Anypoint Studio
In this step, we will install LDAP Connector. To install the connector in Anypoint Studio, go to Help --> Install New Software and select "Anypoint Connectors Update Site - http://repository.mulesoft.org/connectors/releases/3.5.0" option.
Step 2. Install mule-module-ldap-1.3.1.jar file
Technically, you can add following dependency in you Mule Project pom.xml file but you may still get an error while running the project with LDAP configuration. The error message will be something like "Invalid content found starting with ldap:...."
To resolve this issue, the simplest trick is to copy mule-module-ldap-1.3.1.jar file in following location. Please note that I am using mule embedded server version 3.7.3 but you could be using different version of embedded mule server. Please make sure you restart "Anypoint Studio" after placing the jar file in "user" directory.
Jar File | mule-module-ldap-1.3.1.jar |
Copy To Location | AnypointStudio/plugins/org.mule.tooling.server.3.7.3.ee_5.4.0.201511251736/mule/lib/user |
Step 3. Create Mule Project and Mule Flow
Let's create new Mule Project and create Mule Flow as below.
Mule Flow XML:
Step 4. Run Mule Project and Validate
This is a final step to run the Mule Project and validate if our code is working as expected. I am going to use "DHC REST Client" chrome extension for sending GET requests to our Mule HTTP Connector configured above. Let's cover FOUR very basic test cases and verify the results. There is one more thing to note here. Sometimes, LDAP Connection will be timed out due to some network connection and since in this basic example we are not having Exception Strategy defined, the error will be thrown in console. Just try to send same request couple of times, and you will get successful results back.
Case A. HTTP GET Request without "uid" query parameter
We will first trigger HTTP GET Request without "uid" query parameter. We have a choice block to check if "uid" query parameter is available or not. If this parameter is not available, then we will just print a log message in console stating "LdapSearch : Request received without UID parameter". Please note that, we are not sending any HTTP Status code or response back. So you will see HTTP Status Code as 200 in DHC REST Client.
HTTP GET: http://localhost:8081/ldapsearch
Result: LdapSearch : Request received without UID parameter
Case B. HTTP GET Request with "uid" query parameter but no data found
We will first trigger HTTP GET Request with "uid" query parameter. If this parameter is available, then we will connect to LDAP Server and invoke "search" operation using MuleSoft LDAP Connector. Since the search returned empty results i.e. data for requested "uid" is not available, we will see log message as "LdapSearch : Result : []" in console and HTTP Status Code as 200 in DHC REST Client.
HTTP GET: http://localhost:8081/ldapsearch?uid=123
Result: LdapSearch : Result : []
Case C. HTTP GET Request with "uid" query parameter and data is returned
We will first trigger HTTP GET Request with "uid" query parameter. If this parameter is available, then we will connect to LDAP Server and invoke "search" operation using MuleSoft LDAP Connector. Since the search returned valid result i.e. data for requested "uid" is available, we will see following log message in console and HTTP Status Code as 200 in DHC REST Client.
HTTP GET: http://localhost:8081/ldapsearch?uid=euler
Result:
LdapSearch : Result : [dn: uid=euler,dc=example,dc=com
uid: euler
mail: euler@ldap.forumsys.com
sn: Euler
cn: Leonhard Euler
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
]
Case D. HTTP GET Request with “uid” query parameter and multiple results returned
We will first trigger HTTP GET Request with “uid” query parameter. If this parameter is available, then we will connect to LDAP Server and invoke “search” operation using MuleSoft LDAP Connector. Since the search returned valid results i.e. multiple results for requested “uid” is available, we will see following log message in console and HTTP Status Code as 200 in DHC REST Client.
HTTP GET: http://localhost:8081/ldapsearch?uid=e*
Result:
LdapSearch : Result : [dn: uid=einstein,dc=example,dc=com
uid: einstein
mail: einstein@ldap.forumsys.com
sn: Einstein
cn: Albert Einstein
telephoneNumber: 314-159-2653
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top,
dn: uid=euler,dc=example,dc=com
uid: euler
mail: euler@ldap.forumsys.com
sn: Euler
cn: Leonhard Euler
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top,
dn: uid=euclid,dc=example,dc=com
uid: euclid
mail: euclid@ldap.forumsys.com
sn: Euclid
cn: Euclid
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
]
P.S. Click here to access my other posts.
This information is really awesome thanks for sharing most valuable information.
ReplyDeleteMulesoft Online Training
Thanks for sharing such useful information with us to get some idea about that content.
ReplyDeleteMulesoft Online Training
Mulesoft Training in Hyderabad
I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting mulesoft online training
ReplyDeleteThanks for sharing useful information.. we have learned so much information from your blog..
ReplyDeleteMulesoft Training in Hyderabad
Mulesoft Online Training
Thanks For sharing such a useful and informative stuff
ReplyDeletemulesoft training in hyderabad
mulesoft training in bangalore
mulesoft training hyderabad
best mulesoft online training
Thanks for sharing valuable information and keep posting.
ReplyDeletelearn mulesoft online
mulesoft online training india
nice ...........................................!
ReplyDeleteAbinitio online training
Abinitio training
Android online training
Android training
Ansible online training
Ansible training
Appium online training
Appium training
AWS online training
AWS training
Azure DevOps online training
Azure DevOps training
Azure online training
Azure training
Chef online training
Chef training
Data Guard online training
Data Guard training
Data Modelling online training
Data Modelling training
Wow, amazing post! Really engaging, thank you.
ReplyDeleteMule soft training in bangalore
I really liked your blog article.Really thank you! Really Cool.
ReplyDeletesalesforce online training
hadoop online training
mulesoft online training
linux online training
etl testing online training
web methods online training
This comment has been removed by the author.
ReplyDeleteExcellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative. We are also providing the best services click on below links to visit our website.
ReplyDeleteOracle Fusion HCM Training
Workday Training
Okta Training
Palo Alto Training
Adobe Analytics Training
Thank you for sharing such a nice and interesting blog with us.
ReplyDeleteMulesoft Online Course
Mule ESB Training