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) ... doable 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.AddOperationContext;

import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;

import org.apache.directory.server.core.normalization.NormalizationInterceptor;

 

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 values

     * 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 = 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.SearchOperationContext;

 

/**

*

* @author agrosse

*/

public class ProxyClient {

        DirContext ctx = null;

       

        NamingEnumeration results = null;

   

    public void connect() throws NamingException {   

            

        Properties p = new Properties();

        p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

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

        p.setProperty(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");

        p.setProperty(Context.SECURITY_CREDENTIALS, "secret");

        p.setProperty(Context.SECURITY_AUTHENTICATION, "simple");

       

                

        

        try {

           ctx = new InitialDirContext(p);

           

             

        } catch (NamingException ne){

            Trace.error( ne);

        } catch (Throwable e) {

            Trace.error( e);

        } finally {

            if (results != null) {

                try {

                    results.close();

                } catch (Exception e) {

                }

            }

            if (ctx != null) {

                try {

                    ctx.close();

                } catch (Exception e) {

               }

            }

        }

   

    

    }

   

    public NamingEnumeration search(SearchOperationContext  opContext) throws NamingException {

           

        

        

        SearchControls controls = (SearchControls) opContext.getRequestControl(null);

           

        return  results = ctx.search(opContext.getScope().toString(), opContext.getFilter().toString(),controls);

    }

   

}

 

 

AXEL GROSSE