|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -22,7 +22,7 @@ import com.unboundid.ldap.sdk.DN;
|
|
|
|
import com.unboundid.ldap.sdk.LDAPConnection;
|
|
|
|
import com.unboundid.ldap.sdk.LDAPConnection;
|
|
|
|
import com.unboundid.ldap.sdk.LDAPException;
|
|
|
|
import com.unboundid.ldap.sdk.LDAPException;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
@ -38,7 +38,6 @@ import org.springframework.ldap.core.LdapTemplate;
|
|
|
|
import org.springframework.ldap.core.support.LdapContextSource;
|
|
|
|
import org.springframework.ldap.core.support.LdapContextSource;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link EmbeddedLdapAutoConfiguration}
|
|
|
|
* Tests for {@link EmbeddedLdapAutoConfiguration}
|
|
|
@ -47,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class EmbeddedLdapAutoConfigurationTests {
|
|
|
|
class EmbeddedLdapAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
.withConfiguration(AutoConfigurations.of(EmbeddedLdapAutoConfiguration.class));
|
|
|
|
.withConfiguration(AutoConfigurations.of(EmbeddedLdapAutoConfiguration.class));
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -151,38 +150,32 @@ class EmbeddedLdapAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testLdapContextSourceWithCredentials() {
|
|
|
|
void ldapContextSourceWithCredentialsIsCreated() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org",
|
|
|
|
this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org",
|
|
|
|
"spring.ldap.embedded.credential.username:uid=root", "spring.ldap.embedded.credential.password:boot")
|
|
|
|
"spring.ldap.embedded.credential.username:uid=root", "spring.ldap.embedded.credential.password:boot")
|
|
|
|
.run(context -> {
|
|
|
|
.run(context -> {
|
|
|
|
LdapContextSource ldapContextSource = context.getBean(LdapContextSource.class);
|
|
|
|
LdapContextSource ldapContextSource = context.getBean(LdapContextSource.class);
|
|
|
|
assertThat(ldapContextSource.getUserDn()).isEqualTo("uid=root");
|
|
|
|
assertThat(ldapContextSource.getUrls()).isNotEmpty();
|
|
|
|
assertThat(ldapContextSource.getUrls()).isNotEmpty();
|
|
|
|
assertThat(ldapContextSource.getUserDn()).isEqualTo("uid=root");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testLdapContextSourceWithoutCredentials() {
|
|
|
|
void ldapContextSourceWithoutCredentialsIsCreated() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org")
|
|
|
|
this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org").run(context -> {
|
|
|
|
.run(context -> {
|
|
|
|
|
|
|
|
LdapContextSource ldapContextSource = context.getBean(LdapContextSource.class);
|
|
|
|
LdapContextSource ldapContextSource = context.getBean(LdapContextSource.class);
|
|
|
|
assertThat(ldapContextSource.getUserDn()).isEmpty();
|
|
|
|
|
|
|
|
assertThat(ldapContextSource.getUrls()).isNotEmpty();
|
|
|
|
assertThat(ldapContextSource.getUrls()).isNotEmpty();
|
|
|
|
|
|
|
|
assertThat(ldapContextSource.getUserDn()).isEmpty();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testNoLdapContextSourceWithoutContextSourceClass() {
|
|
|
|
void ldapContextWithoutSpringLdapIsNotCreated() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org")
|
|
|
|
.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org")
|
|
|
|
.withClassLoader(new FilteredClassLoader(ContextSource.class)).run(context -> {
|
|
|
|
.withClassLoader(new FilteredClassLoader(ContextSource.class))
|
|
|
|
assertThat(context).hasNotFailed();
|
|
|
|
.run(context -> {
|
|
|
|
assertThat(context).doesNotHaveBean(LdapContextSource.class);
|
|
|
|
NoSuchBeanDefinitionException expectedException =
|
|
|
|
});
|
|
|
|
new NoSuchBeanDefinitionException(LdapContextSource.class);
|
|
|
|
|
|
|
|
assertThatThrownBy(()-> context.getBean(LdapContextSource.class))
|
|
|
|
|
|
|
|
.isInstanceOf(expectedException.getClass())
|
|
|
|
|
|
|
|
.hasMessage(expectedException.getMessage());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|