From 6063ce9c8d3f32a7c9d53a0aa77d2cbfa0798f7b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 16 Jan 2013 14:59:41 +0100 Subject: LDAP: enable support for multiple LDAP/AD servers --- apps/user_ldap/appinfo/app.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'apps/user_ldap/appinfo/app.php') diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php index 9e72e388e67..69860ba1432 100644 --- a/apps/user_ldap/appinfo/app.php +++ b/apps/user_ldap/appinfo/app.php @@ -23,11 +23,27 @@ OCP\App::registerAdmin('user_ldap', 'settings'); -$connector = new OCA\user_ldap\lib\Connection('', 'user_ldap'); -$userBackend = new OCA\user_ldap\USER_LDAP(); -$userBackend->setConnector($connector); -$groupBackend = new OCA\user_ldap\GROUP_LDAP(); -$groupBackend->setConnector($connector); +$query = \OCP\DB::prepare(' + SELECT DISTINCT `configkey` + FROM `*PREFIX*appconfig` + WHERE `configkey` LIKE ? +'); +$serverConnections = $query->execute(array('%ldap_login_filter'))->fetchAll(); +if(count($serverConnections) == 1) { + $prefix = substr($serverConnections[0]['configkey'], 0, strlen($serverConnections[0]['configkey'])- strlen('ldap_login_filter')); + $connector = new OCA\user_ldap\lib\Connection($prefix); + $userBackend = new OCA\user_ldap\USER_LDAP(); + $userBackend->setConnector($connector); + $groupBackend = new OCA\user_ldap\GROUP_LDAP(); + $groupBackend->setConnector($connector); +} else { + $prefixes = array(); + foreach($serverConnections as $serverConnection) { + $prefixes[] = substr($serverConnection['configkey'], 0, strlen($serverConnection['configkey'])- strlen('ldap_login_filter')); + } + $userBackend = new OCA\user_ldap\User_Proxy($prefixes); + $groupBackend = new OCA\user_ldap\Group_Proxy($prefixes); +} // register user backend OC_User::useBackend($userBackend); -- cgit v1.2.3