diff --git a/core/src/test/java/org/acegisecurity/ldap/LdapServerManager.java b/core/src/test/java/org/acegisecurity/ldap/LdapServerManager.java index d6d4b21633..aebd5b0c73 100644 --- a/core/src/test/java/org/acegisecurity/ldap/LdapServerManager.java +++ b/core/src/test/java/org/acegisecurity/ldap/LdapServerManager.java @@ -35,9 +35,11 @@ import org.apache.directory.server.jndi.ServerContextFactory; import org.apache.directory.server.protocol.shared.store.LdifFileLoader; import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.support.DefaultDirObjectFactory; +import org.springframework.core.io.Resource; /** @@ -47,10 +49,11 @@ import org.springframework.ldap.core.support.DefaultDirObjectFactory; * @author Luke Taylor (borrowed from Spring Ldap project). * */ -public class LdapServerManager implements DisposableBean { +public class LdapServerManager implements DisposableBean, InitializingBean { private static Log log = LogFactory.getLog(LdapServerManager.class); private ContextSource contextSource; + private Resource ldifFile; public void setContextSource(ContextSource contextSource) { this.contextSource = contextSource; @@ -70,6 +73,17 @@ public class LdapServerManager implements DisposableBean { new InitialContext(env); } + + public void afterPropertiesSet() throws Exception { + if (ldifFile != null) { + cleanAndSetup(ldifFile.getFile().getAbsolutePath()); + } + } + + public void setLdifFile(Resource ldifFile) { + this.ldifFile = ldifFile; + } + public void cleanAndSetup(String ldifFile) throws Exception { DirContext ctx = contextSource.getReadWriteContext();