Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit b725367

Browse files
melangervyskocilpavel
authored andcommitted
LDAP startTLS support (port 389)
1 parent 9e0dce6 commit b725367

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/LdapConnector.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ class LdapConnector
3131
private $hostname;
3232
private $user;
3333
private $password;
34+
private $enableTLS;
3435

3536
/**
3637
* LdapConnector constructor.
3738
* @param $hostname
3839
* @param $user
3940
* @param $password
41+
* @param $enableTLS
4042
*/
41-
public function __construct($hostname, $user, $password)
43+
public function __construct($hostname, $user, $password, $enableTLS = false)
4244
{
4345
$this->hostname = $hostname;
4446
$this->user = $user;
4547
$this->password = $password;
48+
$this->enableTLS = $enableTLS;
4649
}
4750

4851
/**
@@ -108,6 +111,13 @@ protected function search($base, $filter, $attributes = null)
108111
}
109112

110113
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
114+
115+
// Enable TLS, if needed
116+
if ($this->enableTLS && stripos($this->hostname, "ldaps:") === false) {
117+
if (!@ldap_start_tls($conn)) {
118+
throw new Exception('Unable to force TLS on Perun LDAP');
119+
}
120+
}
111121

112122
if (ldap_bind($conn, $this->user, $this->password) === false) {
113123
throw new Exception('Unable to bind user to the Perun LDAP, ' . $this->hostname);

0 commit comments

Comments
 (0)