Announcement Announcement Module
No announcement yet.
Is there a tool that allows for pre-populating an LDAP Server Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a tool that allows for pre-populating an LDAP Server

    From issues I've experienced with using Spring-LDAP:

    There's no LdapUnit (like DbUnit) to delete/insert users and roles before running tests. I tried to use the LdapTestServer[1] from Acegi, but no dice.


    Do you have any suggestions for pre-populating an LDAP server? I'm currently using DbUnit for Hibernate/iBATIS and I need something similar when testing LDAP.


  • #2
    One of my coworkers keeps bragging about how wonderful WebObjects is, and how its persistence layer treats ldap like just another database. Your post made me think that perhaps DbUnit could be modified to do ldap as well.

    No help to you at the moment but I thought I'd "share".


    • #3
      I don't know of anything quite like DBUnit for LDAP. However you might want to have a look at ddsteps. DDSteps is a framework for data-driven testing and it includes some functionality for pre-populating LDAP data (from Excel sheets) as well as validating the data after the test has been completed.

      The LDAP populating functionality is just a useful extra feature in the framework; it's a very powerful tool for integration and function testing in that it separates the test data from the actual tests.


      • #4
        Another alternative is to look at how the integration tests in Spring LDAP are managed. It's a bit verbose, but if you browse the following files in src/itest/java, you'll see how it's done:


        Basically we start a new in-memory server instance for each test, create a partition in it, and load an LDIF file with test data.

        The handling of the server is perhaps slightly non-intuitive. First, you plug in ApacheDS by setting the initialcontext factory to be the ApacheDS ServerContextFactory. You start a server instance by creating an InitialContext. You shut down the server instance by adding a ShutdownConfiguration to the environment and then creating an InitialContext again.

        Here is an example of shutting down the server:

        public class LdapServerManager implements InitializingBean {
           public void shutdown() throws NamingException {
              Properties env = new Properties();
              ShutdownConfiguration configuration = new ShutdownConfiguration();
              new InitialContext(env);
        We start the server simply by configuring it as a Spring bean:

        <bean name="serverContext" class="javax.naming.InitialContext">
              <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
                 <property name="targetObject" ref="configEnvHelper" />
                 <property name="propertyPath" value="env" />
        <bean id="configEnvHelper" class="org.springframework.ldap.ConfigEnvHelper">
        The configEnvHelper bean sets the initialcontext factory, the server working directory, and other configuration properties in afterPropertiesSet:

        public class ConfigEnvHelper implements InitializingBean {
           public void afterPropertiesSet() throws Exception {
              initialEnv.put(Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName());
        Admittedly, it's convoluted, but it enables repeatable integration tests towards a real LDAP server without the hassles of installing and maintaining a server. Anyone that checks out the source code get this benefit. Just point to the src/itest/java source folder and run it as a JUnit test.