Skip to content

Instantly share code, notes, and snippets.

@agebhar1
Last active October 12, 2019 14:17
Show Gist options
  • Select an option

  • Save agebhar1/99bbb22c656298b1d6735466649fc132 to your computer and use it in GitHub Desktop.

Select an option

Save agebhar1/99bbb22c656298b1d6735466649fc132 to your computer and use it in GitHub Desktop.
Spring embedded LDAP Server
https://github.com/spring-projects/spring-boot/pull/13502: Add support to set base in EmbeddedLdapAutoConfiguration
declined
https://github.com/spring-projects/spring-boot/issues/12646: embeded ldap autocongiguration bug
Duplicate of #11693.
declined/closed
https://github.com/spring-projects/spring-boot/issues/11693: EmbeddedLdapAutoConfiguration not setting the base information into the LdapContextSource
That's inaccurate. #10443 has been closed as a duplicate of #10444 and the latter has been declined.
closed
https://github.com/spring-projects/spring-boot/issues/10443: Provide ability to set contextSource base through spring.ldap.base property when using embedded LDAP autoconfiguration
closed in favor of #10444
https://github.com/spring-projects/spring-boot/pull/10444: Ldap contextSource base property populating in EmbeddedLdapAutoConfig
This broke Spring Data's integration tests and, looking at the error, this change is way more invasive than I thought. Perhaps you could provide a solution that is opt-in instead?
declined
=> https://github.com/kamkie/spring-ldap-bug/blob/master/src/test/java/com/example/springldapbug/LdapConfigurationWorkaround.java
Caused by: java.lang.IllegalArgumentException: PersistentEntity must not be null!
=> https://stackoverflow.com/questions/47969157/incompatibility-between-spring-ldap-and-spring-data-rest
=> https://jira.spring.io/browse/DATALDAP-60: Enable Spring Data LDAP for Spring Data REST usage
=> https://jira.spring.io/browse/DATAREST-1198: Add Converter to convert String to javax.naming.ldap.LdapName
package com.example.springldapbug;
import org.springframework.boot.autoconfigure.ldap.LdapProperties;
import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.env.Environment;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.util.StringUtils;
@TestConfiguration
@EnableConfigurationProperties({LdapProperties.class, EmbeddedLdapProperties.class})
public class LdapConfigurationWorkaround {
@Bean
@DependsOn("directoryServer")
public ContextSource ldapContextSource(Environment environment,
LdapProperties properties,
EmbeddedLdapProperties embeddedProperties) {
LdapContextSource source = new LdapContextSource();
if (hasCredentials(embeddedProperties.getCredential())) {
source.setUserDn(embeddedProperties.getCredential().getUsername());
source.setPassword(embeddedProperties.getCredential().getPassword());
}
source.setUrls(properties.determineUrls(environment));
source.setBase(embeddedProperties.getBaseDn().get(0));
return source;
}
private boolean hasCredentials(EmbeddedLdapProperties.Credential credential) {
return StringUtils.hasText(credential.getUsername())
&& StringUtils.hasText(credential.getPassword());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment