diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java index 92e52dcb09..07d43eb9d3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java @@ -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()) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java index 2db8c69fcf..8ca76d59ab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java @@ -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 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 + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java index 6bdbb23527..d36350b1f6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfigurationTests.java @@ -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