You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/05/05 12:07:26 UTC

[2/4] camel git commit: Added camel-ldap docs to Gitbook

Added camel-ldap docs to Gitbook


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d83af661
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d83af661
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d83af661

Branch: refs/heads/master
Commit: d83af66135bb46961f13685792f0bdda77133c5c
Parents: bccfc2b
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu May 5 13:28:51 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu May 5 13:28:51 2016 +0200

----------------------------------------------------------------------
 components/camel-ldap/src/main/docs/ldap.adoc | 345 +++++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                |   1 +
 2 files changed, 346 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d83af661/components/camel-ldap/src/main/docs/ldap.adoc
----------------------------------------------------------------------
diff --git a/components/camel-ldap/src/main/docs/ldap.adoc b/components/camel-ldap/src/main/docs/ldap.adoc
new file mode 100644
index 0000000..09a21c5
--- /dev/null
+++ b/components/camel-ldap/src/main/docs/ldap.adoc
@@ -0,0 +1,345 @@
+[[LDAP-LDAPComponent]]
+LDAP Component
+~~~~~~~~~~~~~~
+
+The *ldap* component allows you to perform searches in LDAP servers
+using filters as the message payload. +
+ This component uses standard JNDI (`javax.naming` package) to access
+the server.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-ldap</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+[[LDAP-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+-----------------------------
+ldap:ldapServerBean[?options]
+-----------------------------
+
+The _ldapServerBean_ portion of the URI refers to a
+http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html[DirContext]
+bean in the registry. The LDAP component only supports producer
+endpoints, which means that an `ldap` URI cannot appear in the `from` at
+the start of a route.
+
+You can append query options to the URI in the following format,
+`?option=value&option=value&...`
+
+[[LDAP-Options]]
+Options
+^^^^^^^
+
+
+// component options: START
+The LDAP component has no options.
+// component options: END
+
+
+
+// endpoint options: START
+The LDAP component supports 7 endpoint options which are listed below:
+
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| dirContextName | producer |  | String | *Required* Name of javax.naming.directory.DirContext bean to lookup in the registry.
+| base | producer | ou=system | String | The base DN for searches.
+| pageSize | producer |  | Integer | When specified the ldap module uses paging to retrieve all results (most LDAP Servers throw an exception when trying to retrieve more than 1000 entries in one query). To be able to use this a LdapContext (subclass of DirContext) has to be passed in as ldapServerBean (otherwise an exception is thrown)
+| returnedAttributes | producer |  | String | Comma-separated list of attributes that should be set in each entry of the result
+| scope | producer | subtree | String | Specifies how deeply to search the tree of entries starting at the base DN.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+|=======================================================================
+// endpoint options: END
+
+
+[[LDAP-Result]]
+Result
+^^^^^^
+
+The result is returned in the Out body as a
+`ArrayList<javax.naming.directory.SearchResult>` object.
+
+[[LDAP-DirContext]]
+DirContext
+^^^^^^^^^^
+
+The URI, `ldap:ldapserver`, references a Spring bean with the ID,
+`ldapserver`. The `ldapserver` bean may be defined as follows:
+
+[source,java]
+-----------------------------------------------------------------------------------------
+<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
+  <constructor-arg>
+    <props>
+      <prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
+      <prop key="java.naming.provider.url">ldap://localhost:10389</prop>
+      <prop key="java.naming.security.authentication">none</prop>
+    </props>
+  </constructor-arg>
+</bean>
+-----------------------------------------------------------------------------------------
+
+The preceding example declares a regular Sun based LDAP `DirContext`
+that connects anonymously to a locally hosted LDAP server.
+
+NOTE: `DirContext` objects are *not* required to support concurrency by
+contract. It is therefore important that the directory context is
+declared with the setting, `scope="prototype"`, in the `bean` definition
+or that the context supports concurrency. In the Spring framework,
+`prototype` scoped objects are instantiated each time they are looked
+up.
+
+[[LDAP-Samples]]
+Samples
+^^^^^^^
+
+Following on from the Spring configuration above, the code sample below
+sends an LDAP request to filter search a group for a member. The Common
+Name is then extracted from the response.
+
+[source,java]
+----------------------------------------------------------
+ProducerTemplate<Exchange> template = exchange
+  .getContext().createProducerTemplate();
+
+Collection<?> results = (Collection<?>) (template
+  .sendBody(
+    "ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system",
+    "(member=uid=huntc,ou=users,ou=system)"));
+
+if (results.size() > 0) {
+  // Extract what we need from the device's profile
+
+  Iterator<?> resultIter = results.iterator();
+  SearchResult searchResult = (SearchResult) resultIter
+      .next();
+  Attributes attributes = searchResult
+      .getAttributes();
+  Attribute deviceCNAttr = attributes.get("cn");
+  String deviceCN = (String) deviceCNAttr.get();
+
+  ...
+----------------------------------------------------------
+
+If no specific filter is required - for example, you just need to look
+up a single entry - specify a wildcard filter expression. For example,
+if the LDAP entry has a Common Name, use a filter expression like:
+
+[source,java]
+------
+(cn=*)
+------
+
+[[LDAP-Bindingusingcredentials]]
+Binding using credentials
++++++++++++++++++++++++++
+
+A Camel end user donated this sample code he used to bind to the ldap
+server using credentials.
+
+[source,java]
+---------------------------------------------------------------------------------------
+Properties props = new Properties();
+props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
+props.setProperty(Context.PROVIDER_URL, "ldap://localhost:389");
+props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
+props.setProperty(Context.REFERRAL, "ignore");
+props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
+props.setProperty(Context.SECURITY_PRINCIPAL, "cn=Manager");
+props.setProperty(Context.SECURITY_CREDENTIALS, "secret");
+
+SimpleRegistry reg = new SimpleRegistry();
+reg.put("myldap", new InitialLdapContext(props, null));
+
+CamelContext context = new DefaultCamelContext(reg);
+context.addRoutes(
+    new RouteBuilder() {
+        public void configure() throws Exception { 
+            from("direct:start").to("ldap:myldap?base=ou=test");
+        }
+    }
+);
+context.start();
+
+ProducerTemplate template = context.createProducerTemplate();
+
+Endpoint endpoint = context.getEndpoint("direct:start");
+Exchange exchange = endpoint.createExchange();
+exchange.getIn().setBody("(uid=test)");
+Exchange out = template.send(endpoint, exchange);
+
+Collection<SearchResult> data = out.getOut().getBody(Collection.class);
+assert data != null;
+assert !data.isEmpty();
+
+System.out.println(out.getOut().getBody());
+
+context.stop();
+---------------------------------------------------------------------------------------
+
+[[LDAP-ConfiguringSSL]]
+Configuring SSL
+^^^^^^^^^^^^^^^
+
+All required is to create a custom socket factory and reference it in
+the InitialDirContext bean - see below sample.
+
+*SSL Configuration*
+
+[source,xml]
+----------------------------------------------------------------------------------------------------------------------------------
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+                 http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
+
+
+    <sslContextParameters xmlns="http://camel.apache.org/schema/blueprint"
+                          id="sslContextParameters">
+        <keyManagers
+                keyPassword="{{keystore.pwd}}">
+            <keyStore
+                    resource="{{keystore.url}}"
+                    password="{{keystore.pwd}}"/>
+        </keyManagers>
+    </sslContextParameters>
+
+    <bean id="customSocketFactory" class="zotix.co.util.CustomSocketFactory">
+        <argument ref="sslContextParameters" />
+    </bean>
+    <bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
+        <argument>
+            <props>
+                <prop key="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/>
+                <prop key="java.naming.provider.url" value="ldaps://lab.zotix.co:636"/>
+                <prop key="java.naming.security.protocol" value="ssl"/>
+                <prop key="java.naming.security.authentication" value="simple" />
+                <prop key="java.naming.security.principal" value="cn=Manager,dc=example,dc=com"/>
+                <prop key="java.naming.security.credentials" value="passw0rd"/>
+                <prop key="java.naming.ldap.factory.socket"
+                      value="zotix.co.util.CustomSocketFactory"/>
+            </props>
+        </argument>
+    </bean>
+</blueprint>
+----------------------------------------------------------------------------------------------------------------------------------
+
+*Custom Socket Factory*
+
+[source,java]
+-----------------------------------------------------------------------------------------------------
+import org.apache.camel.util.jsse.SSLContextParameters;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.KeyStore;
+
+/**
+ * The CustomSocketFactory. Loads the KeyStore and creates an instance of SSLSocketFactory
+ */
+public class CustomSocketFactory extends SSLSocketFactory {
+
+    private static SSLSocketFactory socketFactory;
+
+    /**
+     * Called by the getDefault() method.
+     */
+    public CustomSocketFactory() {
+
+    }
+
+    /**
+     * Called by Blueprint DI to initialise an instance of SocketFactory
+     *
+     * @param sslContextParameters
+     */
+    public CustomSocketFactory(SSLContextParameters sslContextParameters) {
+        try {
+            KeyStore keyStore = sslContextParameters.getKeyManagers().getKeyStore().createKeyStore();
+            TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
+            tmf.init(keyStore);
+            SSLContext ctx = SSLContext.getInstance("TLS");
+            ctx.init(null, tmf.getTrustManagers(), null);
+            socketFactory = ctx.getSocketFactory();
+        } catch (Exception ex) {
+            ex.printStackTrace(System.err);  /* handle exception */
+        }
+    }
+
+    /**
+     * Getter for the SocketFactory
+     *
+     * @return
+     */
+    public static SocketFactory getDefault() {
+        return new CustomSocketFactory();
+    }
+
+    @Override
+    public String[] getDefaultCipherSuites() {
+        return socketFactory.getDefaultCipherSuites();
+    }
+
+    @Override
+    public String[] getSupportedCipherSuites() {
+        return socketFactory.getSupportedCipherSuites();
+    }
+
+    @Override
+    public Socket createSocket(Socket socket, String string, int i, boolean bln) throws IOException {
+        return socketFactory.createSocket(socket, string, i, bln);
+    }
+
+    @Override
+    public Socket createSocket(String string, int i) throws IOException {
+        return socketFactory.createSocket(string, i);
+    }
+
+    @Override
+    public Socket createSocket(String string, int i, InetAddress ia, int i1) throws IOException {
+        return socketFactory.createSocket(string, i, ia, i1);
+    }
+
+    @Override
+    public Socket createSocket(InetAddress ia, int i) throws IOException {
+        return socketFactory.createSocket(ia, i);
+    }
+
+    @Override
+    public Socket createSocket(InetAddress ia, int i, InetAddress ia1, int i1) throws IOException {
+        return socketFactory.createSocket(ia, i, ia1, i1);
+    }
+}
+-----------------------------------------------------------------------------------------------------
+
+�
+
+[[LDAP-SeeAlso]]
+See Also
+^^^^^^^^
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
+

http://git-wip-us.apache.org/repos/asf/camel/blob/d83af661/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index b8a7719..86f524d 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -181,6 +181,7 @@
     * [Krati](krati.adoc)
     * [Kubernetes](kubernetes.adoc)
     * [Kura](kura.adoc)
+    * [LDAP](ldap.adoc)
     * [Metrics](metrics.adoc)
     * [Mock](mock.adoc)
     * [NATS](nats.adoc)