See inline On Sat, Sep 17, 2011 at 12:57 AM, Jonathan Carlson <[email protected]> wrote: > Thanks so much Stefan for taking the time to make that example. I just > didn't notice the formatting change in the example code I was looking at. > > Is there an example of creating a small hierarchy? I've tried something like > this but got an error saying there was no partition for dc=example,dc=com
You need to create a partition for "dc=example,dc=com" first. You can do that in the @CreateDS annotation. Here is an example: http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java > @ApplyLdifs({ > "dn: dc=example,dc=com", > "objectClass: dcObject", > "dn: ou=users,dc=example,dc=com", > "objectClass: organizationalUnit", > "ou: users\n", > "dn: cn=jon,ou=users,dc=example,dc=com", > "objectClass: person", > "cn: jon", > "sn: Carlson" > }) > > Also, is there an example of doing a lookup on a directory created this way > using an InitialContext? The LDAP client framework that I am testing uses > this method of lookup so it needs to support it. > > // Create a environment container > Hashtable<Object, Object> env = new Hashtable<Object, Object>(); > env.put(Context.PROVIDER_URL, "ldap://localhost:1024"); > env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); > env.put(Context.SECURITY_CREDENTIALS, "secret"); > env.put(Context.SECURITY_AUTHENTICATION, "simple"); > env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); > InitialContext initialContext = new InitialContext(env); > DirContext appRoot = (DirContext) initialContext.lookup(""); > SearchControls controls = new SearchControls(); > controls.setSearchScope(SearchControls.SUBTREE_SCOPE); > controls.setTimeLimit(30000); > NamingEnumeration<SearchResult> results = appRoot.search("", "(cn=jon)", > controls); Yes, that is possible. But be aware that the port you use is variable. I found an example that shows how to obtain the port here: http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/server-integ/src/test/java/org/apache/directory/server/ssl/LdapsIT.java You can find more examples within the tests: http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/test-framework http://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.7/server-integ Kind Regards, Stefan
