From dev-return-44285-apmail-directory-dev-archive=directory.apache.org@directory.apache.org Sun Sep 29 00:52:35 2013 Return-Path: X-Original-To: apmail-directory-dev-archive@www.apache.org Delivered-To: apmail-directory-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B113F10B1E for ; Sun, 29 Sep 2013 00:52:35 +0000 (UTC) Received: (qmail 51688 invoked by uid 500); 29 Sep 2013 00:52:35 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 51629 invoked by uid 500); 29 Sep 2013 00:52:34 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Delivered-To: moderator for dev@directory.apache.org Received: (qmail 24081 invoked by uid 99); 28 Sep 2013 23:46:07 -0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) X-WSS-ID: 0MTV0EX-22-1R5-02 X-M-MSG: From: Axel Grosse To: "dev@directory.apache.org" Subject: apacheds interceptor question - how to map NamingEnumeration to EntryFilteringCursor Thread-Topic: apacheds interceptor question - how to map NamingEnumeration to EntryFilteringCursor Thread-Index: Ac68pKM0W3SL/8ciT/y0Lmcc0zp3HA== Date: Sat, 28 Sep 2013 23:44:47 +0000 Message-ID: Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.129.17.6] Content-Type: multipart/alternative; boundary="_000_E8C66D7B548D594AA2D874080BF5BB222D70D9A7WPTXMAIL1ptxaxw_" MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org --_000_E8C66D7B548D594AA2D874080BF5BB222D70D9A7WPTXMAIL1ptxaxw_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi I am developing a LDAP Proxy based on embedded apache directory service ... have set up an embedded Ldap Server wich runs nice against his directory .. but I wont to intercept the search and use an Interceptor to ask a Backend = LDAP Server ... so I need to forward the search in complete (filter,basedn,controls) ... do= able with SearchOperationContext my problem now is the answer type ... normal LDAP Client search get a NamingEnumeration back ... the interceptor class need to return an EntryFilteringCursor does anyone has an idea how to map these two ? thanks for any help Axel code for ProxyInterceptor: import com.vordel.trace.Trace; import java.util.List; import org.apache.directory.api.ldap.model.exception.LdapException; import org.apache.directory.server.core.api.filtering.EntryFilter; import org.apache.directory.server.core.api.filtering.EntryFilteringCursor; import org.apache.directory.server.core.api.interceptor.BaseInterceptor; import org.apache.directory.server.core.api.interceptor.Interceptor; import org.apache.directory.server.core.api.interceptor.context.AddOperatio= nContext; import org.apache.directory.server.core.api.interceptor.context.SearchOpera= tionContext; import org.apache.directory.server.core.normalization.NormalizationIntercep= tor; import com.vordel.dwe.ldap.proxy.ProxyClient; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.NamingEnumeration; import javax.naming.NamingException; /** * * @author agrosse */ public class ProxyInterceptor extends BaseInterceptor{ private static ProxyClient pc; NamingEnumeration resultClient; /** * Intercepts the search operation in order to replace plain password v= alues * with hashed ones. */ @Override public EntryFilteringCursor search( SearchOperationContext opContext) = throws LdapException { try { pc.connect(); } catch (NamingException ex) { Trace.error(ex);; } Trace.debug("Intercation filter touched"); try { //call new backend DS .. todo resultClient =3D pc.search(opContext); } catch ( Exception e){ Trace.error("Error in Interceptor"); } finally { this.getNextInterceptor(opContext); return resultClient; //super.search(opContext) } } } code for ProxyClient: import com.vordel.trace.Trace; import java.util.Properties; import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; import org.apache.directory.server.core.api.interceptor.context.SearchOpera= tionContext; /** * * @author agrosse */ public class ProxyClient { DirContext ctx =3D null; NamingEnumeration results =3D null; public void connect() throws NamingException { Properties p =3D new Properties(); p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.L= dapCtxFactory"); p.setProperty(Context.PROVIDER_URL, "ldap://localhost:389/"); p.setProperty(Context.SECURITY_PRINCIPAL, "uid=3Dadmin,ou=3Dsystem"= ); p.setProperty(Context.SECURITY_CREDENTIALS, "secret"); p.setProperty(Context.SECURITY_AUTHENTICATION, "simple"); try { ctx =3D new InitialDirContext(p); } catch (NamingException ne){ Trace.error( ne); } catch (Throwable e) { Trace.error( e); } finally { if (results !=3D null) { try { results.close(); } catch (Exception e) { } } if (ctx !=3D null) { try { ctx.close(); } catch (Exception e) { } } } } public NamingEnumeration search(SearchOperationContext opContext) thro= ws NamingException { SearchControls controls =3D (SearchControls) opContext.getRequestCo= ntrol(null); return results =3D ctx.search(opContext.getScope().toString(), opC= ontext.getFilter().toString(),controls); } } AXEL GROSSE --_000_E8C66D7B548D594AA2D874080BF5BB222D70D9A7WPTXMAIL1ptxaxw_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi

I am developing a LDAP Proxy ba= sed on embedded apache directory service ...

 

have set up an embedded Ldap Se= rver wich runs nice against his directory ..

 

but I wont to intercept the sea= rch and use an Interceptor to ask a Backend LDAP Server ...

 

so I need to forward the search= in complete (filter,basedn,controls) ... doable with SearchOperationContex= t

 

my problem now is the answer ty= pe

... normal LDAP Client search g= et a NamingEnumeration back

... the interceptor class need = to return an EntryFilteringCursor

 

does anyone has an idea how to = map these two ?

 

thanks for any help<= /span>

 

Axel

 

code for ProxyInterceptor:=

 

import com.vordel.trace.Trace;<= o:p>

import java.util.List;

import org.apache.directory.api= .ldap.model.exception.LdapException;

import org.apache.directory.ser= ver.core.api.filtering.EntryFilter;

import org.apache.directory.ser= ver.core.api.filtering.EntryFilteringCursor;

import org.apache.directory.ser= ver.core.api.interceptor.BaseInterceptor;

import org.apache.directory.ser= ver.core.api.interceptor.Interceptor;

import org.apache.directory.ser= ver.core.api.interceptor.context.AddOperationContext;

import org.apache.directory.ser= ver.core.api.interceptor.context.SearchOperationContext;<= /p>

import org.apache.directory.ser= ver.core.normalization.NormalizationInterceptor;

 

import com.vordel.dwe.ldap.prox= y.ProxyClient;

import java.util.logging.Level;=

import java.util.logging.Logger= ;

import javax.naming.NamingEnume= ration;

import javax.naming.NamingExcep= tion;

 

 

/**

*

* @author agrosse

*/

public class ProxyInterceptor e= xtends BaseInterceptor{

    <= /span>

   private stati= c ProxyClient pc;

   NamingEnumeration = resultClient;

 

 

    /**

     * Inte= rcepts the search operation in order to replace plain password values<= /o:p>

     * with= hashed ones.

     */

    @Override

    public Entry= FilteringCursor search( SearchOperationContext  opContext) throws Ldap= Exception {

     &= nbsp; try {

     &= nbsp;     pc.connect();

     &= nbsp; } catch (NamingException ex) {

     &= nbsp;     Trace.error(ex);;

     &= nbsp; }

     &= nbsp; 

     &= nbsp;  Trace.debug("Intercation filter touched");<= /o:p>

     &= nbsp;  try {

     &= nbsp;  //call new backend DS .. todo

     &= nbsp;   resultClient =3D pc.search(opContext);<= /p>

     &= nbsp;     

     &= nbsp;  

     &= nbsp;  } catch ( Exception e){

     &= nbsp;    Trace.error("Error in Interceptor");=

     &= nbsp;  } finally {

     &= nbsp;

     &= nbsp;   this.getNextInterceptor(opContext);

     &= nbsp;   

     &= nbsp;    

     &= nbsp;    

     &= nbsp;    return resultClient;

     &= nbsp;    //super.search(opContext)

     &= nbsp;  }

    }=

    

}

 

code for ProxyClient:

 

import com.vordel.trace.Trace;<= o:p>

import java.util.Properties;

import javax.naming.Context;

import javax.naming.NamingEnume= ration;

import javax.naming.NamingExcep= tion;

import javax.naming.directory.A= ttribute;

import javax.naming.directory.A= ttributes;

import javax.naming.directory.D= irContext;

import javax.naming.directory.I= nitialDirContext;

import javax.naming.directory.S= earchControls;

import javax.naming.directory.S= earchResult;

import org.apache.directory.ser= ver.core.api.interceptor.context.SearchOperationContext;<= /p>

 

/**

*

* @author agrosse

*/

public class ProxyClient {=

     &= nbsp;  DirContext ctx =3D null;

     &= nbsp; 

     &= nbsp;  NamingEnumeration results =3D null;

    <= /span>

    public = void connect() throws NamingException {   

     &= nbsp;      

     &= nbsp;  Properties p =3D new Properties();

     &= nbsp;  p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jn= di.ldap.LdapCtxFactory");

     &= nbsp;  p.setProperty(Context.PROVIDER_URL, "ldap://localhost:389/= ");

     &= nbsp;  p.setProperty(Context.SECURITY_PRINCIPAL, "uid=3Dadmin,ou= =3Dsystem");

     &= nbsp;  p.setProperty(Context.SECURITY_CREDENTIALS, "secret")= ;

     &= nbsp;  p.setProperty(Context.SECURITY_AUTHENTICATION, "simple&quo= t;);

     &= nbsp; 

     &= nbsp;          

     &= nbsp;  

     &= nbsp;  try {

     &= nbsp;     ctx =3D new InitialDirContext(p);<= /span>

     &= nbsp;     

     &= nbsp;       

     &= nbsp;  } catch (NamingException ne){

     &= nbsp;      Trace.error( ne);

     &= nbsp;  } catch (Throwable e) {

     &= nbsp;      Trace.error( e);

     &= nbsp;  } finally {

     &= nbsp;      if (results !=3D null) {

      =           try {

     &= nbsp;           &nbs= p;  results.close();

     &= nbsp;          } catch (Except= ion e) {

     &= nbsp;          }

     &= nbsp;      }

     &= nbsp;      if (ctx !=3D null) {<= /p>

     &= nbsp;          try {

     &= nbsp;           &nbs= p;  ctx.close();

     &= nbsp;          } catch (Except= ion e) {

     &= nbsp;         }

     &= nbsp;      }

     &= nbsp;  }

    <= /span>

    

    }<= /o:p>

    <= /span>

    public = NamingEnumeration search(SearchOperationContext  opContext) throws Nam= ingException {

     &= nbsp;     

     &= nbsp;  

     &= nbsp;  

     &= nbsp;  SearchControls controls =3D (SearchControls) opContext.get= RequestControl(null);

     &= nbsp;     

     &= nbsp;  return  results =3D ctx.search(opContext.getScope().t= oString(), opContext.getFilter().toString(),controls);

    }=

    <= /span>

}

 

 

AXEL GROSSE

 

--_000_E8C66D7B548D594AA2D874080BF5BB222D70D9A7WPTXMAIL1ptxaxw_--