diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-10 17:11:02 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-27 13:34:15 +0200 |
commit | d4f92494a23747af545d7ebb70eaf3e417f46eaa (patch) | |
tree | e0b0610eca24fb38028bc50ada7bd7b397358c97 /apps/user_ldap/lib | |
parent | b9cc2ad660fb7a43f2b0a12e1290527fcebb995a (diff) | |
download | nextcloud-server-d4f92494a23747af545d7ebb70eaf3e417f46eaa.tar.gz nextcloud-server-d4f92494a23747af545d7ebb70eaf3e417f46eaa.zip |
LDAP: make Access be a dependency to the user and group backend instead of inheriting it.
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/access.php | 7 | ||||
-rw-r--r-- | apps/user_ldap/lib/backendutility.php | 38 | ||||
-rw-r--r-- | apps/user_ldap/lib/connection.php | 22 | ||||
-rw-r--r-- | apps/user_ldap/lib/jobs.php | 11 | ||||
-rw-r--r-- | apps/user_ldap/lib/ldap.php | 2 | ||||
-rw-r--r-- | apps/user_ldap/lib/ldaputility.php (renamed from apps/user_ldap/lib/backendbase.php) | 20 | ||||
-rw-r--r-- | apps/user_ldap/lib/proxy.php | 25 |
7 files changed, 81 insertions, 44 deletions
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/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 @@ +<?php + +/** + * ownCloud – LDAP BackendUtility + * + * @author Arthur Schiwon + * @copyright 2013 Arthur Schiwon blizzz@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +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/backendbase.php b/apps/user_ldap/lib/ldaputility.php index 5ed73a0a5b1..975df7d1de0 100644 --- a/apps/user_ldap/lib/backendbase.php +++ b/apps/user_ldap/lib/ldaputility.php @@ -1,7 +1,7 @@ <?php /** - * ownCloud – LDAP BackendBase + * ownCloud – LDAP LDAPUtility * * @author Arthur Schiwon * @copyright 2013 Arthur Schiwon blizzz@owncloud.com @@ -23,24 +23,14 @@ namespace OCA\user_ldap\lib; -abstract class BackendBase { +abstract class LDAPUtility { 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 + * @brief constructor, make sure the subclasses call this one! + * @param $ldapWrapper an instance of an ILDAPWrapper */ - public function setLDAPWrapper(ILDAPWrapper $ldapWrapper) { + public function __construct(ILDAPWrapper $ldapWrapper) { $this->ldap = $ldapWrapper; - return true; } }
\ 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) { |