From d4f92494a23747af545d7ebb70eaf3e417f46eaa Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 10 Sep 2013 17:11:02 +0200 Subject: LDAP: make Access be a dependency to the user and group backend instead of inheriting it. --- apps/user_ldap/lib/access.php | 7 +++--- apps/user_ldap/lib/backendbase.php | 46 ----------------------------------- apps/user_ldap/lib/backendutility.php | 38 +++++++++++++++++++++++++++++ apps/user_ldap/lib/connection.php | 22 ++++++++++------- apps/user_ldap/lib/jobs.php | 11 +++++---- apps/user_ldap/lib/ldap.php | 2 ++ apps/user_ldap/lib/ldaputility.php | 36 +++++++++++++++++++++++++++ apps/user_ldap/lib/proxy.php | 25 ++++++++++--------- 8 files changed, 112 insertions(+), 75 deletions(-) delete mode 100644 apps/user_ldap/lib/backendbase.php create mode 100644 apps/user_ldap/lib/backendutility.php create mode 100644 apps/user_ldap/lib/ldaputility.php (limited to 'apps/user_ldap/lib') diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 4b7920b7162..3d791755aba 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -23,12 +23,13 @@ namespace OCA\user_ldap\lib; -abstract class Access extends BackendBase { - protected $connection; +class Access extends LDAPUtility { + public $connection; //never ever check this var directly, always use getPagedSearchResultState protected $pagedSearchedSuccessful; - public function setConnector(Connection &$connection) { + public function __construct(Connection $connection, ILDAPWrapper $ldap) { + parent::__construct($ldap); $this->connection = $connection; } diff --git a/apps/user_ldap/lib/backendbase.php b/apps/user_ldap/lib/backendbase.php deleted file mode 100644 index 5ed73a0a5b1..00000000000 --- a/apps/user_ldap/lib/backendbase.php +++ /dev/null @@ -1,46 +0,0 @@ -. - * - */ - -namespace OCA\user_ldap\lib; - -abstract class BackendBase { - protected $ldap; - - public function __construct() { - $this->ldap = new LDAP(); - } - - /** - * @brief sets the LDAP Wrapper to be used - * - * @param $ldapWrapper an instance of the Wrapper - * @return true on success, otherwise false - * - * The LDAP Wrapper must implement the PHP LDAP functions, which are used - * in the LDAP backend - */ - public function setLDAPWrapper(ILDAPWrapper $ldapWrapper) { - $this->ldap = $ldapWrapper; - return true; - } -} \ No newline at end of file diff --git a/apps/user_ldap/lib/backendutility.php b/apps/user_ldap/lib/backendutility.php new file mode 100644 index 00000000000..f279b1e997e --- /dev/null +++ b/apps/user_ldap/lib/backendutility.php @@ -0,0 +1,38 @@ +. + * + */ + +namespace OCA\user_ldap\lib; + +use OCA\user_ldap\lib\Access; + +abstract class BackendUtility { + protected $access; + + /** + * @brief constructor, make sure the subclasses call this one! + * @param $access an instance of Access for LDAP interaction + */ + public function __construct(Access $access) { + $this->access = $access; + } +} \ No newline at end of file diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index dd627a4e1b1..0bf13a19377 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -23,7 +23,7 @@ namespace OCA\user_ldap\lib; -class Connection extends BackendBase { +class Connection extends LDAPUtility { private $ldapConnectionRes = null; private $configPrefix; private $configID; @@ -60,7 +60,7 @@ class Connection extends BackendBase { 'ldapQuotaDefault' => null, 'ldapEmailAttribute' => null, 'ldapCacheTTL' => null, - 'ldapUuidAttribute' => null, + 'ldapUuidAttribute' => 'auto', 'ldapOverrideUuidAttribute' => null, 'ldapOverrideMainServer' => false, 'ldapConfigurationActive' => false, @@ -77,8 +77,8 @@ class Connection extends BackendBase { * @param $configPrefix a string with the prefix for the configkey column (appconfig table) * @param $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections */ - public function __construct($configPrefix = '', $configID = 'user_ldap') { - parent::__construct(); + public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { + parent::__construct($ldap); $this->configPrefix = $configPrefix; $this->configID = $configID; $memcache = new \OC\Memcache\Factory(); @@ -363,6 +363,14 @@ class Connection extends BackendBase { && $params[$parameter] === 'homeFolderNamingRule')) && !empty($value)) { $value = 'attr:'.$value; + } else if (strpos($parameter, 'ldapBase') !== false + || (isset($params[$parameter]) + && strpos($params[$parameter], 'ldapBase') !== false)) { + $this->readBase($params[$parameter], $value); + if(is_array($setParameters)) { + $setParameters[] = $parameter; + } + continue; } if(isset($this->config[$parameter])) { $this->config[$parameter] = $value; @@ -433,10 +441,6 @@ class Connection extends BackendBase { $config[$dbKey] = ''; } continue; - } else if((strpos($classKey, 'ldapBase') !== false) - || (strpos($classKey, 'ldapAttributes') !== false)) { - $config[$dbKey] = implode("\n", $this->config[$classKey]); - continue; } $config[$dbKey] = $this->config[$classKey]; } @@ -553,7 +557,7 @@ class Connection extends BackendBase { * @returns an associative array with the default values. Keys are correspond * to config-value entries in the database table */ - public function getDefaults() { + static public function getDefaults() { return array( 'ldap_host' => '', 'ldap_port' => '389', diff --git a/apps/user_ldap/lib/jobs.php b/apps/user_ldap/lib/jobs.php index 6b7666d4ca1..2f90da3bfb6 100644 --- a/apps/user_ldap/lib/jobs.php +++ b/apps/user_ldap/lib/jobs.php @@ -139,13 +139,14 @@ class Jobs extends \OC\BackgroundJob\TimedJob { return self::$groupBE; } $configPrefixes = Helper::getServerConfigurationPrefixes(true); - if(count($configPrefixes) == 1) { + $ldapWrapper = new OCA\user_ldap\lib\LDAP(); + if(count($configPrefixes) === 1) { //avoid the proxy when there is only one LDAP server configured - $connector = new Connection($configPrefixes[0]); - self::$groupBE = new \OCA\user_ldap\GROUP_LDAP(); - self::$groupBE->setConnector($connector); + $connector = new OCA\user_ldap\lib\Connection($ldapWrapper, $configPrefixes[0]); + $ldapAccess = new OCA\user_ldap\lib\Access($connector, $ldapWrapper); + self::$groupBE = new OCA\user_ldap\GROUP_LDAP($ldapAccess); } else { - self::$groupBE = new \OCA\user_ldap\Group_Proxy($configPrefixes); + self::$groupBE = new \OCA\user_ldap\Group_Proxy($configPrefixes, $ldapWrapper); } return self::$groupBE; diff --git a/apps/user_ldap/lib/ldap.php b/apps/user_ldap/lib/ldap.php index 0f082147b14..ee2e336cc95 100644 --- a/apps/user_ldap/lib/ldap.php +++ b/apps/user_ldap/lib/ldap.php @@ -149,6 +149,8 @@ class LDAP implements ILDAPWrapper { && $errorCode === -4) { } else if ($errorCode === 32) { //for now + } else if ($errorCode === 10) { + //referrals, we switch them off, but then there is AD :) } else { throw new \Exception('LDAP error '.$errorMsg.' (' . $errorCode.') after calling '.$this->curFunc. diff --git a/apps/user_ldap/lib/ldaputility.php b/apps/user_ldap/lib/ldaputility.php new file mode 100644 index 00000000000..975df7d1de0 --- /dev/null +++ b/apps/user_ldap/lib/ldaputility.php @@ -0,0 +1,36 @@ +. + * + */ + +namespace OCA\user_ldap\lib; + +abstract class LDAPUtility { + protected $ldap; + + /** + * @brief constructor, make sure the subclasses call this one! + * @param $ldapWrapper an instance of an ILDAPWrapper + */ + public function __construct(ILDAPWrapper $ldapWrapper) { + $this->ldap = $ldapWrapper; + } +} \ No newline at end of file diff --git a/apps/user_ldap/lib/proxy.php b/apps/user_ldap/lib/proxy.php index ae3e3be7361..c74b357bdd2 100644 --- a/apps/user_ldap/lib/proxy.php +++ b/apps/user_ldap/lib/proxy.php @@ -23,26 +23,27 @@ namespace OCA\user_ldap\lib; +use OCA\user_ldap\lib\Access; + abstract class Proxy { - static private $connectors = array(); + static private $accesses = array(); + private $ldap = null; - public function __construct() { + public function __construct(ILDAPWrapper $ldap) { + $this->ldap = $ldap; $this->cache = \OC_Cache::getGlobalCache(); } - private function addConnector($configPrefix) { - self::$connectors[$configPrefix] = new \OCA\user_ldap\lib\Connection($configPrefix); + private function addAccess($configPrefix) { + $connector = new Connection($this->ldap, $configPrefix); + self::$accesses[$configPrefix] = new Access($connector, $this->ldap); } - protected function getConnector($configPrefix) { - if(!isset(self::$connectors[$configPrefix])) { - $this->addConnector($configPrefix); + protected function getAccess($configPrefix) { + if(!isset(self::$accesses[$configPrefix])) { + $this->addAccess($configPrefix); } - return self::$connectors[$configPrefix]; - } - - protected function getConnectors() { - return self::$connectors; + return self::$accesses[$configPrefix]; } protected function getUserCacheKey($uid) { -- cgit v1.2.3