camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r934984 [2/2] - in /websites/production/camel/content: aws-s3.html book-component-appendix.html book-in-one-page.html cache/main.pageCache ldap.html
Date Sun, 04 Jan 2015 08:19:59 GMT
Modified: websites/production/camel/content/ldap.html
==============================================================================
--- websites/production/camel/content/ldap.html (original)
+++ websites/production/camel/content/ldap.html Sun Jan  4 08:19:59 2015
@@ -85,50 +85,19 @@
 	<tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="LDAP-LDAPComponent">LDAP Component</h2>
-
-<p>The <strong>ldap</strong> component allows you to perform searches in
LDAP servers using filters as the message payload.<br clear="none">
-This component uses standard JNDI (<code>javax.naming</code> package) to access
the server. </p>
-
-<p>Maven users will need to add the following dependency to their <code>pom.xml</code>
for this component:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
-<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
-&lt;dependency&gt;
+<div class="wiki-content maincontent"><h2 id="LDAP-LDAPComponent">LDAP Component</h2><p>The
<strong>ldap</strong> component allows you to perform searches in LDAP servers
using filters as the message payload.<br clear="none"> This component uses standard
JNDI (<code>javax.naming</code> package) to access the server.</p><p>Maven
users will need to add the following dependency to their <code>pom.xml</code>
for this component:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;dependency&gt;
     &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
     &lt;artifactId&gt;camel-ldap&lt;/artifactId&gt;
     &lt;version&gt;x.x.x&lt;/version&gt;
     &lt;!-- use the same version as your Camel core version --&gt;
 &lt;/dependency&gt;
 ]]></script>
-</div></div>
-
-<h3 id="LDAP-URIformat">URI format</h3>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
-<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
-ldap:ldapServerBean[?options]
+</div></div><h3 id="LDAP-URIformat">URI format</h3><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ldap:ldapServerBean[?options]
 ]]></script>
-</div></div>
-
-<p>The <em>ldapServerBean</em> portion of the URI refers to a <a shape="rect"
class="external-link" href="http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html"
rel="nofollow">DirContext</a> bean in the registry. The LDAP component only supports
producer endpoints, which means that an <code>ldap</code> URI cannot appear in
the <code>from</code> at the start of a route.</p>
-
-<p>You can append query options to the URI in the following format, <code>?option=value&amp;option=value&amp;...</code></p>
-
-<h3 id="LDAP-Options">Options</h3>
-<div class="confluenceTableSmall">
-<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p> Name </p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p> Default Value </p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>base</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>ou=system</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The
base DN for searches. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>scope</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>subtree</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Specifies
how deeply to search the tree of entries, starting at the base DN.  Value can be <code>object</code>,
<code>onelevel</code>, or <code>subtree</code>. </p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"
 ><p>pageSize </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>
no paging used </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>
<strong>Camel 2.6:</strong> 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)   </p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>returnedAttributes</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> depends on LDAP Server (could be
all or none) </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>
<strong>Camel 2.6:</strong> Comma-separated list of attributes that should be
set in each entry of the result </p></td></tr></tbody></table></div>
-</div>
-
-<h3 id="LDAP-Result">Result</h3>
-<p>The result is returned in the Out body as a <code>ArrayList&lt;javax.naming.directory.SearchResult&gt;</code>
object. </p>
-
-<h3 id="LDAP-DirContext">DirContext</h3>
-
-<p>The URI, <code>ldap:ldapserver</code>, references a Spring bean with
the ID, <code>ldapserver</code>. The <code>ldapserver</code> bean
may be defined as follows:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
-<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
-&lt;bean id=&quot;ldapserver&quot; class=&quot;javax.naming.directory.InitialDirContext&quot;
scope=&quot;prototype&quot;&gt;
+</div></div><p>The <em>ldapServerBean</em> portion of the URI
refers to a <a shape="rect" class="external-link" href="http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html"
rel="nofollow">DirContext</a> bean in the registry. The LDAP component only supports
producer endpoints, which means that an <code>ldap</code> URI cannot appear in
the <code>from</code> at the start of a route.</p><p>You can append
query options to the URI in the following format, <code>?option=value&amp;option=value&amp;...</code></p><h3
id="LDAP-Options">Options</h3><div class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p>Default Value</p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>base</code></p></td><td
colspan="1" rowspan="1" cl
 ass="confluenceTd"><p><code>ou=system</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The base DN for searches.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>scope</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>subtree</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Specifies how deeply to search the
tree of entries, starting at the base DN. Value can be <code>object</code>, <code>onelevel</code>,
or <code>subtree</code>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>pageSize</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>no paging used</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.6:</strong> 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 b
 e passed in as ldapServerBean (otherwise an exception is thrown)</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>returnedAttributes</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>depends on LDAP Server (could be
all or none)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.6:</strong> Comma-separated list of attributes that should be set in each entry of
the result</p></td></tr></tbody></table></div></div><h3
id="LDAP-Result">Result</h3><p>The result is returned in the Out body as a
<code>ArrayList&lt;javax.naming.directory.SearchResult&gt;</code> object.</p><h3
id="LDAP-DirContext">DirContext</h3><p>The URI, <code>ldap:ldapserver</code>,
references a Spring bean with the ID, <code>ldapserver</code>. The <code>ldapserver</code>
bean may be defined as follows:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;bean
id=&quot;ldapserver&quot; class=&quot;javax.naming.directory.InitialDirContext&quot;
scope=&quot;prototype&quot;&gt;
   &lt;constructor-arg&gt;
     &lt;props&gt;
       &lt;prop key=&quot;java.naming.factory.initial&quot;&gt;com.sun.jndi.ldap.LdapCtxFactory&lt;/prop&gt;
@@ -138,26 +107,14 @@ ldap:ldapServerBean[?options]
   &lt;/constructor-arg&gt;
 &lt;/bean&gt;
 ]]></script>
-</div></div>
-
-<p>The preceding example declares a regular Sun based LDAP <code>DirContext</code>
that connects anonymously to a locally hosted LDAP server.</p>
-
-    <div class="aui-message warning shadowed information-macro">
+</div></div><p>The preceding example declares a regular Sun based LDAP
<code>DirContext</code> that connects anonymously to a locally hosted LDAP server.</p>
   <div class="aui-message warning shadowed information-macro">
                             <span class="aui-icon icon-warning">Icon</span>
                 <div class="message-content">
-                            
-<p><code>DirContext</code> objects are <strong>not</strong>
required to support concurrency by contract. It is therefore important that the directory
context is declared with the setting, <code>scope="prototype"</code>, in the <code>bean</code>
definition or that the context supports concurrency. In the Spring framework, <code>prototype</code>
scoped objects are instantiated each time they are looked up.</p>
+                            <p><code>DirContext</code> objects are <strong>not</strong>
required to support concurrency by contract. It is therefore important that the directory
context is declared with the setting, <code>scope="prototype"</code>, in the <code>bean</code>
definition or that the context supports concurrency. In the Spring framework, <code>prototype</code>
scoped objects are instantiated each time they are looked up.</p>
                     </div>
     </div>
-
-
-<h3 id="LDAP-Samples">Samples</h3>
-
-<p>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.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
-<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
-ProducerTemplate&lt;Exchange&gt; template = exchange
+<h3 id="LDAP-Samples">Samples</h3><p>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.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ProducerTemplate&lt;Exchange&gt;
template = exchange
   .getContext().createProducerTemplate();
 
 Collection&lt;?&gt; results = (Collection&lt;?&gt;) (template
@@ -178,22 +135,11 @@ if (results.size() &gt; 0) {
 
   ...
 ]]></script>
-</div></div>
-
-<p>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:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
-<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
-(cn=*)
+</div></div><p>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:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[(cn=*)
 ]]></script>
-</div></div>
-
-<h4 id="LDAP-Bindingusingcredentials">Binding using credentials</h4>
-
-<p>A Camel end user donated this sample code he used to bind to the ldap server using
credentials.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
-<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
-Properties props = new Properties();
+</div></div><h4 id="LDAP-Bindingusingcredentials">Binding using credentials</h4><p>A
Camel end user donated this sample code he used to bind to the ldap server using credentials.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[Properties
props = new Properties();
 props.setProperty(Context.INITIAL_CONTEXT_FACTORY, &quot;com.sun.jndi.ldap.LdapCtxFactory&quot;);
 props.setProperty(Context.PROVIDER_URL, &quot;ldap://localhost:389&quot;);
 props.setProperty(Context.URL_PKG_PREFIXES, &quot;com.sun.jndi.url&quot;);
@@ -230,9 +176,131 @@ System.out.println(out.getOut().getBody(
 
 context.stop();
 ]]></script>
-</div></div>
+</div></div><h3 id="LDAP-ConfiguringSSL">Configuring SSL</h3><p>All
required is to create a custom socket factory and reference it in the InitialDirContext bean
- see below sample.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>SSL Configuration</b></div><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;?xml
version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+&lt;blueprint xmlns=&quot;http://www.osgi.org/xmlns/blueprint/v1.0.0&quot;
+           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
+           xsi:schemaLocation=&quot;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&quot;&gt;
+
+
+    &lt;sslContextParameters xmlns=&quot;http://camel.apache.org/schema/blueprint&quot;
+                          id=&quot;sslContextParameters&quot;&gt;
+        &lt;keyManagers
+                keyPassword=&quot;{{keystore.pwd}}&quot;&gt;
+            &lt;keyStore
+                    resource=&quot;{{keystore.url}}&quot;
+                    password=&quot;{{keystore.pwd}}&quot;/&gt;
+        &lt;/keyManagers&gt;
+    &lt;/sslContextParameters&gt;
+
+    &lt;bean id=&quot;customSocketFactory&quot; class=&quot;zotix.co.util.CustomSocketFactory&quot;&gt;
+        &lt;argument ref=&quot;sslContextParameters&quot; /&gt;
+    &lt;/bean&gt;
+    &lt;bean id=&quot;ldapserver&quot; class=&quot;javax.naming.directory.InitialDirContext&quot;
scope=&quot;prototype&quot;&gt;
+        &lt;argument&gt;
+            &lt;props&gt;
+                &lt;prop key=&quot;java.naming.factory.initial&quot; value=&quot;com.sun.jndi.ldap.LdapCtxFactory&quot;/&gt;
+                &lt;prop key=&quot;java.naming.provider.url&quot; value=&quot;ldaps://lab.zotix.co:636&quot;/&gt;
+                &lt;prop key=&quot;java.naming.security.protocol&quot; value=&quot;ssl&quot;/&gt;
+                &lt;prop key=&quot;java.naming.security.authentication&quot;
value=&quot;simple&quot; /&gt;
+                &lt;prop key=&quot;java.naming.security.principal&quot; value=&quot;cn=Manager,dc=example,dc=com&quot;/&gt;
+                &lt;prop key=&quot;java.naming.security.credentials&quot; value=&quot;passw0rd&quot;/&gt;
+                &lt;prop key=&quot;java.naming.ldap.factory.socket&quot;
+                      value=&quot;zotix.co.util.CustomSocketFactory&quot;/&gt;
+            &lt;/props&gt;
+        &lt;/argument&gt;
+    &lt;/bean&gt;
+&lt;/blueprint&gt;]]></script>
+</div></div><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Custom Socket
Factory</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[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() {
 
-<h3 id="LDAP-SeeAlso">See Also</h3>
+    }
+
+    /**
+     * 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(&quot;SunX509&quot;);
+            tmf.init(keyStore);
+            SSLContext ctx = SSLContext.getInstance(&quot;TLS&quot;);
+            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);
+    }
+}]]></script>
+</div></div><p>&#160;</p><p></p><h3 id="LDAP-SeeAlso">See
Also</h3>
 <ul><li><a shape="rect" href="configuring-camel.html">Configuring Camel</a></li><li><a
shape="rect" href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect" href="getting-started.html">Getting
Started</a></li></ul></div>
         </td>
         <td valign="top">



Mime
View raw message