Fixed LDAP caching

This commit is contained in:
Deon George 2014-07-18 12:35:27 +10:00
parent 7f2f037406
commit 20724f62fc
4 changed files with 26 additions and 8 deletions

View File

@ -65,6 +65,8 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
* @return boolean TRUE|FALSE
*/
private function _bind($u,$p) {
Log::instance()->add(LOG_NOTICE,':instance :method BINDing, Username :user, Pass :pass',array(':instance'=>$this->_instance,':method'=>__METHOD__,':user'=>$u,':pass'=>md5($p)));
/*
// @todo To implement
// If SASL has been configured for binding, then start it now.
@ -92,6 +94,7 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
if (! $br)
return FALSE;
Log::instance()->add(LOG_NOTICE,':instance :method BOUND, Username :user, Pass :pass',array(':instance'=>$this->_instance,':method'=>__METHOD__,':user'=>$u,':pass'=>md5($p)));
$this->_connected = TRUE;
/*
@ -115,11 +118,6 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
$benchmark = Profiler::start("Schema Retrieve ({$this->_instance})", $this->_instance);
}
if ($this->_instance == 'auth') {
$this->getSchema();
}
if (isset($benchmark))
Profiler::stop($benchmark);
@ -144,8 +142,12 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
// Make sure we are connected.
$this->_connection OR $this->connect();
Log::instance()->add(LOG_NOTICE,':instance :method BINDing, Username :user, Pass :pass, LoginAttr :login_attr',array(':instance'=>$this->_instance,':method'=>__METHOD__,':user'=>$user,':pass'=>md5($pass),':login_attr'=>$this->_config['login_attr']));
// Do we need to do an search to find the DN
if (! empty($this->_config['login_attr']) AND strtoupper($this->_config['login_attr']) != 'DN') {
Log::instance()->add(LOG_NOTICE,':instance :method BINDing, Searching for DN',array(':instance'=>$this->_instance,':method'=>__METHOD__));
// Do we need to authenticate for this search?
// Extract the connection parameters, adding required variabels
extract($this->_config['connection'] + array(
@ -171,6 +173,7 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
));
try {
Log::instance()->add(LOG_NOTICE,':instance :method AUTH BINDing, Username :user, Pass :pass, LoginAttr :login_attr',array(':instance'=>$this->_instance,':method'=>__METHOD__,':user'=>$username,':pass'=>md5($password)));
$x = LDAP::factory('auth',NULL,$config);
// Our Auth Bind credentials are wrong
@ -180,7 +183,7 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
$u = $x->search(NULL)
->scope('sub')
->where($this->_config['login_attr'],'=',$user)
->execute();
->execute(NULL,'Model_LDAP');
if (! $u)
return FALSE;
@ -194,7 +197,7 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
foreach ($u as $dn => $leaf)
if ($this->_bind($dn,$pass))
return ORM::factory('LDAP',$dn);
return $leaf;
// We didnt find an AUTH DN to bind with
return FALSE;
@ -220,6 +223,8 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
'port' => '',
));
Log::instance()->add(LOG_NOTICE,':instance :method CONNECT:- host :hostname, port :port',array(':instance'=>$this->_instance,':method'=>__METHOD__,':hostname'=>$hostname,':port'=>$port));
/*
// @todo To implement
if (function_exists('run_hook'))
@ -258,6 +263,8 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
if (isset($benchmark))
Profiler::stop($benchmark);
Log::instance()->add(LOG_NOTICE,':instance :method connectED',array(':instance'=>$this->_instance,':method'=>__METHOD__));
$this->_connection = $r;
}

View File

@ -42,7 +42,7 @@ abstract class Kohana_Database_LDAP_Result_Cached extends Database_Result_Cached
}
public function key() {
return $this->_current_row;
return current($this->_result)->pk();
}
public function next() {

View File

@ -241,6 +241,7 @@ abstract class Kohana_Database_LDAP_Search {
throw HTTP_Exception::factory(501,'Cant run a search without a connection (:type,:filter)',array(':type'=>$this->_db,':filter'=>$this->_filter));
$result = new Database_LDAP_Search_Result;
foreach ($this->_base as $base) {
if (($this->_lifetime !== NULL AND $this->_db->caching()) OR (Kohana::$caching AND $this->_db->caching() AND $this->cached())) {
// Set the cache key based on the database instance name and SQL

View File

@ -62,21 +62,31 @@ abstract class Kohana_Database_LDAP_Search_Result implements ArrayAccess,Iterato
}
public function next() {
// If our current entry has more valid entries, skip to the next one.
if (current($this->result)->valid() AND current($this->result)->next()->valid())
return current($this->result);
// Skip to our next record
next($this->result);
// If the next record is invalid, keep jumping to find a valid record
while (current($this->result) AND ! current($this->result)->valid())
if (next($this->result) === FALSE)
break;
// Rewind our current record
if (is_object($this->result))
current($this->result)->rewind();
return current($this->result);
}
public function rewind() {
is_resource($this->result) ? rewind($this->result) : reset($this->result);
current($this->result)->rewind();
// If our current record is invalid, skip to the next one.
if (! current($this->result)->valid())
$this->next(FALSE);