Added schema retrieval
This commit is contained in:
parent
4793a4b74c
commit
376dedbcab
@ -109,6 +109,38 @@ abstract class Kohana_Database_LDAP extends Kohana_LDAP {
|
||||
run_hook('post_connect',array('server_id'=>$this->index,'method'=>$method,'id'=>$bind['id']));
|
||||
*/
|
||||
|
||||
// Get our Schema.
|
||||
if (isset($benchmark)) {
|
||||
Profiler::stop($benchmark);
|
||||
$benchmark = Profiler::start("Schema Retrieve ({$this->_instance})", $this->_instance);
|
||||
}
|
||||
|
||||
if ($this->_instance == 'auth') {
|
||||
$x = LDAP::factory('schema',NULL,$this->_config);
|
||||
|
||||
try {
|
||||
// Our Auth Bind credentials are wrong
|
||||
if ($x->bind((isset($this->_config['schema']['dn']) ? $this->_config['schema']['dn'] : 'fred'),(isset($this->_config['schema']['password']) ? $this->_config['schema']['password'] : 'fred'))) {
|
||||
|
||||
$u = $x->search(array(''))
|
||||
->scope('base')
|
||||
->where('objectclass','=','*')
|
||||
->execute();
|
||||
|
||||
if (! $u OR ! isset($u[''][0]['subschemasubentry'][0]))
|
||||
throw new Kohana_Exception('Couldnt find schema?');
|
||||
|
||||
$x->setSchema(ORM::factory('LDAP_Schema',$u[''][0]['subschemasubentry'][0]));
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
// If we are a command line, we can just print the error
|
||||
echo _('Unable to retrieve the SCHEMA from the LDAP server.');
|
||||
echo _('The error message is').': '.$e->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($benchmark))
|
||||
Profiler::stop($benchmark);
|
||||
|
||||
|
@ -16,6 +16,11 @@ abstract class Kohana_LDAP extends Database {
|
||||
*/
|
||||
protected $_connected = FALSE;
|
||||
|
||||
/**
|
||||
* @var Our LDAP OBJECT that holds the schema
|
||||
*/
|
||||
protected $_schema = NULL;
|
||||
|
||||
/**
|
||||
* @var string Our default usage when connection
|
||||
*/
|
||||
@ -96,5 +101,13 @@ abstract class Kohana_LDAP extends Database {
|
||||
public static function instance($name=NULL,array $config=NULL) {
|
||||
throw Kohana_Exception('Sorry, you cant use instance(), you need to use factory()');
|
||||
}
|
||||
|
||||
public function setSchema(Model_LDAP_Schema $orm) {
|
||||
$this->_schema = $orm;
|
||||
}
|
||||
|
||||
public function schema() {
|
||||
return $this->_schema;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
14
classes/Model/LDAP/Schema.php
Normal file
14
classes/Model/LDAP/Schema.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class holds our LDAP Schema
|
||||
*
|
||||
* @package Kohana/Database
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2013 phpLDAPadmin Development Team
|
||||
* @license http://dev.phpldapadmin.org/license.html
|
||||
*/
|
||||
class Model_LDAP_Schema extends ORM_LDAP {
|
||||
}
|
||||
?>
|
@ -38,6 +38,10 @@ return array (
|
||||
'profiling' => TRUE,
|
||||
|
||||
'login_attr'=>'uid',
|
||||
'schema'=>array(
|
||||
'dn' => FALSE,
|
||||
'password' => FALSE,
|
||||
),
|
||||
),
|
||||
);
|
||||
?>
|
||||
|
24
tests/classes/LDAPSchema.php
Normal file
24
tests/classes/LDAPSchema.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This should test all our connection methods to the LDAP server
|
||||
* and return success and failures.
|
||||
*
|
||||
* @package Kohana/LDAP
|
||||
* @category Test
|
||||
* @author Deon George
|
||||
* @copyright (c) 2013 phpLDAPadmin Development Team
|
||||
* @license http://dev.phpldapadmin.org/license.html
|
||||
* @group ldap
|
||||
* @group ldap.server
|
||||
*/
|
||||
Class LDAPSchema extends Unittest_TestCase {
|
||||
/**
|
||||
*/
|
||||
function testSchemaAccess() {
|
||||
$x = LDAP::factory('default');
|
||||
$x->bind('bart','eatmyshorts');
|
||||
|
||||
$this->assertTrue(LDAP::factory('schema')->schema() instanceof Model_LDAP_Schema);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user