directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: apacheds interceptor question - how to map NamingEnumeration to EntryFilteringCursor
Date Sun, 29 Sep 2013 06:24:04 GMT
Hi,

the simple wy to do it is to use teh LDAP API instead of JNDI. JNDI is
by all mean atrocious anyway...

Otherwise, we have a class named NamingEnumerationAdapter which wraps a
EntryFilteringCursor, and this is what you want, I guess :


    public NamingEnumerationAdapter( EntryFilteringCursor cursor )
throws NamingException


Le 9/28/13 4:44 PM, Axel Grosse a écrit :
> 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
>
>


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Mime
View raw message