directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Seelmann <>
Subject Re: ApplyLdifs
Date Sat, 17 Sep 2011 09:41:02 GMT
See inline

On Sat, Sep 17, 2011 at 12:57 AM, Jonathan Carlson <> 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:

> @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 ="", "(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:

You can find more examples within the tests:

Kind Regards,

View raw message