Commit af0bdc89 authored by Stephane Nicoll's avatar Stephane Nicoll

Add support for anonymousReadOnly in LdapProperties

See gh-11744
parent 633aefa8
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
...@@ -58,6 +58,7 @@ public class LdapAutoConfiguration { ...@@ -58,6 +58,7 @@ public class LdapAutoConfiguration {
source.setUrls(this.properties.determineUrls(this.environment)); source.setUrls(this.properties.determineUrls(this.environment));
source.setBaseEnvironmentProperties( source.setBaseEnvironmentProperties(
Collections.unmodifiableMap(this.properties.getBaseEnvironment())); Collections.unmodifiableMap(this.properties.getBaseEnvironment()));
source.setAnonymousReadOnly(this.properties.getAnonymousReadOnly());
return source; return source;
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
...@@ -60,6 +60,11 @@ public class LdapProperties { ...@@ -60,6 +60,11 @@ public class LdapProperties {
*/ */
private Map<String, String> baseEnvironment = new HashMap<>(); private Map<String, String> baseEnvironment = new HashMap<>();
/**
* Whether read-only operations should use an anonymous environment.
*/
private boolean anonymousReadOnly;
public String[] getUrls() { public String[] getUrls() {
return this.urls; return this.urls;
} }
...@@ -100,6 +105,14 @@ public class LdapProperties { ...@@ -100,6 +105,14 @@ public class LdapProperties {
this.baseEnvironment = baseEnvironment; this.baseEnvironment = baseEnvironment;
} }
public boolean getAnonymousReadOnly() {
return this.anonymousReadOnly;
}
public void setAnonymousReadOnly(boolean anonymousReadOnly) {
this.anonymousReadOnly = anonymousReadOnly;
}
public String[] determineUrls(Environment environment) { public String[] determineUrls(Environment environment) {
if (ObjectUtils.isEmpty(this.urls)) { if (ObjectUtils.isEmpty(this.urls)) {
return new String[] { "ldap://localhost:" + determinePort(environment) }; return new String[] { "ldap://localhost:" + determinePort(environment) };
......
...@@ -89,4 +89,13 @@ public class LdapAutoConfigurationTests { ...@@ -89,4 +89,13 @@ public class LdapAutoConfigurationTests {
}); });
} }
@Test
public void testContextSourceWithDefaultAnonymousReadOnly() {
this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:123")
.run(context -> {
LdapContextSource contextSource = context.getBean(LdapContextSource.class);
assertThat(contextSource.isAnonymousReadOnly()).isFalse();
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment