Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Manager/LdapConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class LdapConnection implements LdapConnectionInterface

protected $ress;

/**
* Holds a list of resources per username (username=>resource) to allow for reusing binded connections.
* @var array
*/
protected $resources = array();

public function __construct(array $params, Logger $logger)
{
$this->params = $params;
Expand Down Expand Up @@ -64,7 +70,7 @@ public function search(array $params)

/**
* @return true
* @throws \IMAG\LdapBundle\Exceptions\ConnectionException | Connection error
* @throws \IMAG\LdapBundle\Exception\ConnectionException | Connection error
*/
public function bind($user_dn, $password = '', $ress = null)
{
Expand Down Expand Up @@ -128,6 +134,16 @@ private function connect()
? $this->params['client']['port']
: '389';

// check if there is a binded connection for this username, if there is, set $this->ress and return without
// doing it again.
$username = $this->params['client']['username'];
if (isset($this->params['client']['username'])) {
if (isset($this->resources[$username])) {
$this->ress = $this->resources[$username];
return $this;
}
}

$ress = @ldap_connect($this->params['client']['host'], $port);

if (isset($this->params['client']['version'])) {
Expand All @@ -151,6 +167,8 @@ private function connect()
$this->checkLdapError($ress);
}

// store resource per username to be reused later.
$this->resources[$username] = $ress;
$this->ress = $ress;

return $this;
Expand Down