So I have an existing config file that configures an org.springframework.ldap.core.ContextSource
.
@Configuration
public class LdapContextConfig {
@Inject
private LdapProperties ldapProperties;
@Bean
public ContextSource contextSource() {
final TransactionAwareContextSourceProxy transactionAwareContextSourceProxy =
new TransactionAwareContextSourceProxy(poolingContextSource());
return transactionAwareContextSourceProxy;
}
@Bean
public PoolingContextSource poolingContextSource() {
final PoolingContextSource poolingContextSource = new MutablePoolingContextSource();
poolingContextSource.setContextSource(ldapContextSource());
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setTestOnBorrow(true); //default false
return poolingContextSource;
}
@Bean
public LdapContextSource ldapContextSource() {
final LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(ldapProperties.getUrl());
ldapContextSource.setBase(ldapProperties.getBase());
ldapContextSource.setUserDn(ldapProperties.getUserDn());
ldapContextSource.setPassword(ldapProperties.getPassword());
return ldapContextSource;
}
}
This uses a custom LdapProperties
class to pull the url, base, userDn, and password from a properties file when the application is deployed.
Now, I am trying to set up an embedded ApacheDS server to use in integration testing.
I have another config file to set up a an ApacheDS DirectoryService
.
@Configuration
public class EmbeddedLdapConfig {
@Bean
public DirectoryService getDirectoryService() throws Exception {
final DirectoryService directoryService = new DefaultDirectoryService();
//other config
return directoryService;
}
}
Now I am looking for a way to map the ApacheDS DirectoryService
to the Spring LdapContextSource
.
I have injected the DirectoryService
into my LdapContextConfig
and created a separate @Bean
for the embedded LdapContextSource
.
@Inject
private DirectoryService directoryService;
@Bean
public LdapContextSource embeddedLdapContextSource() {
final LdapContextSource embeddedLdapContextSource = /*convert DirectoryService to LdapContextSource*/;
return embeddedLdapContextSource;
}
Is it possible to somehow get an LdapContextSource
from an ApacheDS DirectoryService
? If so, how would I go about doing it?