Pruebas de integración con spring-security y ldap.
Spring ldap server embebido en pruebas unitarias Es similar, sin embargo no me dieron respuesta que me suites.
Puedo ejecutar mis pruebas de integración con Spring y el servidor de LDAP integrado de Spring-Security sin ningún problema. Sin embargo, todavía no he encontrado una manera de borrar el servidor ldap incorporado y cargar el ldif nuevamente para proporcionar un entorno de prueba común.
LdapTestUtils de spring-ldap proporciona un método cleanAndSetup (). Sin embargo, esto no funciona con la versión sugerida (1.5.5) de apache-ds, ya que LdifFileLoader ahora requiere unaCoreSession en vez deDirContext proporcionado por LdapTestUtils. Esto causa una
java.lang.NoSuchMethodError:
org.apache.directory.server.protocol.shared.store.LdifFileLoader.<init>(Ljavax/naming/directory/DirContext;Ljava/lang/String;)
Solo quiero un método que borre el servidor ldap incorporado y lo llene nuevamente con el archivo ldif (como se hizo en el inicio). ¿Alguien tiene una idea al respecto?
Versión: spring 3.1, spring-ldap 1.3, spring-security 3.1, apache-ds 1.5.5
Solución (Gracias a Luke Taylor):
@Inject
private ApplicationContext applicationContext;
@Before
public void reloadLdapDirectory() throws NamingException, IOException{
ApacheDSContainer apacheDSContainer = (ApacheDSContainer) applicationContext.getBean(BeanIds.EMBEDDED_APACHE_DS);
LdapTestUtils.clearSubContexts(contextSource, DistinguishedName.EMPTY_PATH);
ClassPathResource classPathResource = new ClassPathResource("ldap.ldif");
File tempFile = File.createTempFile("spring_ldap_test", ".ldif");
try {
InputStream inputStream = classPathResource.getInputStream();
IOUtils.copy(inputStream, new FileOutputStream(tempFile));
LdifFileLoader fileLoader = new LdifFileLoader(apacheDSContainer.getService().getAdminSession(), tempFile.getAbsolutePath());
fileLoader.execute();
}
finally {
try {
tempFile.delete();
}
catch (Exception e) {
// Ignore this
}
}
}