LDAP: only connect to LDAP once on login

This commit is contained in:
Arthur Schiwon 2013-08-14 16:03:18 +02:00
parent 69350c4e0d
commit c538ac3081
2 changed files with 18 additions and 6 deletions

View File

@ -29,6 +29,9 @@ class Connection {
private $configID;
private $configured = false;
//whether connection should be kept on __destruct
private $dontDestruct = false;
//cache handler
protected $cache;
@ -83,11 +86,20 @@ class Connection {
}
public function __destruct() {
if(is_resource($this->ldapConnectionRes)) {
if(!$this->dontDestruct && is_resource($this->ldapConnectionRes)) {
@ldap_unbind($this->ldapConnectionRes);
};
}
/**
* @brief defines behaviour when the instance is cloned
*/
public function __clone() {
//a cloned instance inherits the connection resource. It may use it,
//but it may not disconnect it
$this->dontDestruct = true;
}
public function __get($name) {
if(!$this->configured) {
$this->readConfiguration();

View File

@ -77,11 +77,6 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
}
$dn = $ldap_users[0];
//are the credentials OK?
if(!$this->areCredentialsValid($dn, $password)) {
return false;
}
//do we have a username for him/her?
$ocname = $this->dn2username($dn);
@ -90,6 +85,11 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
$this->updateQuota($dn);
$this->updateEmail($dn);
//are the credentials OK?
if(!$this->areCredentialsValid($dn, $password)) {
return false;
}
//give back the display name
return $ocname;
}