Adds support for spring-ldap
Resolves #12 Signed-off-by: Emily Casey <ecasey@pivotal.io>
This commit is contained in:
11
README.md
11
README.md
@@ -105,6 +105,17 @@ Disable Property: `org.springframework.cloud.bindings.boot.kafka.enable`
|
||||
| `spring.kafka.producer.bootstrap-servers` | `{secret/producer.bootstrap-servers}`
|
||||
| `spring.kafka.streams.bootstrap-servers` | `{secret/streams.bootstrap-servers}`
|
||||
|
||||
### LDAP
|
||||
Kind: `LDAP`
|
||||
Disable Property: `org.springframework.cloud.bindings.boot.ldap.enable`
|
||||
|
||||
| Property | Value
|
||||
| -------- | ------------------
|
||||
| `spring.ldap.base` | `{secret/base}`
|
||||
| `spring.ldap.password` | `{secret/password}`
|
||||
| `spring.ldap.urls` | `{secret/urls}`
|
||||
| `spring.ldap.username` | `{secret/username}`
|
||||
|
||||
### MongoDB
|
||||
Kind: `MongoDB`
|
||||
Disable Property: `org.springframework.cloud.bindings.boot.mongodb.enable`
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings.boot;
|
||||
|
||||
import org.springframework.cloud.bindings.Binding;
|
||||
import org.springframework.cloud.bindings.Bindings;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
|
||||
*/
|
||||
public final class LDAPBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "LDAP";
|
||||
|
||||
@Override
|
||||
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
|
||||
if (!isKindEnabled(environment, KIND)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bindings.filterBindings(KIND).forEach(binding -> {
|
||||
MapMapper map = new MapMapper(binding.getSecret(), properties);
|
||||
map.from("base").to("spring.ldap.base");
|
||||
map.from("password").to("spring.ldap.password");
|
||||
map.from("urls").to("spring.ldap.urls");
|
||||
map.from("username").to("spring.ldap.username");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
|
||||
org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.EurekaBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.KafkaBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.LDAPBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor, \
|
||||
|
||||
@@ -98,7 +98,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
|
||||
@Test
|
||||
@DisplayName("included implementations are registered")
|
||||
void includedImplementations() {
|
||||
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(16);
|
||||
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(17);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings.boot;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.cloud.bindings.Binding;
|
||||
import org.springframework.cloud.bindings.Bindings;
|
||||
import org.springframework.cloud.bindings.FluentMap;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.boot.LDAPBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("LDAP BindingsPropertiesProcessor")
|
||||
final class LDAPBindingsPropertiesProcessorTest {
|
||||
|
||||
private final Bindings bindings = new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("urls", "test-urls")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("username", "test-username")
|
||||
.withEntry("base", "test-base")
|
||||
)
|
||||
);
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
private final HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes LDAP properties")
|
||||
void testJdbc() {
|
||||
new LDAPBindingsPropertiesProcessor().process(environment, bindings, properties);
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.ldap.urls", "test-urls")
|
||||
.containsEntry("spring.ldap.username", "test-username")
|
||||
.containsEntry("spring.ldap.password", "test-password")
|
||||
.containsEntry("spring.ldap.base", "test-base");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("can be disabled")
|
||||
void disabled() {
|
||||
environment.setProperty("org.springframework.cloud.bindings.boot.ldap.enable", "false");
|
||||
|
||||
new OracleBindingsPropertiesProcessor().process(environment, bindings, properties);
|
||||
|
||||
assertThat(properties).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user