Skip to content

Commit e7950a5

Browse files
authored
Merge pull request #12693 from nextcloud/fix/11474/fix-first-ldap-login
fix exception on LDAP mapping during login
2 parents c4a9bd1 + feb5366 commit e7950a5

File tree

7 files changed

+71
-17
lines changed

7 files changed

+71
-17
lines changed

.drone.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ pipeline:
629629
image: nextcloudci/integration-php7.0:integration-php7.0-6
630630
commands:
631631
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
632+
- ./occ config:system:set redis host --value=cache
633+
- ./occ config:system:set redis port --value=6379 --type=integer
634+
- ./occ config:system:set redis timeout --value=0 --type=integer
635+
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.local
636+
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.distributed
632637
- ./occ app:enable user_ldap
633638
- cd build/integration
634639
- ./run.sh ldap_features/ldap-openldap.feature
@@ -639,6 +644,11 @@ pipeline:
639644
image: nextcloudci/integration-php7.0:integration-php7.0-6
640645
commands:
641646
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
647+
- ./occ config:system:set redis host --value=cache
648+
- ./occ config:system:set redis port --value=6379 --type=integer
649+
- ./occ config:system:set redis timeout --value=0 --type=integer
650+
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.local
651+
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.distributed
642652
- ./occ app:enable user_ldap
643653
- cd build/integration
644654
- ./run.sh ldap_features/openldap-uid-username.feature
@@ -649,6 +659,11 @@ pipeline:
649659
image: nextcloudci/integration-php7.0:integration-php7.0-6
650660
commands:
651661
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
662+
- ./occ config:system:set redis host --value=cache
663+
- ./occ config:system:set redis port --value=6379 --type=integer
664+
- ./occ config:system:set redis timeout --value=0 --type=integer
665+
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.local
666+
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.distributed
652667
- ./occ app:enable user_ldap
653668
- cd build/integration
654669
- ./run.sh ldap_features/openldap-numerical-id.feature
@@ -958,10 +973,13 @@ matrix:
958973
- TESTS: integration-ldap-features
959974
- TESTS: integration-ldap-openldap-features
960975
ENABLE_OPENLDAP: true
976+
ENABLE_REDIS: true
961977
- TESTS: integration-ldap-openldap-uid-features
962978
ENABLE_OPENLDAP: true
979+
ENABLE_REDIS: true
963980
- TESTS: integration-ldap-openldap-numerical-id-features
964981
ENABLE_OPENLDAP: true
982+
ENABLE_REDIS: true
965983
- TESTS: integration-trashbin
966984
- TESTS: integration-remote-api
967985
- TESTS: integration-download

apps/dav/lib/CardDAV/SyncService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private function parseMultiStatus($body) {
261261
/**
262262
* @param IUser $user
263263
*/
264-
public function updateUser($user) {
264+
public function updateUser(IUser $user) {
265265
$systemAddressBook = $this->getLocalSystemAddressBook();
266266
$addressBookId = $systemAddressBook['id'];
267267
$converter = new Converter($this->accountManager);

apps/dav/lib/HookManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ public function setup() {
101101

102102
public function postCreateUser($params) {
103103
$user = $this->userManager->get($params['uid']);
104-
$this->syncService->updateUser($user);
104+
if ($user instanceof IUser) {
105+
$this->syncService->updateUser($user);
106+
}
105107
}
106108

107109
public function preDeleteUser($params) {

apps/user_ldap/lib/Access.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -609,33 +609,49 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped
609609
// outside of core user management will still cache the user as non-existing.
610610
$originalTTL = $this->connection->ldapCacheTTL;
611611
$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
612-
if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
613-
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
614-
if($mapper->map($fdn, $intName, $uuid)) {
615-
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
616-
if($this->ncUserManager instanceof PublicEmitter && $isUser) {
617-
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
618-
}
619-
$newlyMapped = true;
612+
if( $intName !== ''
613+
&& (($isUser && !$this->ncUserManager->userExists($intName))
614+
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
615+
)
616+
) {
617+
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
618+
$newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
619+
if($newlyMapped) {
620620
return $intName;
621621
}
622622
}
623-
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
624623

624+
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
625625
$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
626-
if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
627-
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
628-
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$altName]);
626+
if (is_string($altName)) {
627+
if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
628+
$newlyMapped = true;
629+
return $altName;
629630
}
630-
$newlyMapped = true;
631-
return $altName;
632631
}
633632

634633
//if everything else did not help..
635634
\OCP\Util::writeLog('user_ldap', 'Could not create unique name for '.$fdn.'.', ILogger::INFO);
636635
return false;
637636
}
638637

638+
protected function mapAndAnnounceIfApplicable(
639+
AbstractMapping $mapper,
640+
string $fdn,
641+
string $name,
642+
string $uuid,
643+
bool $isUser
644+
) :bool {
645+
if($mapper->map($fdn, $name, $uuid)) {
646+
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
647+
$this->cacheUserExists($name);
648+
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
649+
}
650+
return true;
651+
}
652+
return false;
653+
}
654+
639655
/**
640656
* gives back the user names as they are used ownClod internally
641657
* @param array $ldapUsers as returned by fetchList()

apps/user_ldap/lib/AppInfo/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
namespace OCA\User_LDAP\AppInfo;
2525

2626
use OCA\User_LDAP\Controller\RenewPasswordController;
27+
use OCA\User_LDAP\ILDAPWrapper;
28+
use OCA\User_LDAP\LDAP;
2729
use OCP\AppFramework\App;
2830
use OCP\AppFramework\IAppContainer;
2931
use OCP\IL10N;
@@ -50,5 +52,9 @@ public function __construct () {
5052
$server->getURLGenerator()
5153
);
5254
});
55+
56+
$container->registerService(ILDAPWrapper::class, function () {
57+
return new LDAP();
58+
});
5359
}
5460
}

apps/user_ldap/lib/Command/SetConfig.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
namespace OCA\User_LDAP\Command;
2828

29+
use OCA\User_LDAP\ConnectionFactory;
30+
use OCA\User_LDAP\LDAP;
2931
use Symfony\Component\Console\Command\Command;
3032
use Symfony\Component\Console\Input\InputArgument;
3133
use Symfony\Component\Console\Input\InputInterface;
@@ -83,5 +85,8 @@ protected function setValue($configID, $key, $value) {
8385
$configHolder = new Configuration($configID);
8486
$configHolder->$key = $value;
8587
$configHolder->saveConfiguration();
88+
89+
$connectionFactory = new ConnectionFactory(new LDAP());
90+
$connectionFactory->get($configID)->clearCache();
8691
}
8792
}

apps/user_ldap/lib/Controller/ConfigAPIController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OC\Core\Controller\OCSController;
2828
use OC\Security\IdentityProof\Manager;
2929
use OCA\User_LDAP\Configuration;
30+
use OCA\User_LDAP\ConnectionFactory;
3031
use OCA\User_LDAP\Helper;
3132
use OCP\AppFramework\Http\DataResponse;
3233
use OCP\AppFramework\OCS\OCSBadRequestException;
@@ -45,6 +46,9 @@ class ConfigAPIController extends OCSController {
4546
/** @var ILogger */
4647
private $logger;
4748

49+
/** @var ConnectionFactory */
50+
private $connectionFactory;
51+
4852
public function __construct(
4953
$appName,
5054
IRequest $request,
@@ -53,7 +57,8 @@ public function __construct(
5357
IUserManager $userManager,
5458
Manager $keyManager,
5559
Helper $ldapHelper,
56-
ILogger $logger
60+
ILogger $logger,
61+
ConnectionFactory $connectionFactory
5762
) {
5863
parent::__construct(
5964
$appName,
@@ -67,6 +72,7 @@ public function __construct(
6772

6873
$this->ldapHelper = $ldapHelper;
6974
$this->logger = $logger;
75+
$this->connectionFactory = $connectionFactory;
7076
}
7177

7278
/**
@@ -198,6 +204,7 @@ public function modify($configID, $configData) {
198204
}
199205

200206
$configuration->saveConfiguration();
207+
$this->connectionFactory->get($configID)->clearCache();
201208
} catch(OCSException $e) {
202209
throw $e;
203210
} catch (\Exception $e) {

0 commit comments

Comments
 (0)