Skip to content

Commit 13787da

Browse files
committed
Fix LDAP connection options
1 parent 129a271 commit 13787da

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,21 @@ private function connect()
147147
return;
148148
}
149149

150+
foreach ($this->config['options'] as $name => $value) {
151+
if (ConnectionOptions::isPreconnectOption($name)) {
152+
$this->setOption($name, $value);
153+
}
154+
}
155+
150156
$this->connection = ldap_connect($this->config['connection_string']);
151157

152158
foreach ($this->config['options'] as $name => $value) {
153-
$this->setOption($name, $value);
159+
if (!ConnectionOptions::isPreconnectOption($name)) {
160+
$this->setOption($name, $value);
161+
}
154162
}
155163

164+
156165
if (false === $this->connection) {
157166
throw new LdapException('Could not connect to Ldap server: '.ldap_error($this->connection));
158167
}

src/Symfony/Component/Ldap/Adapter/ExtLdap/ConnectionOptions.php

+13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final class ConnectionOptions
4040
public const DEBUG_LEVEL = 0x5001;
4141
public const TIMEOUT = 0x5002;
4242
public const NETWORK_TIMEOUT = 0x5005;
43+
public const X_TLS_CACERTFILE = 0x6002;
4344
public const X_TLS_CACERTDIR = 0x6003;
4445
public const X_TLS_CERTFILE = 0x6004;
4546
public const X_TLS_CRL_ALL = 0x02;
@@ -62,6 +63,13 @@ final class ConnectionOptions
6263
public const X_KEEPALIVE_PROBES = 0x6301;
6364
public const X_KEEPALIVE_INTERVAL = 0x6302;
6465

66+
private const PRECONNECT_OPTIONS = [
67+
self::DEBUG_LEVEL,
68+
self::X_TLS_CACERTDIR,
69+
self::X_TLS_CACERTFILE,
70+
self::X_TLS_REQUIRE_CERT,
71+
];
72+
6573
public static function getOptionName(string $name): string
6674
{
6775
return sprintf('%s::%s', self::class, strtoupper($name));
@@ -89,4 +97,9 @@ public static function isOption(string $name): bool
8997
{
9098
return \defined(self::getOptionName($name));
9199
}
100+
101+
public static function isPreconnectOption(string $name): bool
102+
{
103+
return \in_array(self::getOption($name), self::PRECONNECT_OPTIONS, true);
104+
}
92105
}

0 commit comments

Comments
 (0)