Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

LDAP Connector

Select

This document provides an example of a simple LDAP Extension configuration, including basic instructions for installing and connecting to an LDAP server using the LDAP connector.

The Lightweight Directory Access Protocol (LDAP) is a public standard that facilitates maintenance and access to distributed directories (such as network user privilege information) over an Internet Protocol (IP) network.

Many LDAP servers are included in free-use open source projects and packages. The particulars of installing, running and configuring LDAP servers fall outside the scope of this document.

Prerequisites

To use the LDAP connector, you must have the following:

  • Access to either an OpenLDAP, Apache Directory, or MicroSoft Active Directory Instance.

  • Anypoint Studio version 7.0 (or higher) or Anypoint Design Center.

To use the LDAP connector in a production environment, you must have either:

  • An Enterprise license to use Mule.

  • A CloudHub Starter, Professional, or Enterprise account.

This document assumes that you are familiar with Mule, Anypoint Connectors, Anypoint Studio essentials, elements in a Mule flow, and global elements.

Compatibility

The LDAP connector is compatible with:

Application/Service Version

Mule Runtime

4.0.0

Java

1.8.0_x or higher

Anypoint Studio

7.0 or higher

Installing the Connector

  1. In Anypoint Studio, click the Exchange icon in the Studio taskbar.

  2. Click Login in Anypoint Exchange.

  3. Search for the connector and click Install.

  4. Follow the prompts to install the connector.

When Studio has an update, a message displays in the lower right corner, which you can click to install the update.

Configuring the LDAP Connector Global Element

To use the LDAP connector in a Mule application, you must configure a global LDAP configuration element that can be used by as many LDAP connectors as you require for your application. Note that this connector supports server side pooling for Basic configuration, which can be configured in the Pooling section.

  1. Click the Global Elements tab at the base of the canvas.

  2. On the Global Configuration Elements screen, click Create. Following window would be displayed.

    Global Element Configuration Wizard

  3. In the Choose Global Type wizard, expand Connector Configuration and select LDAP Configuration and click Ok. Following window would be displayed.

    Global Element Properties

  4. Choose among one of the 2 configurations provided in the drop down list - one for Basic and the other for TLS configuration and configure its properties.

    Parameter Description

    Name

    Enter a name for the configuration to reference it.

    Principal DN

    The DN (distinguished name) of the user

    Password

    The password of the user

    Authentication

    Specifies the authentication mechanism to use. Default: Simple

    URL

    The connection URL to the LDAP server

    In the image above, the placeholder values refer to a configuration file mule-artifact.properties placed in the src/main/resources folder of your project. You can either enter your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better re-usability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ.

  5. Keep the Advanced tab and the Pooling tabs with their default entries. Pooling tab is only available for Basic configuration.

  6. Click Test Connection to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to your instance of LDAP server.

  7. Click OK to save the global connector configurations.

Configuring With the XML Editor or Standalone

Ensure that you have included the LDAP namespace in your configuration file.

         
      
1
2
3
4
5
6
7
8
9
10
11
12
<mule xmlns:ldap="http://www.mulesoft.org/schema/mule/ldap" xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ldap http://www.mulesoft.org/schema/mule/ldap/current/mule-ldap.xsd">



<!-- Put your flows and configuration elements here -->
</mule>
Create a global element for LDAP Basic configuration using the following configuration code:

         
      
1
2
3
4
5
6
7
8
9
        <ldap:config name="LDAP_Configuration" doc:name="LDAP Configuration">
                <ldap:basic-connection authDn="${config.principal.dn}"
                        authPassword="${config.password}" url="${config.url}">
                        <ldap:extended-configurations>
                                <ldap:extended-configuration key="java.naming.ldap.factory.socket"
                                        value="org.mule.extension.ldap.internal.util.BypassTrustSSLSocketFactory" />
                        </ldap:extended-configurations>
                </ldap:basic-connection>
        </ldap:config>
Save the changes made to the XML file.

Using the Connector

The LDAP connector supports the following operations:

Operation Description

Bind

Authenticates against the LDAP server. This occurs automatically before each operation but can also be performed on request.

Search

Performs an LDAP search in a base DN with a given filter.

Search one

Performs an LDAP search that is supposed to return a unique result.

Paged result search

Performs an LDAP search and streams result to the rest of the flow.

Lookup

Retrieves a unique LDAP entry.

Exists

Checks whether an LDAP entry exists in the LDAP server or not.

Add

Creates a new LDAP entry.

Add single-valued attribute

Adds a specific single-valued attribute to an existing LDAP entry.

Add multi-valued attribute

Adds a specific multi-valued attribute to an existing LDAP entry.

Modify

Updates an existing LDAP entry.

Modify single-valued attribute

Updates specific single-valued attribute of an existing LDAP entry.

Modify multi-valued attribute

Updates specific multi-valued attribute of an existing LDAP entry.

Delete

Deletes an existing LDAP entry.

Delete single-valued attribute

Deletes specific single-valued attribute to an existing LDAP entry.

Delete multi-valued attribute

Deletes specific multi-valued attribute to an existing LDAP entry.

Rename

Renames an existing LDAP entry.

Connector Namespace and Schema

When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.

Namespace: http://www.mulesoft.org/schema/mule/ldap

Schema Location: http://www.mulesoft.org/schema/mule/ldap/current/mule-ldap.xsd

If you are manually coding the Mule application in Studio’s XML editor or other text editor, paste these into the header of your Configuration XML, inside the <mule> tag.

          
       
1
2
3
4
5
6
7
8
9
10
<mule xmlns:ldap="http://www.mulesoft.org/schema/mule/ldap" xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ldap http://www.mulesoft.org/schema/mule/ldap/current/mule-ldap.xsd">

      <!-- put your global configuration elements and flows here -->

</mule>

Using the Connector in a Mavenized Mule App

If you are coding a Mavenized Mule application, this XML snippet must be included in your pom.xml file.


          
       
1
2
3
4
5
6
<dependency>
    <groupId>org.mule.connectors</groupId>
    <artifactId>mule-ldap-connector</artifactId>
    <version>3.0.0</version>
    <classifier>mule-plugin</classifier>
</dependency>

Use Cases and Demos

Listed below are the most common use cases for the LDAP connector, and some demo application walkthroughs.

Adding User Accounts to Active Directory

Business user accounts can be added to Active Directory groups defined on the base DN.

Retrieve User attributes

Basic attributes of the business user can be retrieved for one or more purposes, like e-mail or phone.

Adding to a Flow

  1. Create a new Mule Project in Anypoint Studio.

  2. Add a suitable Mule Inbound Endpoint, such as the HTTP listener at the beginning of the flow.

  3. Drag any operation of the LDAP connector, say Add entry operation and drop it onto the canvas.

  4. Click the connector to open the Properties Editor.

    Flow Settings

  5. Configure the following parameters:

    Field Description

    Display Name

    Enter a unique label for the LDAP operation in your application.

    Basic Settings

    Extension configuration

    Connect to a global element linked to this connector. Global elements encapsulate reusable data about the connection to the target resource or service. Select the global LDAP connector element that you had created.

    General

    Entry

    #[payload], which refers to a LDAPEntry object created in the previous component typically a DataWeave component and transformed as input payload to this processor

  6. Click the Refresh button just after the Structural object class text field to fetch the metadata based on the Structural Object Class, which traverses the directory information tree to retrieve the hierarchy and all the properties it inherits.

Example Use Case 1 with LDAP Connector

Add and delete an organizational person from an organizational unit.

Add User Entry Flow

  1. Create a new Mule Project in Anypoint Studio.

  2. Add the below properties to mule-artifact.properties file to hold your LDAP credentials and place it in the project’s src/main/resources directory.

    
                 
              
    1
    2
    3
    
    config.principal.dn=<DN>
    config.password=<Password>
    config.url=<URL>
  3. Drag an HTTP Listener onto the canvas and configure the following parameters:

    Parameter Value

    Display Name

    HTTP

    Extension configuration

    If no HTTP element has been created yet, click the plus sign to add a new HTTP Listener Configuration and click OK (leave the values to its defaults).

    Path

    /

  4. Now let’s create the organizational unit entry using a DataWeave component. Drag the DataWeave component next to the HTTP Listener and use the script below.

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    8
    
    %dw 2.0
    output application/java
    ---
    {
            dn : "ou=DevOpsGroup," ++ attributes.queryParams.dn,
            ou : "DevOpsGroup",
            objectclass : ["top", "organizationalUnit"]
    }
  5. Drag Add entry operation of the LDAP connector next to the DataWeave component to add the LDAP Entry.

  6. Configure the LDAP connector by adding a new LDAP Global Element. Click the plus sign next to the Extension configuration field.

    1. Configure the global element according to the table below:

      Parameter Description Value

      Name

      Enter a name for the configuration to reference it.

      <Configuration_Name>

      Principal DN

      The DN (distinguished name) of the user.

      ${config.principal.dn}

      Password

      The password of the user.

      ${config.password}

      URL

      The connection URL to the LDAP server.

      ${config.url}

    2. The corresponding XML configuration should be as follows:

      
                      
                   
      1
      2
      3
      4
      5
      6
      7
      8
      9
      
              <ldap:config name="LDAP_Configuration" doc:name="LDAP Configuration">
                      <ldap:basic-connection authDn="${config.principal.dn}"
                              authPassword="${config.password}" url="${config.url}">
                              <ldap:extended-configurations>
                                      <ldap:extended-configuration key="java.naming.ldap.factory.socket"
                                              value="org.mule.extension.ldap.internal.util.BypassTrustSSLSocketFactory" />
                              </ldap:extended-configurations>
                      </ldap:basic-connection>
              </ldap:config>
  7. Click Test Connection to confirm that Mule can connect with the LDAP server instance. If the connection is successful, click OK to save the configuration. Otherwise, review or correct any incorrect parameters, then test again.

  8. Back in the properties editor of the LDAP connector, configure the parameters required for the add entry operation:

    Parameter Value

    Display Name

    Add Group Entry to LDAP Directory

    Basic Settings

    Extension configuration

    Select the global LDAP connector element that you had created.

    General

    Entry

    #[payload], the default value

  9. Now let’s create the organizational person entry using a DataWeave component. Drag the DataWeave component next to the LDAP connector and use the script below.

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    %dw 2.0
    output application/java
    ---
    {
            dn : "cn=Test User,ou=DevOpsGroup," ++ attributes.queryParams.dn,
            uid : "testUser",
            cn : "Test User",
            sn : "User",
            userPassword : "test1234",
            objectclass : ["top", "person", "organizationalPerson", "inetOrgPerson"]
    }
  10. Drag Add entry operation of the LDAP connector next to the DataWeave component to add the LDAP User Entry.

  11. In the properties editor of the LDAP connector, configure the parameters as below:

    Parameter Value

    Display Name

    Add User Entry to LDAP Directory

    Basic Settings

    Extension configuration

    Select the global LDAP connector element that you had created.

    General

    Entry

    #[payload], the default value

  12. Now that we have successfully added the entries, let’s try to delete them using the LDAP connector.

  13. Drag Delete entry operation of the LDAP connector next to the LDAP connector to delete the LDAP User Entry.

  14. In the properties editor of the LDAP connector, configure the parameters as below:

    Parameter Value

    Display Name

    Delete User Entry from LDAP Directory

    Basic Settings

    Extension configuration

    Select the global LDAP connector element that you had created.

    General

    DN

    #['cn=Test User,ou=DevOpsGroup,' ++ attributes.queryParams.dn]

  15. Drag another Delete entry operation of the LDAP connector next to the LDAP connector to delete the LDAP Group Entry.

    Parameter Value

    Display Name

    Delete Group Entry from LDAP Directory

    Basic Settings

    Extension configuration

    Select the global LDAP connector element that you had created.

    General

    DN

    #['ou=DevOpsGroup,' ++ attributes.queryParams.dn]

  16. Finally drag the DataWeave component next to the LDAP connector to set the payload to "Flow Successfully Completed".

Example Use Case 1 Code

Paste this code into your XML Editor to quickly load the flow for this example use case into your Mule application.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:ldap="http://www.mulesoft.org/schema/mule/ldap"
        xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ldap http://www.mulesoft.org/schema/mule/ldap/current/mule-ldap.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">


        <http:listener-config name="HTTP_Listener_config"
                doc:name="HTTP Listener config">
                <http:listener-connection host="127.0.0.1"
                        port="8081" />
        </http:listener-config>

        <ldap:config name="LDAP_Configuration" doc:name="LDAP Configuration">
                <ldap:basic-connection authDn="${config.principal.dn}"
                        authPassword="${config.password}" url="${config.url}">
                        <ldap:extended-configurations>
                                <ldap:extended-configuration key="java.naming.ldap.factory.socket"
                                        value="org.mule.extension.ldap.internal.util.BypassTrustSSLSocketFactory" />
                        </ldap:extended-configurations>
                </ldap:basic-connection>
        </ldap:config>

        <flow name="ldap-add-entry-flow">
                <http:listener config-ref="HTTP_Listener_config" path="/"
                        doc:name="HTTP" />

                <ee:transform doc:name="DataWeave to Create DevOps Group Object">
                        <ee:message>
                                <ee:set-payload><![CDATA[%dw 2.0
output application/java
---
{
        dn : "ou=DevOpsGroup," ++ attributes.queryParams.dn,
        ou : "DevOpsGroup",
        objectclass : ["top", "organizationalUnit"]
}
]]></ee:set-payload>
                        </ee:message>
                </ee:transform>

                <ldap:add config-ref="LDAP_Configuration" doc:name="Add Group Entry to LDAP Directory" />


                <ee:transform doc:name="DataWeave to Create User Object">
                        <ee:message>
                                <ee:set-payload><![CDATA[%dw 2.0
output application/java
---
{
        dn : "cn=Test User,ou=DevOpsGroup," ++ attributes.queryParams.dn,
        uid : "testUser",
        cn : "Test User",
        sn : "User",
        userPassword : "test1234",
        objectclass : ["top", "person", "organizationalPerson", "inetOrgPerson"]
}
]]></ee:set-payload>
                        </ee:message>
                </ee:transform>


                <ldap:add config-ref="LDAP_Configuration" doc:name="Add User Entry to LDAP Directory" />

                <ldap:delete config-ref="LDAP_Configuration"
                        dn="#['cn=Test User,ou=DevOpsGroup,' ++ attributes.queryParams.dn]"
                        doc:name="Delete User Entry from LDAP Directory" />

                <ldap:delete config-ref="LDAP_Configuration"
                        dn="#['ou=DevOpsGroup,' ++ attributes.queryParams.dn]" doc:name="Delete Group Entry from LDAP Directory" />

                <ee:transform doc:name="DataWeave to set Payload indicating flow completed">
                        <ee:message>
                                <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
        result : "Flow Successfully Completed"
}
]]></ee:set-payload>
                        </ee:message>
                </ee:transform>
        </flow>


</mule>

Example Use Case 2 with LDAP Connector

A custom trust store can be setup to tell which servers are allowed to communicate to.

Extended configuration parameters can be used for this to specify a custom trust store.

The same Use Case 1 (above) can be used to execute this except for the configuration part of LDAP connector which should now use TLS configuration.

Find below the XML configuration snippet of LDAP connector which uses TLS configuration and update the Use Case 1 xml file (above) with it.


          
       
1
2
3
4
5
6
7
8
9
<ldap:config name="LDAP_Configuration" doc:name="LDAP Configuration">
<ldap:tls-connection authDn="${config.principal.dn}"
                            authPassword="${config.password}" url="${config.url}">
    <ldap:extended-configurations>
        <ldap:extended-configuration key="org.mule.module.ldap.trustStorePath" value="the_path_to_trust_store_jks_file" />
        <ldap:extended-configuration key="org.mule.module.ldap.trustStorePassword" value="changeit" />
    </ldap:extended-configurations>
</ldap:tls-connection>
</ldap:config>

Run Demo Application

  1. Save and run the project as a Mule Application.

  2. Open a web browser and check the response after entering the URL:

    http://localhost:8081/?dn=dc=mulesoft,dc=org.