Merge pull request #44850 from dobrosi
* pr/44850: Polish "Add support for configuring LDAP's referral property" Add support for configuring LDAP's referral property Closes gh-44850
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.autoconfigure.ldap;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
@@ -67,6 +68,9 @@ public class LdapAutoConfiguration {
|
||||
propertyMapper.from(connectionDetails.getUsername()).to(source::setUserDn);
|
||||
propertyMapper.from(connectionDetails.getPassword()).to(source::setPassword);
|
||||
propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly);
|
||||
propertyMapper.from(properties.getReferral())
|
||||
.as(((referral) -> referral.name().toLowerCase(Locale.ROOT)))
|
||||
.to(source::setReferral);
|
||||
propertyMapper.from(connectionDetails.getBase()).to(source::setBase);
|
||||
propertyMapper.from(connectionDetails.getUrls()).to(source::setUrls);
|
||||
propertyMapper.from(properties.getBaseEnvironment())
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.ldap.ReferralException;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -62,6 +63,12 @@ public class LdapProperties {
|
||||
*/
|
||||
private Boolean anonymousReadOnly;
|
||||
|
||||
/**
|
||||
* Specify how referrals encountered by the service provider are to be processed. If
|
||||
* not specified, the default is determined by the provider.
|
||||
*/
|
||||
private Referral referral;
|
||||
|
||||
/**
|
||||
* LDAP specification settings.
|
||||
*/
|
||||
@@ -109,6 +116,14 @@ public class LdapProperties {
|
||||
this.anonymousReadOnly = anonymousReadOnly;
|
||||
}
|
||||
|
||||
public Referral getReferral() {
|
||||
return this.referral;
|
||||
}
|
||||
|
||||
public void setReferral(Referral referral) {
|
||||
this.referral = referral;
|
||||
}
|
||||
|
||||
public Map<String, String> getBaseEnvironment() {
|
||||
return this.baseEnvironment;
|
||||
}
|
||||
@@ -182,4 +197,26 @@ public class LdapProperties {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the methods to handle referrals.
|
||||
*/
|
||||
public enum Referral {
|
||||
|
||||
/**
|
||||
* Follow referrals automatically.
|
||||
*/
|
||||
FOLLOW,
|
||||
|
||||
/**
|
||||
* Ignore referrals.
|
||||
*/
|
||||
IGNORE,
|
||||
|
||||
/**
|
||||
* Throw {@link ReferralException} when a referral is encountered.
|
||||
*/
|
||||
THROW
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,6 +88,14 @@ class LdapAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextSourceWithReferral() {
|
||||
this.contextRunner.withPropertyValues("spring.ldap.referral:ignore").run((context) -> {
|
||||
LdapContextSource contextSource = context.getBean(LdapContextSource.class);
|
||||
assertThat(contextSource).hasFieldOrPropertyWithValue("referral", "ignore");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextSourceWithExtraCustomization() {
|
||||
this.contextRunner
|
||||
|
||||
Reference in New Issue
Block a user