1
0
mirror of synced 2026-08-31 14:35:18 +00:00

Bind UnboundIdContainer to loopback address

This commit is contained in:
Joe Grandja
2026-07-10 10:42:39 -04:00
committed by Josh Cummings
parent 249ea55494
commit 56456601ab
4 changed files with 27 additions and 3 deletions
@@ -21,9 +21,11 @@ import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,6 +50,24 @@ public class UnboundIdContainerTests {
}
}
@Test
public void startLdapServerThenListenerBindsToLoopbackAddressOnly() throws Exception {
UnboundIdContainer server = new UnboundIdContainer("dc=springframework,dc=org", null);
server.setApplicationContext(new GenericApplicationContext());
List<Integer> ports = getDefaultPorts(1);
server.setPort(ports.get(0));
try {
server.afterPropertiesSet();
InMemoryDirectoryServer directoryServer = (InMemoryDirectoryServer) ReflectionTestUtils.getField(server,
"directoryServer");
assertThat(directoryServer.getListenAddress().isLoopbackAddress()).isTrue();
}
finally {
server.destroy();
}
}
@Test
public void afterPropertiesSetWhenPortIsZeroThenRandomPortIsSelected() throws Exception {
UnboundIdContainer server = new UnboundIdContainer("dc=springframework,dc=org", null);
@@ -17,6 +17,7 @@
package org.springframework.security.ldap.server;
import java.io.InputStream;
import java.net.InetAddress;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
@@ -98,7 +99,8 @@ public class UnboundIdContainer
try {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.defaultPartitionSuffix);
config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", this.port));
config.setListenerConfigs(
InMemoryListenerConfig.createLDAPConfig("LDAP", InetAddress.getLoopbackAddress(), this.port, null));
config.setEnforceSingleStructuralObjectClass(false);
config.setEnforceAttributeSyntaxCompliance(true);
DN dn = new DN(this.defaultPartitionSuffix);