Move LDAP Docker Compose support into spring-boot-ldap
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.boot.docker.compose.service.connection.ldap;
|
||||
|
||||
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
|
||||
import org.springframework.boot.ldap.autoconfigure.LdapConnectionDetails;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link LLdapDockerComposeConnectionDetailsFactory}.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
class LLdapDockerComposeConnectionDetailsFactoryIntegrationTests {
|
||||
|
||||
@DockerComposeTest(composeFile = "lldap-compose.yaml", image = TestImage.LLDAP)
|
||||
void runCreatesConnectionDetails(LdapConnectionDetails connectionDetails) {
|
||||
assertThat(connectionDetails.getUsername()).isEqualTo("cn=admin,ou=people,dc=springframework,dc=org");
|
||||
assertThat(connectionDetails.getPassword()).isEqualTo("somepassword");
|
||||
assertThat(connectionDetails.getBase()).isEqualTo("dc=springframework,dc=org");
|
||||
assertThat(connectionDetails.getUrls()).hasSize(1);
|
||||
assertThat(connectionDetails.getUrls()[0]).startsWith("ldap://");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.boot.docker.compose.service.connection.ldap;
|
||||
|
||||
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
|
||||
import org.springframework.boot.ldap.autoconfigure.LdapConnectionDetails;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link OpenLdapDockerComposeConnectionDetailsFactory}.
|
||||
*
|
||||
* @author Philipp Kessler
|
||||
*/
|
||||
class OpenLdapDockerComposeConnectionDetailsFactoryIntegrationTests {
|
||||
|
||||
@DockerComposeTest(composeFile = "ldap-compose.yaml", image = TestImage.OPEN_LDAP)
|
||||
void runCreatesConnectionDetails(LdapConnectionDetails connectionDetails) {
|
||||
assertThat(connectionDetails.getUsername()).isEqualTo("cn=admin,dc=ldap,dc=example,dc=org");
|
||||
assertThat(connectionDetails.getPassword()).isEqualTo("somepassword");
|
||||
assertThat(connectionDetails.getBase()).isEqualTo("dc=ldap,dc=example,dc=org");
|
||||
assertThat(connectionDetails.getUrls()).hasSize(1);
|
||||
assertThat(connectionDetails.getUrls()[0]).startsWith("ldaps://");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
services:
|
||||
ldap:
|
||||
image: '{imageName}'
|
||||
environment:
|
||||
- 'LDAP_DOMAIN=ldap.example.org'
|
||||
- 'LDAP_ADMIN_PASSWORD=somepassword'
|
||||
- 'LDAP_TLS=true'
|
||||
hostname: ldap
|
||||
ports:
|
||||
- "389"
|
||||
- "636"
|
||||
@@ -1,8 +0,0 @@
|
||||
services:
|
||||
ldap:
|
||||
image: '{imageName}'
|
||||
environment:
|
||||
- 'LLDAP_LDAP_BASE_DN=dc=springframework,dc=org'
|
||||
- 'LLDAP_LDAP_USER_PASS=somepassword'
|
||||
ports:
|
||||
- "3890"
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.boot.docker.compose.service.connection.ldap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
import org.springframework.boot.ldap.autoconfigure.LdapConnectionDetails;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create {@link LdapConnectionDetails}
|
||||
* for an {@code ldap} service.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
class LLdapDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<LdapConnectionDetails> {
|
||||
|
||||
LLdapDockerComposeConnectionDetailsFactory() {
|
||||
super("lldap/lldap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LdapConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new LLdapDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link LdapConnectionDetails} backed by an {@code lldap} {@link RunningService}.
|
||||
*/
|
||||
static class LLdapDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements LdapConnectionDetails {
|
||||
|
||||
private final String[] urls;
|
||||
|
||||
private final String base;
|
||||
|
||||
private final String username;
|
||||
|
||||
private final String password;
|
||||
|
||||
LLdapDockerComposeConnectionDetails(RunningService service) {
|
||||
super(service);
|
||||
Map<String, String> env = service.env();
|
||||
boolean usesTls = Boolean.parseBoolean(env.getOrDefault("LLDAP_LDAPS_OPTIONS__ENABLED", "false"));
|
||||
String ldapPort = usesTls ? env.getOrDefault("LLDAP_LDAPS_OPTIONS__PORT", "6360")
|
||||
: env.getOrDefault("LLDAP_LDAP_PORT", "3890");
|
||||
this.urls = new String[] { "%s://%s:%d".formatted(usesTls ? "ldaps" : "ldap", service.host(),
|
||||
service.ports().get(Integer.parseInt(ldapPort))) };
|
||||
this.base = env.getOrDefault("LLDAP_LDAP_BASE_DN", "dc=example,dc=com");
|
||||
this.password = env.getOrDefault("LLDAP_LDAP_USER_PASS", "password");
|
||||
this.username = "cn=admin,ou=people,%s".formatted(this.base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUrls() {
|
||||
return this.urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBase() {
|
||||
return this.base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.boot.docker.compose.service.connection.ldap;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
import org.springframework.boot.ldap.autoconfigure.LdapConnectionDetails;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create {@link LdapConnectionDetails}
|
||||
* for an {@code ldap} service.
|
||||
*
|
||||
* @author Philipp Kessler
|
||||
*/
|
||||
class OpenLdapDockerComposeConnectionDetailsFactory
|
||||
extends DockerComposeConnectionDetailsFactory<LdapConnectionDetails> {
|
||||
|
||||
protected OpenLdapDockerComposeConnectionDetailsFactory() {
|
||||
super("osixia/openldap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LdapConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new OpenLdapDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link LdapConnectionDetails} backed by an {@code openldap} {@link RunningService}.
|
||||
*/
|
||||
static class OpenLdapDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements LdapConnectionDetails {
|
||||
|
||||
private final String[] urls;
|
||||
|
||||
private final String base;
|
||||
|
||||
private final String username;
|
||||
|
||||
private final String password;
|
||||
|
||||
OpenLdapDockerComposeConnectionDetails(RunningService service) {
|
||||
super(service);
|
||||
Map<String, String> env = service.env();
|
||||
boolean usesTls = Boolean.parseBoolean(env.getOrDefault("LDAP_TLS", "true"));
|
||||
String ldapPort = usesTls ? env.getOrDefault("LDAPS_PORT", "636") : env.getOrDefault("LDAP_PORT", "389");
|
||||
this.urls = new String[] { "%s://%s:%d".formatted(usesTls ? "ldaps" : "ldap", service.host(),
|
||||
service.ports().get(Integer.parseInt(ldapPort))) };
|
||||
if (env.containsKey("LDAP_BASE_DN")) {
|
||||
this.base = env.get("LDAP_BASE_DN");
|
||||
}
|
||||
else {
|
||||
this.base = Arrays.stream(env.getOrDefault("LDAP_DOMAIN", "example.org").split("\\."))
|
||||
.map("dc=%s"::formatted)
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
this.password = env.getOrDefault("LDAP_ADMIN_PASSWORD", "admin");
|
||||
this.username = "cn=admin,%s".formatted(this.base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUrls() {
|
||||
return this.urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBase() {
|
||||
return this.base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Docker Compose LDAP service connections.
|
||||
*/
|
||||
package org.springframework.boot.docker.compose.service.connection.ldap;
|
||||
@@ -1,8 +1,6 @@
|
||||
# Connection Details Factories
|
||||
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
|
||||
org.springframework.boot.docker.compose.service.connection.clickhouse.ClickHouseR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.ldap.LLdapDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.ldap.OpenLdapDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.mariadb.MariaDbR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.mongo.MongoDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
|
||||
Reference in New Issue
Block a user