OCP\JSON::callCheck();
$prefix = $_POST['ldap_serverconfig_chooser'];
-$connection = new \OCA\user_ldap\lib\Connection($prefix);
+$ldapWrapper = new OCA\user_ldap\lib\LDAP();
+$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
OCP\JSON::success(array('configuration' => $connection->getConfiguration()));
OCP\JSON::callCheck();
$prefix = $_POST['ldap_serverconfig_chooser'];
-$connection = new \OCA\user_ldap\lib\Connection($prefix);
+$ldapWrapper = new OCA\user_ldap\lib\LDAP();
+$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
$connection->setConfiguration($_POST);
$connection->saveConfiguration();
OCP\JSON::success();
$l=OC_L10N::get('user_ldap');
-$connection = new \OCA\user_ldap\lib\Connection('', null);
+$ldapWrapper = new OCA\user_ldap\lib\LDAP();
+$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, '', null);
if($connection->setConfiguration($_POST)) {
//Configuration is okay
if($connection->bind()) {
OCP\App::registerAdmin('user_ldap', 'settings');
$configPrefixes = OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes(true);
+$ldapWrapper = new OCA\user_ldap\lib\LDAP();
if(count($configPrefixes) === 1) {
- $connector = new OCA\user_ldap\lib\Connection($configPrefixes[0]);
- $userBackend = new OCA\user_ldap\USER_LDAP();
- $userBackend->setConnector($connector);
- $groupBackend = new OCA\user_ldap\GROUP_LDAP();
- $groupBackend->setConnector($connector);
+ $connector = new OCA\user_ldap\lib\Connection($ldapWrapper, $configPrefixes[0]);
+ $ldapAccess = new OCA\user_ldap\lib\Access($connector, $ldapWrapper);
+ $userBackend = new OCA\user_ldap\USER_LDAP($ldapAccess);
+ $groupBackend = new OCA\user_ldap\GROUP_LDAP($ldapAccess);
} else {
- $userBackend = new OCA\user_ldap\User_Proxy($configPrefixes);
- $groupBackend = new OCA\user_ldap\Group_Proxy($configPrefixes);
+ $userBackend = new OCA\user_ldap\User_Proxy($configPrefixes, $ldapWrapper);
+ $groupBackend = new OCA\user_ldap\Group_Proxy($configPrefixes, $ldapWrapper);
}
if(count($configPrefixes) > 0) {
namespace OCA\user_ldap;
-class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
+use OCA\user_ldap\lib\Access;
+use OCA\user_ldap\lib\BackendUtility;
+
+class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface {
protected $enabled = false;
- public function setConnector(lib\Connection &$connection) {
- parent::setConnector($connection);
- $filter = $this->connection->ldapGroupFilter;
- $gassoc = $this->connection->ldapGroupMemberAssocAttr;
+ public function __construct(Access $access) {
+ parent::__construct($access);
+ $filter = $this->access->connection->ldapGroupFilter;
+ $gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
if(!empty($filter) && !empty($gassoc)) {
$this->enabled = true;
}
if(!$this->enabled) {
return false;
}
- if($this->connection->isCached('inGroup'.$uid.':'.$gid)) {
- return $this->connection->getFromCache('inGroup'.$uid.':'.$gid);
+ if($this->access->connection->isCached('inGroup'.$uid.':'.$gid)) {
+ return $this->access->connection->getFromCache('inGroup'.$uid.':'.$gid);
}
- $dn_user = $this->username2dn($uid);
- $dn_group = $this->groupname2dn($gid);
+ $dn_user = $this->access->username2dn($uid);
+ $dn_group = $this->access->groupname2dn($gid);
// just in case
if(!$dn_group || !$dn_user) {
- $this->connection->writeToCache('inGroup'.$uid.':'.$gid, false);
+ $this->access->connection->writeToCache('inGroup'.$uid.':'.$gid, false);
return false;
}
//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
- $members = $this->readAttribute($dn_group, $this->connection->ldapGroupMemberAssocAttr);
+ $members = $this->access->readAttribute($dn_group, $this->access->connection->ldapGroupMemberAssocAttr);
if(!$members) {
- $this->connection->writeToCache('inGroup'.$uid.':'.$gid, false);
+ $this->access->connection->writeToCache('inGroup'.$uid.':'.$gid, false);
return false;
}
//extra work if we don't get back user DNs
//TODO: this can be done with one LDAP query
- if(strtolower($this->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
+ if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
$dns = array();
foreach($members as $mid) {
- $filter = str_replace('%uid', $mid, $this->connection->ldapLoginFilter);
- $ldap_users = $this->fetchListOfUsers($filter, 'dn');
+ $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
+ $ldap_users = $this->access->fetchListOfUsers($filter, 'dn');
if(count($ldap_users) < 1) {
continue;
}
}
$isInGroup = in_array($dn_user, $members);
- $this->connection->writeToCache('inGroup'.$uid.':'.$gid, $isInGroup);
+ $this->access->connection->writeToCache('inGroup'.$uid.':'.$gid, $isInGroup);
return $isInGroup;
}
return array();
}
$cacheKey = 'getUserGroups'.$uid;
- if($this->connection->isCached($cacheKey)) {
- return $this->connection->getFromCache($cacheKey);
+ if($this->access->connection->isCached($cacheKey)) {
+ return $this->access->connection->getFromCache($cacheKey);
}
- $userDN = $this->username2dn($uid);
+ $userDN = $this->access->username2dn($uid);
if(!$userDN) {
- $this->connection->writeToCache($cacheKey, array());
+ $this->access->connection->writeToCache($cacheKey, array());
return array();
}
//uniqueMember takes DN, memberuid the uid, so we need to distinguish
- if((strtolower($this->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
- || (strtolower($this->connection->ldapGroupMemberAssocAttr) === 'member')
+ if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
+ || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
) {
$uid = $userDN;
- } else if(strtolower($this->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
- $result = $this->readAttribute($userDN, 'uid');
+ } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
+ $result = $this->access->readAttribute($userDN, 'uid');
$uid = $result[0];
} else {
// just in case
$uid = $userDN;
}
- $filter = $this->combineFilterWithAnd(array(
- $this->connection->ldapGroupFilter,
- $this->connection->ldapGroupMemberAssocAttr.'='.$uid
+ $filter = $this->access->combineFilterWithAnd(array(
+ $this->access->connection->ldapGroupFilter,
+ $this->access->connection->ldapGroupMemberAssocAttr.'='.$uid
));
- $groups = $this->fetchListOfGroups($filter, array($this->connection->ldapGroupDisplayName, 'dn'));
- $groups = array_unique($this->ownCloudGroupNames($groups), SORT_LOCALE_STRING);
- $this->connection->writeToCache($cacheKey, $groups);
+ $groups = $this->access->fetchListOfGroups($filter, array($this->access->connection->ldapGroupDisplayName, 'dn'));
+ $groups = array_unique($this->access->ownCloudGroupNames($groups), SORT_LOCALE_STRING);
+ $this->access->connection->writeToCache($cacheKey, $groups);
return $groups;
}
}
$cachekey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
// check for cache of the exact query
- $groupUsers = $this->connection->getFromCache($cachekey);
+ $groupUsers = $this->access->connection->getFromCache($cachekey);
if(!is_null($groupUsers)) {
return $groupUsers;
}
// check for cache of the query without limit and offset
- $groupUsers = $this->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
+ $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
if(!is_null($groupUsers)) {
$groupUsers = array_slice($groupUsers, $offset, $limit);
- $this->connection->writeToCache($cachekey, $groupUsers);
+ $this->access->connection->writeToCache($cachekey, $groupUsers);
return $groupUsers;
}
if($limit === -1) {
$limit = null;
}
- $groupDN = $this->groupname2dn($gid);
+ $groupDN = $this->access->groupname2dn($gid);
if(!$groupDN) {
// group couldn't be found, return empty resultset
- $this->connection->writeToCache($cachekey, array());
+ $this->access->connection->writeToCache($cachekey, array());
return array();
}
- $members = $this->readAttribute($groupDN, $this->connection->ldapGroupMemberAssocAttr);
+ $members = $this->access->readAttribute($groupDN, $this->access->connection->ldapGroupMemberAssocAttr);
if(!$members) {
//in case users could not be retrieved, return empty resultset
- $this->connection->writeToCache($cachekey, array());
+ $this->access->connection->writeToCache($cachekey, array());
return array();
}
$groupUsers = array();
- $isMemberUid = (strtolower($this->connection->ldapGroupMemberAssocAttr) === 'memberuid');
+ $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
foreach($members as $member) {
if($isMemberUid) {
//we got uids, need to get their DNs to 'tranlsate' them to usernames
- $filter = $this->combineFilterWithAnd(array(
+ $filter = $this->access->combineFilterWithAnd(array(
\OCP\Util::mb_str_replace('%uid', $member,
- $this->connection->ldapLoginFilter, 'UTF-8'),
- $this->getFilterPartForUserSearch($search)
+ $this->access->connection->ldapLoginFilter, 'UTF-8'),
+ $this->access->getFilterPartForUserSearch($search)
));
- $ldap_users = $this->fetchListOfUsers($filter, 'dn');
+ $ldap_users = $this->access->fetchListOfUsers($filter, 'dn');
if(count($ldap_users) < 1) {
continue;
}
- $groupUsers[] = $this->dn2username($ldap_users[0]);
+ $groupUsers[] = $this->access->dn2username($ldap_users[0]);
} else {
//we got DNs, check if we need to filter by search or we can give back all of them
if(!empty($search)) {
- if(!$this->readAttribute($member,
- $this->connection->ldapUserDisplayName,
- $this->getFilterPartForUserSearch($search))) {
+ if(!$this->access->readAttribute($member,
+ $this->access->connection->ldapUserDisplayName,
+ $this->access->getFilterPartForUserSearch($search))) {
continue;
}
}
// dn2username will also check if the users belong to the allowed base
- if($ocname = $this->dn2username($member)) {
+ if($ocname = $this->access->dn2username($member)) {
$groupUsers[] = $ocname;
}
}
}
natsort($groupUsers);
- $this->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers);
+ $this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers);
$groupUsers = array_slice($groupUsers, $offset, $limit);
- $this->connection->writeToCache($cachekey, $groupUsers);
+ $this->access->connection->writeToCache($cachekey, $groupUsers);
return $groupUsers;
}
//Check cache before driving unnecessary searches
\OCP\Util::writeLog('user_ldap', 'getGroups '.$cachekey, \OCP\Util::DEBUG);
- $ldap_groups = $this->connection->getFromCache($cachekey);
+ $ldap_groups = $this->access->connection->getFromCache($cachekey);
if(!is_null($ldap_groups)) {
return $ldap_groups;
}
if($limit <= 0) {
$limit = null;
}
- $filter = $this->combineFilterWithAnd(array(
- $this->connection->ldapGroupFilter,
- $this->getFilterPartForGroupSearch($search)
+ $filter = $this->access->combineFilterWithAnd(array(
+ $this->access->connection->ldapGroupFilter,
+ $this->access->getFilterPartForGroupSearch($search)
));
\OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, \OCP\Util::DEBUG);
- $ldap_groups = $this->fetchListOfGroups($filter, array($this->connection->ldapGroupDisplayName, 'dn'),
+ $ldap_groups = $this->access->fetchListOfGroups($filter, array($this->access->connection->ldapGroupDisplayName, 'dn'),
$limit, $offset);
- $ldap_groups = $this->ownCloudGroupNames($ldap_groups);
+ $ldap_groups = $this->access->ownCloudGroupNames($ldap_groups);
- $this->connection->writeToCache($cachekey, $ldap_groups);
+ $this->access->connection->writeToCache($cachekey, $ldap_groups);
return $ldap_groups;
}
* @return bool
*/
public function groupExists($gid) {
- if($this->connection->isCached('groupExists'.$gid)) {
- return $this->connection->getFromCache('groupExists'.$gid);
+ if($this->access->connection->isCached('groupExists'.$gid)) {
+ return $this->access->connection->getFromCache('groupExists'.$gid);
}
//getting dn, if false the group does not exist. If dn, it may be mapped only, requires more checking.
- $dn = $this->groupname2dn($gid);
+ $dn = $this->access->groupname2dn($gid);
if(!$dn) {
- $this->connection->writeToCache('groupExists'.$gid, false);
+ $this->access->connection->writeToCache('groupExists'.$gid, false);
return false;
}
//if group really still exists, we will be able to read its objectclass
- $objcs = $this->readAttribute($dn, 'objectclass');
+ $objcs = $this->access->readAttribute($dn, 'objectclass');
if(!$objcs || empty($objcs)) {
- $this->connection->writeToCache('groupExists'.$gid, false);
+ $this->access->connection->writeToCache('groupExists'.$gid, false);
return false;
}
- $this->connection->writeToCache('groupExists'.$gid, true);
+ $this->access->connection->writeToCache('groupExists'.$gid, true);
return true;
}
namespace OCA\user_ldap;
+use OCA\user_ldap\lib\ILDAPWrapper;
+
class Group_Proxy extends lib\Proxy implements \OCP\GroupInterface {
private $backends = array();
private $refBackend = null;
* @brief Constructor
* @param $serverConfigPrefixes array containing the config Prefixes
*/
- public function __construct($serverConfigPrefixes) {
- parent::__construct();
+ public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap) {
+ parent::__construct($ldap);
foreach($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] = new \OCA\user_ldap\GROUP_LDAP();
- $connector = $this->getConnector($configPrefix);
- $this->backends[$configPrefix]->setConnector($connector);
+ $this->backends[$configPrefix] = new \OCA\user_ldap\GROUP_LDAP($this->getAccess($configPrefix));
if(is_null($this->refBackend)) {
$this->refBackend = &$this->backends[$configPrefix];
}
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;
}
+++ /dev/null
-<?php
-
-/**
- * ownCloud – LDAP BackendBase
- *
- * @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;
-
-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
--- /dev/null
+<?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
namespace OCA\user_ldap\lib;
-class Connection extends BackendBase {
+class Connection extends LDAPUtility {
private $ldapConnectionRes = null;
private $configPrefix;
private $configID;
'ldapQuotaDefault' => null,
'ldapEmailAttribute' => null,
'ldapCacheTTL' => null,
- 'ldapUuidAttribute' => null,
+ 'ldapUuidAttribute' => 'auto',
'ldapOverrideUuidAttribute' => null,
'ldapOverrideMainServer' => false,
'ldapConfigurationActive' => false,
* @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();
&& $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;
$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];
}
* @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',
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;
&& $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.
--- /dev/null
+<?php
+
+/**
+ * ownCloud – LDAP LDAPUtility
+ *
+ * @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;
+
+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
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) {
$tmpl->assign('serverConfigurationHosts', $hosts);
// assign default values
-if(!isset($ldap)) {
- $ldap = new \OCA\user_ldap\lib\Connection();
-}
-$defaults = $ldap->getDefaults();
+$defaults = \OCA\user_ldap\lib\Connection::getDefaults();
foreach($defaults as $key => $default) {
$tmpl->assign($key.'_default', $default);
}
-// $tmpl->assign();
-
return $tmpl->fetchPage();
namespace OCA\user_ldap;
-class USER_LDAP extends lib\Access implements \OCP\UserInterface {
+use OCA\user_ldap\lib\ILDAPWrapper;
+use OCA\user_ldap\lib\BackendUtility;
+
+class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
private function updateQuota($dn) {
$quota = null;
- $quotaDefault = $this->connection->ldapQuotaDefault;
- $quotaAttribute = $this->connection->ldapQuotaAttribute;
+ $quotaDefault = $this->access->connection->ldapQuotaDefault;
+ $quotaAttribute = $this->access->connection->ldapQuotaAttribute;
if(!empty($quotaDefault)) {
$quota = $quotaDefault;
}
if(!empty($quotaAttribute)) {
- $aQuota = $this->readAttribute($dn, $quotaAttribute);
+ $aQuota = $this->access->readAttribute($dn, $quotaAttribute);
if($aQuota && (count($aQuota) > 0)) {
$quota = $aQuota[0];
}
}
if(!is_null($quota)) {
- \OCP\Config::setUserValue($this->dn2username($dn), 'files', 'quota', \OCP\Util::computerFileSize($quota));
+ \OCP\Config::setUserValue( $this->access->dn2username($dn),
+ 'files',
+ 'quota',
+ \OCP\Util::computerFileSize($quota));
}
}
private function updateEmail($dn) {
$email = null;
- $emailAttribute = $this->connection->ldapEmailAttribute;
+ $emailAttribute = $this->access->connection->ldapEmailAttribute;
if(!empty($emailAttribute)) {
- $aEmail = $this->readAttribute($dn, $emailAttribute);
+ $aEmail = $this->access->readAttribute($dn, $emailAttribute);
if($aEmail && (count($aEmail) > 0)) {
$email = $aEmail[0];
}
if(!is_null($email)) {
- \OCP\Config::setUserValue($this->dn2username($dn), 'settings', 'email', $email);
+ \OCP\Config::setUserValue( $this->access->dn2username($dn),
+ 'settings',
+ 'email',
+ $email);
}
}
}
*/
public function checkPassword($uid, $password) {
//find out dn of the user name
- $filter = \OCP\Util::mb_str_replace('%uid', $uid, $this->connection->ldapLoginFilter, 'UTF-8');
- $ldap_users = $this->fetchListOfUsers($filter, 'dn');
+ $filter = \OCP\Util::mb_str_replace('%uid', $uid, $this->access->connection->ldapLoginFilter, 'UTF-8');
+ $ldap_users = $this->access->fetchListOfUsers($filter, 'dn');
if(count($ldap_users) < 1) {
return false;
}
$dn = $ldap_users[0];
//do we have a username for him/her?
- $ocname = $this->dn2username($dn);
+ $ocname = $this->access->dn2username($dn);
if($ocname) {
//update some settings, if necessary
$this->updateEmail($dn);
//are the credentials OK?
- if(!$this->areCredentialsValid($dn, $password)) {
+ if(!$this->access->areCredentialsValid($dn, $password)) {
return false;
}
$cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
//check if users are cached, if so return
- $ldap_users = $this->connection->getFromCache($cachekey);
+ $ldap_users = $this->access->connection->getFromCache($cachekey);
if(!is_null($ldap_users)) {
return $ldap_users;
}
if($limit <= 0) {
$limit = null;
}
- $filter = $this->combineFilterWithAnd(array(
- $this->connection->ldapUserFilter,
- $this->getFilterPartForUserSearch($search)
+ $filter = $this->access->combineFilterWithAnd(array(
+ $this->access->connection->ldapUserFilter,
+ $this->access->getFilterPartForUserSearch($search)
));
\OCP\Util::writeLog('user_ldap',
'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
\OCP\Util::DEBUG);
//do the search and translate results to owncloud names
- $ldap_users = $this->fetchListOfUsers($filter, array($this->connection->ldapUserDisplayName, 'dn'),
+ $ldap_users = $this->access->fetchListOfUsers(
+ $filter,
+ array($this->access->connection->ldapUserDisplayName, 'dn'),
$limit, $offset);
- $ldap_users = $this->ownCloudUserNames($ldap_users);
+ $ldap_users = $this->access->ownCloudUserNames($ldap_users);
\OCP\Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', \OCP\Util::DEBUG);
- $this->connection->writeToCache($cachekey, $ldap_users);
+ $this->access->connection->writeToCache($cachekey, $ldap_users);
return $ldap_users;
}
* @return boolean
*/
public function userExists($uid) {
- if($this->connection->isCached('userExists'.$uid)) {
- return $this->connection->getFromCache('userExists'.$uid);
+ if($this->access->connection->isCached('userExists'.$uid)) {
+ return $this->access->connection->getFromCache('userExists'.$uid);
}
//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
- $dn = $this->username2dn($uid);
+ $dn = $this->access->username2dn($uid);
if(!$dn) {
- $this->connection->writeToCache('userExists'.$uid, false);
+ \OCP\Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.$this->access->connection->ldapHost, \OCP\Util::DEBUG);
+ $this->access->connection->writeToCache('userExists'.$uid, false);
return false;
}
//check if user really still exists by reading its entry
- if(!is_array($this->readAttribute($dn, ''))) {
- $this->connection->writeToCache('userExists'.$uid, false);
+ if(!is_array($this->access->readAttribute($dn, ''))) {
+ \OCP\Util::writeLog('user_ldap', 'LDAP says no user '.$dn, \OCP\Util::DEBUG);
+ $this->access->connection->writeToCache('userExists'.$uid, false);
return false;
}
- $this->connection->writeToCache('userExists'.$uid, true);
+ $this->access->connection->writeToCache('userExists'.$uid, true);
$this->updateQuota($dn);
return true;
}
}
$cacheKey = 'getHome'.$uid;
- if($this->connection->isCached($cacheKey)) {
- return $this->connection->getFromCache($cacheKey);
+ if($this->access->connection->isCached($cacheKey)) {
+ return $this->access->connection->getFromCache($cacheKey);
}
- if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
- $attr = substr($this->connection->homeFolderNamingRule, strlen('attr:'));
- $homedir = $this->readAttribute($this->username2dn($uid), $attr);
+ if(strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0) {
+ $attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
+ $homedir = $this->access->readAttribute(
+ $this->access->username2dn($uid), $attr);
if($homedir && isset($homedir[0])) {
$path = $homedir[0];
//if attribute's value is an absolute path take this, otherwise append it to data dir
$homedir = \OCP\Config::getSystemValue('datadirectory',
\OC::$SERVERROOT.'/data' ) . '/' . $homedir[0];
}
- $this->connection->writeToCache($cacheKey, $homedir);
+ $this->access->connection->writeToCache($cacheKey, $homedir);
return $homedir;
}
}
//false will apply default behaviour as defined and done by OC_User
- $this->connection->writeToCache($cacheKey, false);
+ $this->access->connection->writeToCache($cacheKey, false);
return false;
}
}
$cacheKey = 'getDisplayName'.$uid;
- if(!is_null($displayName = $this->connection->getFromCache($cacheKey))) {
+ if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
return $displayName;
}
- $displayName = $this->readAttribute(
- $this->username2dn($uid),
- $this->connection->ldapUserDisplayName);
+ $displayName = $this->access->readAttribute(
+ $this->access->username2dn($uid),
+ $this->access->connection->ldapUserDisplayName);
if($displayName && (count($displayName) > 0)) {
- $this->connection->writeToCache($cacheKey, $displayName[0]);
+ $this->access->connection->writeToCache($cacheKey, $displayName[0]);
return $displayName[0];
}
*/
public function getDisplayNames($search = '', $limit = null, $offset = null) {
$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
- if(!is_null($displayNames = $this->connection->getFromCache($cacheKey))) {
+ if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
return $displayNames;
}
foreach ($users as $user) {
$displayNames[$user] = $this->getDisplayName($user);
}
- $this->connection->writeToCache($cacheKey, $displayNames);
+ $this->access->connection->writeToCache($cacheKey, $displayNames);
return $displayNames;
}
namespace OCA\user_ldap;
+use OCA\user_ldap\lib\ILDAPWrapper;
+
class User_Proxy extends lib\Proxy implements \OCP\UserInterface {
private $backends = array();
private $refBackend = null;
* @brief Constructor
* @param $serverConfigPrefixes array containing the config Prefixes
*/
- public function __construct($serverConfigPrefixes) {
- parent::__construct();
+ public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap) {
+ parent::__construct($ldap);
foreach($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] = new \OCA\user_ldap\USER_LDAP();
- $connector = $this->getConnector($configPrefix);
- $this->backends[$configPrefix]->setConnector($connector);
+ $this->backends[$configPrefix] = new \OCA\user_ldap\USER_LDAP($this->getAccess($configPrefix));
if(is_null($this->refBackend)) {
$this->refBackend = &$this->backends[$configPrefix];
}