directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiran Ayyagari <kayyag...@apache.org>
Subject Re: Embedded Apache DS as proxy
Date Thu, 25 Sep 2014 17:15:04 GMT
I didn't find anything wrong with the below given code (I tested with
"ou=system" partition)

I believe you included your custom interceptor in the below code while
running, if that is the case
then I need to see your custom interceptor's code as well to figure out
what is causing the below
mentioned error

On Tue, Sep 23, 2014 at 6:23 PM, Sebastian Oerding <
sebastian.oerding@robotron.de> wrote:

>  Hello,
>
> Am 22.09.2014 17:13, schrieb Kiran Ayyagari:
>
>
>
>  hard to tell without seeing your code, but this issue is not related to
> instance layout.
>
>
> hier is a shortened version of the code (together with JUnit test) which
> results in the previously mentioned error:
>
> package ldap;
>
> import java.util.Hashtable;
>
> import javax.naming.Context;
> import javax.naming.NamingEnumeration;
> import javax.naming.NamingException;
> import javax.naming.directory.SearchControls;
> import javax.naming.directory.SearchResult;
> import javax.naming.ldap.InitialLdapContext;
> import javax.naming.ldap.LdapContext;
>
> import org.apache.directory.server.core.api.DirectoryService;
> import org.apache.directory.server.core.api.InstanceLayout;
> import
> org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
> import org.apache.directory.server.ldap.LdapServer;
> import org.apache.directory.server.protocol.shared.transport.TcpTransport;
>
> public class Test {
>
>     /**
>      * Provokes an error with unknown source.
>      *
>      * @throws Exception
>      */
>     @org.junit.Test
>     public void provokeError() throws Exception {
>         EmbeddedServer els = null;
>         try {
>             els = new EmbeddedServer("localhost", 10489);
>             els.start();
>             LdapContext ctx = initContext("ldap://localhost:10489",
> "userCertificate");
>
>             searchCertificate(ctx, "ou=certificates,dc=smpki",
>                 SearchControls.SUBTREE_SCOPE,
> "033E07C49E8AF56994859466BEBFAA9057A36924");
>         } finally {
>             if (els != null) {
>                 els.stop();
>             }
>         }
>     }
>
>     private LdapContext initContext(String ldapServer, String
> attributeName) throws NamingException {
>
>         Hashtable<String, Object> env = new Hashtable<String, Object>();
>         env.put(Context.SECURITY_AUTHENTICATION, "simple");
>         env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
>         env.put(Context.SECURITY_CREDENTIALS, "secret");
>         env.put(Context.INITIAL_CONTEXT_FACTORY,
> "com.sun.jndi.ldap.LdapCtxFactory");
>         env.put(Context.PROVIDER_URL, ldapServer);
>
>         return new InitialLdapContext(env, null);
>     }
>
>     private NamingEnumeration<SearchResult> searchCertificate(LdapContext
> ctx, String searchBase, int searchScope,
>         String subjectKeyIdentifier) throws NamingException {
>
>         SearchControls searchControls = new SearchControls();
>         searchControls.setSearchScope(searchScope);
>
>         String searchFilter = "(&(objectClass=smpki)(cn=" +
> subjectKeyIdentifier + "))";
>
>         return ctx.search(searchBase, searchFilter, searchControls);
>     }
>
>     private static final class EmbeddedServer {
>         private DirectoryService directoryService;
>         private LdapServer ldapService;
>
>         public EmbeddedServer(final String host, final int port) throws
> Exception {
>             init(host, port);
>         }
>
>         private void init(final String host, final int port) throws
> Exception {
>
>             DefaultDirectoryServiceFactory factory = new
> DefaultDirectoryServiceFactory();
>             factory.init("Test");
>             this.directoryService = factory.getDirectoryService();
>             this.directoryService.getChangeLog().setEnabled(false);
>             this.directoryService.setShutdownHookEnabled(true);
>             this.directoryService.setInstanceLayout(new
> InstanceLayout("/tmp/ldapServer"));
>
>             this.ldapService = new LdapServer();
>             this.ldapService.setTransports(new TcpTransport(host, port));
>             this.ldapService.setDirectoryService(this.directoryService);
>         }
>
>         public void start() throws Exception {
>
>             this.directoryService.startup();
>             this.ldapService.start();
>         }
>
>         public void stop() throws Exception {
>
>             this.ldapService.stop();
>             this.directoryService.shutdown();
>         }
>     }
> }
>
> I'm using Apache DS 2.0.0-M17 on Windows 7 Professional 64bit, Eclipse
> 4.2, JDK 1.6.0_43 (64 bit)
>



-- 
Kiran Ayyagari
http://keydap.com

Mime
View raw message