LDAP: enable support for multiple LDAP/AD servers

This commit is contained in:
Arthur Schiwon 2013-01-16 14:59:41 +01:00
parent 4699f36e44
commit 6063ce9c8d

View file

@ -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);