Nav

LDAP Connector

This document provides an example of a simple LDAP connector 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.

This user guide assumes familiarity with Mule, Anypoint Connectors, and Anypoint Studio Essentials. To increase your familiarity with Studio, consider completing one or more Anypoint Studio Tutorials. Further, this page assumes that you have a basic understanding of Elements in a Mule Flow and Global Elements.

MuleSoft maintains this connector under the Select support policy.

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 - Enterprise Edition.

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.

Contact the MuleSoft Sales Team to obtain either of these. Read more about Installing an Enterprise License.

Compatibility

The LDAP connector is compatible with:

Application/Service Version

Mule Runtime

3.6.0 or higher

Java

1.7.0_x or higher

Anypoint Studio

5.2 or higher

Installing the Connector

To install LDAP connector in Anypoint Studio, follow the steps below:

  • Open Anypoint Studio and go to Help > Install New Software.

  • Select Anypoint Connectors Update Site - http://repository.mulesoft.org/connectors/releases/3.5.0.

  • Locate and select the LDAP connector. Anypoint Studio Install Window

  • Click Next and accept the License Agreement.

  • Restart Studio when prompted.

  • Now, the LDAP connector should appear in your Studio Palette:

    Anypoint Studio palette - LDAP connector

Read more about Installing Connectors.

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 connection caching, which can be configuring in the Cache Configuration tab of the global element.

Read more about Global Elements.
  1. Click the Global Elements tab at the base of the canvas.

  2. On the Global Mule Configuration Elements screen, click Create.

  3. In the Choose Global Type wizard, expand Connector Configuration and select LDAP: Configuration and click Ok.

    Global Element Configuration Wizard

  4. Configure the parameters according to instructions below.

    Global Element Configuration

    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

    URL

    The connection URL to the LDAP server

    Authentication

    Specifies the authentication mechanism to use. Default: Simple

  5. In the image above, the placeholder values refer to a configuration file placed in the src folder of your project. See Learn how to configure properties.

  6. 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. See Deploying to Multiple Environments for instructions on how to manage this.

  7. Keep the Pooling Profile and the Reconnection tabs with their default entries.

  8. 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 Amazon S3. Read more about this in Testing Connections.

  9. Click OK to save the global connector configurations.

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

+


    
            
         
1
2
3
4
5
6
7
8
9
10
11
<mule 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:ldap="http://www.mulesoft.org/schema/mule/ldap"
        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">

<!-- Put your flows and configuration elements here -->
</mule>

+ . Create a global element for LDAP configuration using the following global configuration code:


    
            
         
1
2
3
4
5
<ldap:config name="LDAP_Configuration" authDn="${config.principal.dn}" authPassword="${config.password}" url="${config.url}" doc:name="LDAP: Configuration">
    <ldap:extended-configuration>
        <ldap:extended-configuration key="java.naming.ldap.factory.socket">org.mule.module.ldap.security.BypassTrustSSLSocketFactory</ldap:extended-configuration>
    </ldap:extended-configuration>
</ldap:config>

+ . Save the changes made to the XML file.

Using the Connector

See a full list of operations for any version of the connector here.

The LDAP connector is an operation-based connector, which means that when you add the connector to your flow, you need to configure a specific operation for the connector to execute. The connector currently 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.

Unbind

Closes the current connection, forcing the login operation (bind) the next time it is used.

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 Entry

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.

Rename entry

Renames and existing LDAP entry (moves and entry from a DN to another one).

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.

LDAP entry to LDIF

Transforms a LDAPEntry to a String in LDIF representation (RFC 2849).

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.

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
11
12
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:sns="http://www.mulesoft.org/schema/mule/ldap"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core
               http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/sns
               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
<dependency>
        <groupId>org.mule.modules</groupId>
  <artifactId>mule-module-ldap</artifactId>
  <version>2.0.1</version>
</dependency>

Inside the <version> tags, put the desired version number, the word RELEASE for the latest release, or SNAPSHOT for the latest available version. The available versions to date are:

  • 2.0.1

  • 1.3.1

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 or File endpoint at the beginning of the flow.

  3. Drag and drop the LDAP connector onto the canvas.

  4. Click on the connector to open the Properties Editor.

    Flow Settings

  5. Configure the following parameters:

    Field Description

    Basic Settings

    Display Name

    Enter a unique label for the connector in your application.

    Connector 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 just created.

    Operation

    Select Add entry from the drop-down menu.

    General

    Topic Name

    Enter a unique name for the topic.

  6. Click the blank space on the canvas for the connector 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 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-app.properties file to hold your LDAP credentials and place it in the project’s src/main/app directory.

    
           
                    
                 
    1
    2
    3
    
    config.principal.dn=&lt;DN&gt;
    config.password=&lt;Password&gt;
    config.url=&lt;URL&gt;
  3. Drag an HTTP endpoint onto the canvas and configure the following parameters:

    Parameter Value

    Display Name

    HTTP

    Connector 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. Set the flow variable to hold the group distinguished name (dn), for example: DevOpsGroup.

  5. Drag the Variable Transformer next to the HTTP endpoint component. Configure according to the table below:

    Parameter Description Value

    Operation

    Select the transformer operation.

    Set Variable

    Name

    The variable name.

    dn

    Value

    The variable value.

    ou=DevOpsGroup,#[message.inboundProperties.'http.query.params'.dn]

  6. Now let’s create the organizational unit entry using a Groovy component. Drag the Groovy component next to the Variable Transformer and use the script below.

    
           
                    
                 
    1
    2
    3
    4
    5
    6
    7
    
    import org.mule.module.ldap.api.LDAPEntry;
    
    LDAPEntry entryToAdd = new LDAPEntry(flowVars.dn);
    entryToAdd.addAttribute("ou", "DevOpsGroup");
    entryToAdd.addAttribute("objectclass", ["top", "organizationalUnit"]);
    
    return entryToAdd
  7. Drag the LDAP connector next to the Groovy component to add the LDAP Entry.

  8. Configure the LDAP connector by adding a new LDAP Global Element. Click the plus sign next to the Connector 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
      
      &lt;ldap:config name="LDAP_Configuration" authDn="${config.principal.dn}" authPassword="${config.password}" url="${config.url}" doc:name="LDAP: Config"/&gt;
  9. Click Test Connection to confirm that Mule can connect with the LDAP instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.

  10. Back in the properties editor of the LDAP connector, configure the remaining parameters:

    Parameter Value

    Basic Settings

    Display Name

    Add Group Entry

    Operation

    Add entry

    General

    Entry Reference

    #[payload]

  11. Now let’s create the organizational person entry using a Groovy component. Drag the Groovy component next to the LDAP connector and add the below script to the Script text.

    
           
                    
                 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    import org.mule.module.ldap.api.LDAPEntry;
    
    LDAPEntry entryToAdd = new LDAPEntry("cn=Test User,"+ flowVars.dn);
    entryToAdd.addAttribute("uid", "testUser");
    entryToAdd.addAttribute("cn", "Test User");
    entryToAdd.addAttribute("sn", "User");
    entryToAdd.addAttribute("userPassword", "test1234");
    entryToAdd.addAttribute("objectclass", ["top", "person", "organizationalPerson", "inetOrgPerson"]);
    
    return entryToAdd
  12. Drag the LDAP connector next to the Groovy component. The connector adds the LDAP Entry created in the previous step.

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

    Parameter Value

    Basic Settings

    Display Name

    Add User Entry

    Connector Configuration

    LDAP_Configuration

    Operation

    Add entry

    General

    Entry Reference

    #[payload]

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

  15. Drag the LDAP connector besides the existing flow and configure the parameters as below:

    Parameter Value

    Basic Settings

    Display Name

    Delete User Entry

    Connector Configuration

    LDAP_Configuration

    Operation

    Delete entry

    General

    DN

    cn=Test User,#[flowVars.dn]

  16. Drag another LDAP connector to the right of the first LDAP connector and configure the parameters as below:

    Parameter Value

    Basic Settings

    Display Name

    Delete Group Entry

    Connector Configuration

    LDAP_Configuration

    Operation

    Delete entry

    General

    DN

    #[flowVars.dn]

  17. Finally drag Set Payload transformer to set the value to "Flow Successfully Completed".

Example Use Case 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
&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"&gt;
    &lt;http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/&gt;
    &lt;ldap:config name="LDAP_Configuration" authDn="${config.principal.dn}" authPassword="${config.password}" url="${config.url}" doc:name="LDAP: Config"&gt;
        &lt;ldap:extended-configuration&gt;
            &lt;ldap:extended-configuration key="java.naming.ldap.factory.socket"&gt;org.mule.module.ldap.security.BypassTrustSSLSocketFactory&lt;/ldap:extended-configuration&gt;
        &lt;/ldap:extended-configuration&gt;
    &lt;/ldap:config&gt;
    &lt;flow name="ldap-add-entry-flow"&gt;
        &lt;http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/&gt;
        &lt;set-variable variableName="dn" value="ou=DevOpsGroup,#[message.inboundProperties.'http.query.params'.dn]" doc:name="Set DN as Flow Variable"/&gt;
        &lt;scripting:component doc:name="Groovy Script to Create DevOps Group Object"&gt;
            &lt;scripting:script engine="Groovy"&gt;&lt;![CDATA[import org.mule.module.ldap.api.LDAPEntry;

LDAPEntry entryToAdd = new LDAPEntry(flowVars.dn);
entryToAdd.addAttribute("ou", "DevOpsGroup");
entryToAdd.addAttribute("objectclass", ["top", "organizationalUnit"]);

return entryToAdd]]&gt;&lt;/scripting:script&gt;
        &lt;/scripting:component&gt;
        &lt;ldap:add config-ref="LDAP_Configuration" doc:name="Add Group Entry to LDAP Directory"/&gt;
        &lt;scripting:component doc:name="Groovy Script to Create User Object"&gt;
            &lt;scripting:script engine="Groovy"&gt;&lt;![CDATA[import org.mule.module.ldap.api.LDAPEntry;

LDAPEntry entryToAdd = new LDAPEntry("cn=Test User,"+ flowVars.dn);
entryToAdd.addAttribute("uid", "testUser");
entryToAdd.addAttribute("cn", "Test User");
entryToAdd.addAttribute("sn", "User");
entryToAdd.addAttribute("userPassword", "test1234");
entryToAdd.addAttribute("objectclass", ["top", "person", "organizationalPerson", "inetOrgPerson"]);

return entryToAdd]]&gt;&lt;/scripting:script&gt;
        &lt;/scripting:component&gt;
        &lt;ldap:add config-ref="LDAP_Configuration"  doc:name="Add User Entry to LDAP Directory"/&gt;
        &lt;ldap:delete config-ref="LDAP_Configuration" dn="cn=Test User,#[flowVars.dn]" doc:name="Delete User Entry from LDAP Directory"/&gt;
        &lt;ldap:delete config-ref="LDAP_Configuration" dn="#[flowVars.dn]" doc:name="Delete Group Entry from LDAP Directory"/&gt;
        &lt;set-payload value="Flow Successfully Completed" doc:name="Set Payload: Flow Completed"/&gt;
    &lt;/flow&gt;
&lt;/mule&gt;

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.

Download Demo Applications

You can download a fully functional example from this link.

See Also