I'm trying to duplicate a LDAP layout/schema from the field my application has to deal with-and I'm trying to recreate + test it via an automated test with the embeddable UnboundID LDAP server.
The situation it has to deal with is the user schema's 'memberOf' property like Active Directory has...but I'm not quite sure how to add a 'user' class to this ldap in memory.
1) Is this possible? 2) Is there a better strategy? 3) And what in particular should I do? I'm a LDAP newbie.
Below is my nonworking code.
Thanks, Mike Kohout
public class TestOpenLdap2
{
private InMemoryDirectoryServer server;
@Before
public void start() throws Exception
{
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=com");
config.addAdditionalBindCredentials("cn=admin,ou=People,dc=example,dc=com", "cred");
InMemoryListenerConfig listenerConfig = new InMemoryListenerConfig("test", null, 33390, null, null, null);
config.setListenerConfigs(listenerConfig);
server = new InMemoryDirectoryServer(config);
server.startListening();
}
@Test
public void testMemberOf() throws Exception
{
addEntry("dn: dc=com", "objectClass: top", "objectClass: domain", "dc: com");
ObjectClassDefinition oc = new ObjectClassDefinition("10.19.19.78", new String[]{"user"}, "", false, new String[]{"TOP"},
ObjectClassType.STRUCTURAL, new String[]{"memberOf"},
new String[]{}, new HashMap());
addEntry("dn: cn=schema2,dc=com", "objectClass: top", "objectClass: ldapSubEntry", "objectClass: subschema", "cn: schema2",
"objectClasses: " + oc.toString());
addEntry("dn: dc=people,dc=com", "objectClass: top", "objectClass: domain", "dc: people");
addEntry("dn: dc=groups,dc=com", "objectClass: top", "objectClass: domain", "dc: groups");
addEntry("dn: cn=test-group,dc=groups,dc=com", "objectClass: groupOfUniqueNames", "cn: test group");
addEntry("dn: cn=Testy Tester,dc=people,dc=com", "objectClass: Person", "objectClass: user", "objectClass: organizationalPerson", "sn: Tester", "cn: Testy Tester", "memberOf: cn=test-group,dc=groups,dc=com");
}
public void addEntry(String... args) throws LDIFException, LDAPException
{
LDAPResult result = server.add(args);
assert (result.getResultCode().intValue() == 0);
System.out.println("added entry:" + Arrays.asList(args));
}