DI for NC's user manager
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
373a1d5391
commit
f1565336bd
6 changed files with 35 additions and 14 deletions
|
@ -44,6 +44,7 @@
|
|||
namespace OCA\User_LDAP;
|
||||
|
||||
use OC\HintException;
|
||||
use OC\Hooks\PublicEmitter;
|
||||
use OCA\User_LDAP\Exceptions\ConstraintViolationException;
|
||||
use OCA\User_LDAP\User\IUserTools;
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
|
@ -52,6 +53,7 @@ use OCA\User_LDAP\Mapping\AbstractMapping;
|
|||
|
||||
use OC\ServerNotAvailableException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Util;
|
||||
|
||||
/**
|
||||
|
@ -95,13 +97,16 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
private $helper;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IUserManager */
|
||||
private $ncUserManager;
|
||||
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
ILDAPWrapper $ldap,
|
||||
Manager $userManager,
|
||||
Helper $helper,
|
||||
IConfig $config
|
||||
IConfig $config,
|
||||
IUserManager $ncUserManager
|
||||
) {
|
||||
parent::__construct($ldap);
|
||||
$this->connection = $connection;
|
||||
|
@ -109,6 +114,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
$this->userManager->setLdapAccess($this);
|
||||
$this->helper = $helper;
|
||||
$this->config = $config;
|
||||
$this->ncUserManager = $ncUserManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -605,11 +611,13 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
// outside of core user management will still cache the user as non-existing.
|
||||
$originalTTL = $this->connection->ldapCacheTTL;
|
||||
$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
|
||||
if(($isUser && $intName !== '' && !\OC::$server->getUserManager()->userExists($intName))
|
||||
if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
|
||||
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
|
||||
if($mapper->map($fdn, $intName, $uuid)) {
|
||||
$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
|
||||
\OC::$server->getUserManager()->emit('\OC\User', 'assignedUserId', [$intName]);
|
||||
if($this->ncUserManager instanceof PublicEmitter) {
|
||||
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
|
||||
}
|
||||
$newlyMapped = true;
|
||||
return $intName;
|
||||
}
|
||||
|
@ -618,7 +626,9 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
|
||||
$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
|
||||
if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
|
||||
\OC::$server->getUserManager()->emit('\OC\User', 'assignedUserId', [$intName]);
|
||||
if($this->ncUserManager instanceof PublicEmitter) {
|
||||
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
|
||||
}
|
||||
$newlyMapped = true;
|
||||
return $altName;
|
||||
}
|
||||
|
@ -740,7 +750,7 @@ class Access extends LDAPUtility implements IUserTools {
|
|||
//20 attempts, something else is very wrong. Avoids infinite loop.
|
||||
while($attempts < 20){
|
||||
$altName = $name . '_' . rand(1000,9999);
|
||||
if(!\OC::$server->getUserManager()->userExists($altName)) {
|
||||
if(!$this->ncUserManager->userExists($altName)) {
|
||||
return $altName;
|
||||
}
|
||||
$attempts++;
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace OCA\User_LDAP;
|
|||
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class AccessFactory {
|
||||
/** @var ILDAPWrapper */
|
||||
|
@ -36,17 +37,21 @@ class AccessFactory {
|
|||
protected $helper;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
/** @var IUserManager */
|
||||
private $ncUserManager;
|
||||
|
||||
public function __construct(
|
||||
ILDAPWrapper $ldap,
|
||||
Manager $userManager,
|
||||
Helper $helper,
|
||||
IConfig $config)
|
||||
IConfig $config,
|
||||
IUserManager $ncUserManager)
|
||||
{
|
||||
$this->ldap = $ldap;
|
||||
$this->userManager = $userManager;
|
||||
$this->helper = $helper;
|
||||
$this->config = $config;
|
||||
$this->ncUserManager = $ncUserManager;
|
||||
}
|
||||
|
||||
public function get(Connection $connection) {
|
||||
|
@ -55,7 +60,8 @@ class AccessFactory {
|
|||
$this->ldap,
|
||||
$this->userManager,
|
||||
$this->helper,
|
||||
$this->config
|
||||
$this->config,
|
||||
$this->ncUserManager
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -376,7 +376,8 @@ class Sync extends TimedJob {
|
|||
$this->ldap,
|
||||
$this->userManager,
|
||||
$this->ldapHelper,
|
||||
$this->config
|
||||
$this->config,
|
||||
$this->ncUserManager
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
|
|||
\OC::$server->getUserManager(),
|
||||
\OC::$server->getNotificationManager());
|
||||
$connector = new Connection($ldapWrapper, $configPrefixes[0]);
|
||||
$ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper, \OC::$server->getConfig());
|
||||
$ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper, \OC::$server->getConfig(), \OC::$server->getUserManager());
|
||||
$groupMapper = new GroupMapping($dbc);
|
||||
$userMapper = new UserMapping($dbc);
|
||||
$ldapAccess->setGroupMapper($groupMapper);
|
||||
|
|
|
@ -82,7 +82,7 @@ abstract class Proxy {
|
|||
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
|
||||
$coreUserManager, $coreNotificationManager);
|
||||
$connector = new Connection($this->ldap, $configPrefix);
|
||||
$access = new Access($connector, $this->ldap, $userManager, new Helper($ocConfig), $ocConfig);
|
||||
$access = new Access($connector, $this->ldap, $userManager, new Helper($ocConfig), $ocConfig, $coreUserManager);
|
||||
$access->setUserMapper($userMap);
|
||||
$access->setGroupMapper($groupMap);
|
||||
self::$accesses[$configPrefix] = $access;
|
||||
|
|
|
@ -72,6 +72,8 @@ class AccessTest extends TestCase {
|
|||
private $helper;
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $config;
|
||||
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $ncUserManager;
|
||||
/** @var Access */
|
||||
private $access;
|
||||
|
||||
|
@ -82,13 +84,15 @@ class AccessTest extends TestCase {
|
|||
$this->helper = $this->createMock(Helper::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->userMapper = $this->createMock(UserMapping::class);
|
||||
$this->ncUserManager = $this->createMock(IUserManager::class);
|
||||
|
||||
$this->access = new Access(
|
||||
$this->connection,
|
||||
$this->ldap,
|
||||
$this->userManager,
|
||||
$this->helper,
|
||||
$this->config
|
||||
$this->config,
|
||||
$this->ncUserManager
|
||||
);
|
||||
$this->access->setUserMapper($this->userMapper);
|
||||
}
|
||||
|
@ -227,7 +231,7 @@ class AccessTest extends TestCase {
|
|||
list($lw, $con, $um, $helper) = $this->getConnectorAndLdapMock();
|
||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$access = new Access($con, $lw, $um, $helper, $config);
|
||||
$access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager);
|
||||
|
||||
$lw->expects($this->exactly(1))
|
||||
->method('explodeDN')
|
||||
|
@ -250,7 +254,7 @@ class AccessTest extends TestCase {
|
|||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$lw = new LDAP();
|
||||
$access = new Access($con, $lw, $um, $helper, $config);
|
||||
$access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager);
|
||||
|
||||
if(!function_exists('ldap_explode_dn')) {
|
||||
$this->markTestSkipped('LDAP Module not available');
|
||||
|
@ -431,7 +435,7 @@ class AccessTest extends TestCase {
|
|||
$attribute => array('count' => 1, $dnFromServer)
|
||||
)));
|
||||
|
||||
$access = new Access($con, $lw, $um, $helper, $config);
|
||||
$access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager);
|
||||
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
|
||||
$this->assertSame($values[0], strtolower($dnFromServer));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue