MULE LDAP Transport

default-modules.png

MULE LDAP Transport

No votes yet

Brief explanation of the classes in this project:

./src/main/java/org/mule/transport/ldapx/i18n/LdapxMessages.java

The LdapxMessages java class contains methods for access i18n messages embedded in your java code.

./src/main/resources/META-INF/services/org/mule/i18n/ldapx-messages.properties

These message properties contain i18n strings used by LdapxMessages.java.

./src/main/java/org/mule/transport/ldapx/LdapxConnector.java

The connector for this transport. This is used for configuing common properties on endpoints for this transport
and initialising shared resources.

./src/main/java/org/mule/transport/ldapx/LdapxEndpointURIBuilder.java

The class responsible for parsing custom endpoints for this transport.

./src/main/java/org/mule/transport/ldapx/LdapxInboundTransformer.java

This transformer should convert the inbound message into a type consumable by Mule. For example, in the case of JMS this
class would would convert a JMSMessage to a String, object, Map, etc depending on the time of message. If your transport
does not have a specific message type you do not need this class.

./src/main/java/org/mule/transport/ldapx/LdapxOutboundTransformer.java

This transformer should convert the otbound message into a type supported by the underlying technology. For example,
in the case of JMS this class would would convert a MuleMessage to a JMSMessage. If your transport
does not have a specific message type you do not need this class.

./src/main/java/org/mule/transport/ldapx/LdapxMuleMessageFactory.java

This class is used to convert a transport specific message (e.g. a JMS message object) into a
MuleMessage instance. This factory needs to extract the payload from the message as well as its
message properties and attachments.

./src/main/java/org/mule/transport/ldapx/LdapxMessageDispatcher.java

This part of the transport responsible for outbound endpoints (client). This class should implement the logic needed to
dispatch messages over the underlying transport.

./src/main/java/org/mule/transport/ldapx/LdapxMessageDispatcherFactory.java

The factory used to create LdapxMessageDispatcher instances.

./src/main/java/org/mule/transport/ldapx/LdapxMessageReceiver.java

This part of the transport responsible for inbound endpoints. This class should implement the logic need to
receive messages from the underlying transport. Mule supports polling receivers, that pull events from the transport, but
users can implement listener interfaces to have events pushed to the receiver.

./src/main/resources/META-INF/mule-ldapx.xsd

The configuration schema file for this module. All configuration elements should be defined in this schema.

./src/main/resources/META-INF/spring.schemas

Contains a mapping of the Namespace URI for this projects schema.

./src/main/resources/META-INF/spring.handlers

Contains a mapping of the namespace handler to use for the schema in this project.

./src/main/java/org/mule/transport/ldapx/config/LdapxNamespaceHandler.java

The implmentation of the namespace handler used to parse elements defined in mule-ldapx.xsd.

TESTING
=======

This project also contains test classes that can be run as part of a test suite.

./src/test/java/org/mule/transport/ldapx/LdapxTestCase.java

This is an example functional test case. The test will work as is, but you need to configure it to actually test your
code. For more information about testing see: http://www.mulesoft.org/documentation/display/MULE3USER/Functional+Testing.

./src/test/resources/ldapx-functional-test-config.xml

Defines the Mule configuration for the LdapxTestCase.java.

./src/test/java/org/mule/transport/ldapx/LdapxConnectorTestCase.java

The unit test case for testing the connecotr object for this transport.

./src/test/java/org/mule/transport/ldapx/LdapxEndpointTestCase.java

The unit test case for testing the endpoint builder object for this transport.

./src/test/java/org/mule/transport/ldapx/LdapxMuleMessageFactoryTestCase.java

The test case for testing the custom message factory for this transport.

./src/test/java/org/mule/transport/ldapx/LdapxMessageReceiverTestCase.java

The unit test case for testing the message receiver object for this transport.

./src/test/java/org/mule/transport/ldapx/LdapxNamespaceHandlerTestCase.java

A test case that is used to test each of the configuration elements inside your mule-ldapx.xsd schema file.

./src/test/resources/ldapx-namespace-config.xml

The configuration file for the LdapxNamespaceHandlerTestCase.java testcase.

Sample Application

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:script="http://www.mulesoft.org/schema/mule/scripting" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
        xmlns:spring="http://www.springframework.org/schema/beans" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
        xmlns:ldapx="http://www.mulesoft.org/schema/mule/ldapx"
        xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/3.1/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.1/mule-jms.xsd
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.1/mule-stdio.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesource.org/schema/mule/vm/3.1/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ldapx http://www.mulesoft.org/schema/mule/ldapx/3.1/mule-ldapx.xsd"
>

        <stdio:connector name="stdioConnector" outputMessage=":"
                promptMessage=":" />

        <ldapx:connector name="ldapxConnector" ldapHost="10.10.100.166"
                ldapPort="389" loginDN="CN=Administrator,CN=Users,DC=greytower,DC=local"
                password="admin" searchBase="CN=Users,DC=greytower,DC=local"
                searchScope="1" />

        <flow name="test_input">
                <stdio:inbound-endpoint system="IN"
                        exchange-pattern="one-way" connector-ref="stdioConnector" />
                <choice>
                        <when expression="add:*" evaluator="regex">
                                <expression-transformer expression="payload.replace('add:', '')"
                                        evaluator="groovy" />
                                <message-properties-transformer>
                                        <add-message-property key="ldap_objectClass"
                                                value="#[groovy:['user', 'person'].toArray(new String[1])]" />
                                        <add-message-property key="ldap_cn" value="#[payload]" />
                                        <add-message-property key="ldap_sn" value="#[payload]" />
                                        <add-message-property key="ldap_name" value="#[payload]" />
                                        <add-message-property key="ldap_userpassword"
                                                value="1qwEr4t7" />
                                        <add-message-property key="ldap_password"
                                                value="1qwEr4t7" />
                                        <add-message-property key="ldap_sAMAccountName"
                                                value="#[payload]" />
                                        <add-message-property key="ldap_distinguishedName"
                                                value="#[string:CN=#[payload],CN=Users,DC=greytower,DC=local]" />
                                </message-properties-transformer>
                                <expression-transformer expression="ldap_distinguishedName"
                                        evaluator="header" />
                                <ldapx:message-to-ldapentry-transformer />
                                <ldapx:ldapentry-to-addrequest-transformer />
                                <ldapx:outbound-endpoint exchange-pattern="one-way"
                                        connector-ref="ldapxConnector" address="ldapx://out" />
                        </when>
                        <when expression="delete:*" evaluator="regex">
                                <expression-transformer expression="payload.replace('delete:', '')"
                                        evaluator="groovy" />
                                <expression-transformer
                                        expression="CN=#[payload],CN=Users,DC=greytower,DC=local"
                                        evaluator="string" />
                                <ldapx:string-to-deleterequest-transformer />
                                <ldapx:outbound-endpoint exchange-pattern="one-way"
                                        connector-ref="ldapxConnector" address="ldapx://out" />
                        </when>
                        <when expression="search:*" evaluator="regex">
                                <expression-transformer expression="payload.replace('search:', '')"
                                        evaluator="groovy" />
                                <ldapx:string-to-searchrequest-transformer
                                        ldapConnector-ref="ldapxConnector" />
                                <ldapx:outbound-endpoint exchange-pattern="one-way"
                                        connector-ref="ldapxConnector" address="ldapx://out" />
                        </when>
                        <when expression="modify:*" evaluator="regex">
                                <expression-transformer expression="payload.replace('modify:', '')"
                                        evaluator="groovy" />
                                <message-properties-transformer>
                                        <add-message-property key="ldap_objectClass"
                                                value="#[groovy:['user', 'person'].toArray(new String[1])]" />
                                        <add-message-property key="ldap_cn" value="#[payload]" />
                                        <add-message-property key="ldap_sn" value="#[payload]" />
                                        <add-message-property key="ldap_name" value="#[payload]" />
                                        <add-message-property key="ldap_userpassword"
                                                value="Jeej3chi" />
                                        <add-message-property key="ldap_sAMAccountName"
                                                value="#[payload]" />
                                        <add-message-property key="ldap_distinguishedName"
                                                value="#[string:CN=#[payload],CN=Users,DC=greytower,DC=local]" />
                                </message-properties-transformer>
                                <expression-transformer expression="ldap_distinguishedName"
                                        evaluator="header" />
                                <ldapx:message-to-ldapentry-transformer />
                                <ldapx:ldapentry-to-modifyrequest-transformer
                                        ldapConnector-ref="ldapxConnector" />
                                <ldapx:outbound-endpoint exchange-pattern="one-way"
                                        connector-ref="ldapxConnector" address="ldapx://out" />
                        </when>
                        <otherwise>
                                <expression-transformer expression="Unknown command. Try add, delete or search"
                                        evaluator="string" />
                                <stdio:outbound-endpoint system="OUT"
                                        exchange-pattern="one-way" connector-ref="stdioConnector" />
                        </otherwise>
                </choice>
        </flow>

        <flow name="test_output">
                <ldapx:inbound-endpoint exchange-pattern="one-way"
                        connector-ref="ldapxConnector" address="ldapx://in" />
                <choice>
                        <when expression="com.novell.ldap.LDAPResponse" evaluator="payload-type">
                                <expression-transformer
                                        expression="[Response: [Matched DN: #[jxpath:/matchedDN]], [Error code: #[jxpath:/resultCode]], [Error message: #[jxpath:/errorMessage]]]"
                                        evaluator="string" />
                                <stdio:outbound-endpoint system="OUT"
                                        exchange-pattern="one-way" connector-ref="stdioConnector" />
                        </when>
                        <when expression="com.novell.ldap.LDAPSearchResult" evaluator="payload-type">
                                <ldapx:searchresult-to-ldapentry-transformer />
                                <script:transformer>
                                        <script:script engine="groovy">
                                                def getAttributeString(attrs, key) {
                                                return attrs.getAttribute("name").getStringValue()
                                                }
                                                attrs = payload.getAttributeSet()
                                                return [name: getAttributeString(attrs, "name"), key2:
                                                getAttributeString(attrs, "name")]
</script:script>
                                </script:transformer>
                                <!-- <ldapx:ldapentry-to-string-transformer /> -->
                                <expression-transformer
                                        expression="Name = #[map-payload:name], #[map-payload:key2]"
                                        evaluator="string" />
                                <stdio:outbound-endpoint system="OUT"
                                        exchange-pattern="one-way" connector-ref="stdioConnector" />
                        </when>
                        <when expression="org.mule.transport.NullPayload" evaluator="payload-type">
                                <expression-transformer expression="Null message received."
                                        evaluator="string" />
                                <!-- Do not do anything -->
                        </when>
                        <otherwise>
                                <expression-transformer
                                        expression="Unknown message received. Class #[function:payloadClass]"
                                        evaluator="string" />
                                <stdio:outbound-endpoint system="OUT"
                                        exchange-pattern="one-way" connector-ref="stdioConnector" />
                        </otherwise>
                </choice>
        </flow>

</mule>