aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-12-17 13:07:21 +0100
committerGitHub <noreply@github.com>2018-12-17 13:07:21 +0100
commite7950a5bd6b8736f6fb16c67f2230b631806007b (patch)
tree7827ea10922d4b4ca0fee77873b9129145facbc8 /apps
parentc4a9bd11b93a8855a5f303002eecee12dde9d1d6 (diff)
parentfeb5366a428e25ebb6054c4a3d0bc6ea304bb295 (diff)
downloadnextcloud-server-e7950a5bd6b8736f6fb16c67f2230b631806007b.tar.gz
nextcloud-server-e7950a5bd6b8736f6fb16c67f2230b631806007b.zip
Merge pull request #12693 from nextcloud/fix/11474/fix-first-ldap-login
fix exception on LDAP mapping during login
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CardDAV/SyncService.php2
-rw-r--r--apps/dav/lib/HookManager.php4
-rw-r--r--apps/user_ldap/lib/Access.php44
-rw-r--r--apps/user_ldap/lib/AppInfo/Application.php6
-rw-r--r--apps/user_ldap/lib/Command/SetConfig.php5
-rw-r--r--apps/user_ldap/lib/Controller/ConfigAPIController.php9
6 files changed, 53 insertions, 17 deletions
diff --git a/apps/dav/lib/CardDAV/SyncService.php b/apps/dav/lib/CardDAV/SyncService.php
index 5bd92015ad7..6f6fa0ba379 100644
--- a/apps/dav/lib/CardDAV/SyncService.php
+++ b/apps/dav/lib/CardDAV/SyncService.php
@@ -261,7 +261,7 @@ class SyncService {
/**
* @param IUser $user
*/
- public function updateUser($user) {
+ public function updateUser(IUser $user) {
$systemAddressBook = $this->getLocalSystemAddressBook();
$addressBookId = $systemAddressBook['id'];
$converter = new Converter($this->accountManager);
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php
index b1bd039c65e..27b6525be47 100644
--- a/apps/dav/lib/HookManager.php
+++ b/apps/dav/lib/HookManager.php
@@ -101,7 +101,9 @@ class HookManager {
public function postCreateUser($params) {
$user = $this->userManager->get($params['uid']);
- $this->syncService->updateUser($user);
+ if ($user instanceof IUser) {
+ $this->syncService->updateUser($user);
+ }
}
public function preDeleteUser($params) {
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 82947bd6868..6fe2c155416 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -609,26 +609,25 @@ class Access extends LDAPUtility {
// outside of core user management will still cache the user as non-existing.
$originalTTL = $this->connection->ldapCacheTTL;
$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
- if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
- || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
- if($mapper->map($fdn, $intName, $uuid)) {
- $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
- if($this->ncUserManager instanceof PublicEmitter && $isUser) {
- $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
- }
- $newlyMapped = true;
+ if( $intName !== ''
+ && (($isUser && !$this->ncUserManager->userExists($intName))
+ || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
+ )
+ ) {
+ $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
+ $newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
+ if($newlyMapped) {
return $intName;
}
}
- $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
+ $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
- if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
- if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
- $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$altName]);
+ if (is_string($altName)) {
+ if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
+ $newlyMapped = true;
+ return $altName;
}
- $newlyMapped = true;
- return $altName;
}
//if everything else did not help..
@@ -636,6 +635,23 @@ class Access extends LDAPUtility {
return false;
}
+ protected function mapAndAnnounceIfApplicable(
+ AbstractMapping $mapper,
+ string $fdn,
+ string $name,
+ string $uuid,
+ bool $isUser
+ ) :bool {
+ if($mapper->map($fdn, $name, $uuid)) {
+ if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
+ $this->cacheUserExists($name);
+ $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
+ }
+ return true;
+ }
+ return false;
+ }
+
/**
* gives back the user names as they are used ownClod internally
* @param array $ldapUsers as returned by fetchList()
diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php
index 6d5c416f04f..59d7cdb4924 100644
--- a/apps/user_ldap/lib/AppInfo/Application.php
+++ b/apps/user_ldap/lib/AppInfo/Application.php
@@ -24,6 +24,8 @@
namespace OCA\User_LDAP\AppInfo;
use OCA\User_LDAP\Controller\RenewPasswordController;
+use OCA\User_LDAP\ILDAPWrapper;
+use OCA\User_LDAP\LDAP;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\IL10N;
@@ -50,5 +52,9 @@ class Application extends App {
$server->getURLGenerator()
);
});
+
+ $container->registerService(ILDAPWrapper::class, function () {
+ return new LDAP();
+ });
}
}
diff --git a/apps/user_ldap/lib/Command/SetConfig.php b/apps/user_ldap/lib/Command/SetConfig.php
index db656558efc..cf73874ade8 100644
--- a/apps/user_ldap/lib/Command/SetConfig.php
+++ b/apps/user_ldap/lib/Command/SetConfig.php
@@ -26,6 +26,8 @@
namespace OCA\User_LDAP\Command;
+use OCA\User_LDAP\ConnectionFactory;
+use OCA\User_LDAP\LDAP;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -83,5 +85,8 @@ class SetConfig extends Command {
$configHolder = new Configuration($configID);
$configHolder->$key = $value;
$configHolder->saveConfiguration();
+
+ $connectionFactory = new ConnectionFactory(new LDAP());
+ $connectionFactory->get($configID)->clearCache();
}
}
diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php
index a745e4ce060..ce885b7dabb 100644
--- a/apps/user_ldap/lib/Controller/ConfigAPIController.php
+++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php
@@ -27,6 +27,7 @@ use OC\CapabilitiesManager;
use OC\Core\Controller\OCSController;
use OC\Security\IdentityProof\Manager;
use OCA\User_LDAP\Configuration;
+use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
@@ -45,6 +46,9 @@ class ConfigAPIController extends OCSController {
/** @var ILogger */
private $logger;
+ /** @var ConnectionFactory */
+ private $connectionFactory;
+
public function __construct(
$appName,
IRequest $request,
@@ -53,7 +57,8 @@ class ConfigAPIController extends OCSController {
IUserManager $userManager,
Manager $keyManager,
Helper $ldapHelper,
- ILogger $logger
+ ILogger $logger,
+ ConnectionFactory $connectionFactory
) {
parent::__construct(
$appName,
@@ -67,6 +72,7 @@ class ConfigAPIController extends OCSController {
$this->ldapHelper = $ldapHelper;
$this->logger = $logger;
+ $this->connectionFactory = $connectionFactory;
}
/**
@@ -198,6 +204,7 @@ class ConfigAPIController extends OCSController {
}
$configuration->saveConfiguration();
+ $this->connectionFactory->get($configID)->clearCache();
} catch(OCSException $e) {
throw $e;
} catch (\Exception $e) {