Skip to content

Commit 00d61a0

Browse files
committed
Enum for referral field in LdapProperties.java
Signed-off-by: Andras, Dobrosi <dobrosi@gmail.com>
1 parent 62aecfd commit 00d61a0

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package org.springframework.boot.autoconfigure.ldap;
1818

1919
import java.util.Collections;
20+
import java.util.Optional;
2021

2122
import org.springframework.beans.factory.ObjectProvider;
2223
import org.springframework.boot.autoconfigure.AutoConfiguration;
2324
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2425
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
27+
import org.springframework.boot.autoconfigure.ldap.LdapProperties.Referral;
2628
import org.springframework.boot.autoconfigure.ldap.LdapProperties.Template;
2729
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2830
import org.springframework.boot.context.properties.PropertyMapper;
@@ -67,7 +69,7 @@ public LdapContextSource ldapContextSource(LdapConnectionDetails connectionDetai
6769
propertyMapper.from(connectionDetails.getUsername()).to(source::setUserDn);
6870
propertyMapper.from(connectionDetails.getPassword()).to(source::setPassword);
6971
propertyMapper.from(properties.getAnonymousReadOnly()).to(source::setAnonymousReadOnly);
70-
propertyMapper.from(properties.getReferral()).to(source::setReferral);
72+
Optional.ofNullable(properties.getReferral()).map(Referral::getMode).ifPresent(source::setReferral);
7173
propertyMapper.from(connectionDetails.getBase()).to(source::setBase);
7274
propertyMapper.from(connectionDetails.getUrls()).to(source::setUrls);
7375
propertyMapper.from(properties.getBaseEnvironment())

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapProperties.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.boot.context.properties.ConfigurationProperties;
2323
import org.springframework.core.env.Environment;
24+
import org.springframework.ldap.ReferralException;
2425
import org.springframework.ldap.core.LdapTemplate;
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.ObjectUtils;
@@ -65,7 +66,7 @@ public class LdapProperties {
6566
/**
6667
* Set the method to handle referrals.
6768
*/
68-
private String referral;
69+
private Referral referral;
6970

7071
/**
7172
* LDAP specification settings.
@@ -114,11 +115,11 @@ public void setAnonymousReadOnly(Boolean anonymousReadOnly) {
114115
this.anonymousReadOnly = anonymousReadOnly;
115116
}
116117

117-
public String getReferral() {
118+
public Referral getReferral() {
118119
return this.referral;
119120
}
120121

121-
public void setReferral(String referral) {
122+
public void setReferral(Referral referral) {
122123
this.referral = referral;
123124
}
124125

@@ -195,4 +196,36 @@ public void setIgnoreSizeLimitExceededException(Boolean ignoreSizeLimitExceededE
195196

196197
}
197198

199+
/**
200+
* Enum to define how referrals encountered by the service provider are to be processed.
201+
*/
202+
public enum Referral {
203+
204+
/**
205+
* follow referrals automatically
206+
*/
207+
FOLLOW("follow"),
208+
209+
/**
210+
* ignore referrals
211+
*/
212+
IGNORE("ignore"),
213+
214+
/**
215+
* throw a {@link ReferralException} for each referral
216+
*/
217+
THROW("throw");
218+
219+
private final String mode;
220+
221+
Referral(String mode) {
222+
this.mode = mode;
223+
}
224+
225+
public String getMode() {
226+
return this.mode;
227+
}
228+
229+
}
230+
198231
}

0 commit comments

Comments
 (0)