directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Directory SandBox > Implementing a simple interceptor
Date Sat, 06 Feb 2010 19:58:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/5/_/styles/combined.css?spaceKey=DIRxSBOX&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Implementing
a simple interceptor</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Stefan
     <div class="notificationGreySide">
         <div class='panelMacro'><table class='noteMacro'><colgroup><col
width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif"
width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Be
Careful</b><br /><p>Work in progress. Any feedback highly appreciated!</p></td></tr></table></div>

<h1><a name="Implementingasimpleinterceptor-Implementingasimpleinterceptor"></a>Implementing
a simple interceptor</h1>

<p>The following is for developers who plan to implement their own interceptors in order
to extend or modify the functionality of Apache Directory Server. It contains a simple example
as a starting point.</p>

    <li><a href='#Implementingasimpleinterceptor-Whatexactlyisaninterceptor%3F'>What
exactly is an interceptor?</a></li>
    <li><a href='#Implementingasimpleinterceptor-Passwordhash.Asimpleinterceptor'>Password
hash. A simple interceptor</a></li>
    <li><a href='#Implementingasimpleinterceptor-Thesources'>The sources</a></li>
    <li><a href='#Implementingasimpleinterceptor-ImplementingtheclassPasswordHashInterceptor'>Implementing
the class PasswordHashInterceptor</a></li>
    <li><a href='#Implementingasimpleinterceptor-Usingtheinterceptor'>Using the
    <li><a href='#Implementingasimpleinterceptor-Verification'>Verification</a></li>

<h2><a name="Implementingasimpleinterceptor-Whatexactlyisaninterceptor%3F"></a>What
exactly is an interceptor?</h2>

<p>An interceptor filters method calls performed on on the DefaultPartitionNexus just
like Servlet filters do. The ApacheDS configuration contains a chain of filters performing
several tasks. In order to illustrate this, here is the list of interceptors from the default
server configuration of ApacheDS 1.5.5</p>


<p>Interceptors should usually pass the control of current invocation to the next interceptor
by calling an appropriate method on NextInterceptor.  The flow control is returned when the
next  interceptor's filter method returns. You can therefore implement pre-, post-, around-
invocation handler by how you place the statement.</p>

<p>Interceptors are a powerful way to extend and modify the server behavior. But be
warned. A mistakenly written interceptor may lead to a dis-functional or corrupt server. </p>

<h2><a name="Implementingasimpleinterceptor-Passwordhash.Asimpleinterceptor"></a>Password
hash. A simple interceptor</h2>

<p>In order to demonstrate how to write an interceptor, here is a simple but realistic
example. The following requirement should be fulfilled by an interceptor.</p>

	<li>no user passwords should be stored in clear text in the directory</li>
	<li>If a userpassword is set by an LDAP client in clear text, a message digest algorithm
should be applied to the value, and the one-way encrypted value should be stored</li>
	<li>the algorithm should be applied if new entries are created or existing entries
are modified (hence modify and add operations will be intercepted)</li>
	<li>If the value given by the client is already provided in hashed form, nothing happens</li>

<h3><a name="Implementingasimpleinterceptor-Thesources"></a>The sources</h3>

<p>Currently, the sources are checked in here</p>
	<li><a href=""

<p>In order to build it, simply check it out and type "mvn install". </p>

<h3><a name="Implementingasimpleinterceptor-ImplementingtheclassPasswordHashInterceptor"></a>Implementing
the class PasswordHashInterceptor</h3>

<p>The following UML class diagram depicts the structure of the little example.</p>

<p><img src="/confluence/download/attachments/13271374/passwordHashInterceptor_UML.png"
align="absmiddle" border="0" /></p>

<h3><a name="Implementingasimpleinterceptor-Usingtheinterceptor"></a>Using
the interceptor</h3>

<h4><a name="Implementingasimpleinterceptor-Embeddedmode"></a>Embedded mode</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span>;

<span class="code-keyword">import</span> java.util.List;

<span class="code-keyword">import</span>;
<span class="code-keyword">import</span>;
<span class="code-keyword">import</span>;
<span class="code-keyword">import</span>;
<span class="code-keyword">import</span>;

 * Main class which starts an embedded server with the interceptor added to the
 * chain.
<span class="code-keyword">public</span> class Main {

    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
void main(<span class="code-object">String</span>[] args) <span class="code-keyword">throws</span>
Exception {

        DirectoryService directoryService = <span class="code-keyword">new</span>
        directoryService.setShutdownHookEnabled(<span class="code-keyword">true</span>);

        LdapServer ldapServer = <span class="code-keyword">new</span> LdapServer();
        ldapServer.setAllowAnonymousAccess(<span class="code-keyword">true</span>);

        List&lt;Interceptor&gt; is = directoryService.getInterceptors();
        is.add(<span class="code-keyword">new</span> PasswordHashInterceptor());

        TcpTransport ldapTransport = <span class="code-keyword">new</span> TcpTransport(10389);


<h4><a name="Implementingasimpleinterceptor-Addingittoaserver.xmlfile"></a>Adding
it to a server.xml file</h4>

<h3><a name="Implementingasimpleinterceptor-Verification"></a>Verification</h3>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View

View raw message