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
@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);
Thanks so much for your help. Have a great weekend.
- Jon
On Sep 16, 2011, at 5:07 PM, Stefan Seelmann wrote:
Please try to concat the LDIF with commas like this:
@ApplyLdifs(
{
"dn: cn=jon4,ou=system",
"objectClass: person",
"cn: jon4",
"sn: Carlson"
})
Here is a full working example: https://gist.github.com/2dbfa4eb8d0120a3e297
Kind Regards,
Stefan
On Fri, Sep 16, 2011 at 8:49 PM, Jonathan Carlson
<[email protected]<mailto:[email protected]>> wrote:
I'm hoping there is an easy answer to this...
When I specify @ApplyLdifs on the test class it *always* tells me that the dn
exists already, even if it is the first time I've run it.
@ApplyLdifs({
"dn: cn=jon4,ou=system\n" +
"objectClass: person\n" +
"cn: jon4\n" +
"sn: Carlson\n"
})
@RunWith(FrameworkRunner.class)
@CreateLdapServer(
allowAnonymousAccess = true,
transports = { @CreateTransport(protocol = "LDAP") })
org.apache.directory.shared.ldap.exception.LdapEntryAlreadyExistsException:
ERR_250 cn=jon4,ou=system already exists!
Yet, when I move the @ApplyLdifs to a method, the method doesn't get run by
jUnit.
I'm using the Apache DS version 1.5.7 libraries...
Thanks!
jon carlson | codefortytwo software
1 Main St SE, #400 | Minneapolis, MN 55414
Office: 612.333.4242 | web: www.code42.com<http://www.code42.com/>