Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/user_ldap/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ A user logs into Nextcloud with their LDAP or AD credentials, and is granted acc
</post-migration>
</repair-steps>

<commands>
<command>OCA\User_LDAP\Command\CheckUser</command>
<command>OCA\User_LDAP\Command\CreateEmptyConfig</command>
<command>OCA\User_LDAP\Command\DeleteConfig</command>
<command>OCA\User_LDAP\Command\Search</command>
<command>OCA\User_LDAP\Command\SetConfig</command>
<command>OCA\User_LDAP\Command\ShowConfig</command>
<command>OCA\User_LDAP\Command\ShowRemnants</command>
<command>OCA\User_LDAP\Command\TestConfig</command>
</commands>

<settings>
<admin>OCA\User_LDAP\Settings\Admin</admin>
<admin-section>OCA\User_LDAP\Settings\Section</admin-section>
Expand Down
61 changes: 0 additions & 61 deletions apps/user_ldap/appinfo/register_command.php

This file was deleted.

27 changes: 10 additions & 17 deletions apps/user_ldap/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\IAppContainer;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -86,28 +84,23 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {
$context->injectFn(function (IConfig $config,
INotificationManager $notificationManager,
IUserSession $userSession,
IAppContainer $appContainer,
EventDispatcherInterface $legacyDispatcher,
IEventDispatcher $dispatcher,
IGroupManager $groupManager) {
$helper = new Helper($config);
$context->injectFn(function (
INotificationManager $notificationManager,
IAppContainer $appContainer,
EventDispatcherInterface $legacyDispatcher,
IEventDispatcher $dispatcher,
IGroupManager $groupManager,
User_Proxy $userBackend,
Group_Proxy $groupBackend,
Helper $helper
) {
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
if (count($configPrefixes) > 0) {
$ldapWrapper = new LDAP();

$notificationManager->registerNotifierService(Notifier::class);

$userPluginManager = $appContainer->get(UserPluginManager::class);
$groupPluginManager = $appContainer->get(GroupPluginManager::class);

$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager
);
$groupBackend = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager);

\OC_User::useBackend($userBackend);
$groupManager->addBackend($groupBackend);

Expand Down
26 changes: 10 additions & 16 deletions apps/user_ldap/lib/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
namespace OCA\User_LDAP\Command;

use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User_Proxy;
use OCA\User_LDAP\UserPluginManager;
use OCP\IConfig;

use Symfony\Component\Console\Command\Command;
Expand All @@ -45,13 +43,16 @@
class Search extends Command {
/** @var \OCP\IConfig */
protected $ocConfig;
/** @var User_Proxy */
private $userProxy;
/** @var Group_Proxy */
private $groupProxy;

/**
* @param \OCP\IConfig $ocConfig
*/
public function __construct(IConfig $ocConfig) {
$this->ocConfig = $ocConfig;
public function __construct(IConfig $ocConfig, User_Proxy $userProxy, Group_Proxy $groupProxy) {
parent::__construct();
$this->ocConfig = $ocConfig;
$this->userProxy = $userProxy;
$this->groupProxy = $groupProxy;
}

protected function configure() {
Expand Down Expand Up @@ -117,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->validateOffsetAndLimit($offset, $limit);

if ($input->getOption('group')) {
$proxy = new Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query(GroupPluginManager::class));
$proxy = $this->groupProxy;
$getMethod = 'getGroups';
$printID = false;
// convert the limit of groups to null. This will show all the groups available instead of
Expand All @@ -126,14 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$limit = null;
}
} else {
$proxy = new User_Proxy(
$configPrefixes,
$ldapWrapper,
$this->ocConfig,
\OC::$server->getNotificationManager(),
\OC::$server->getUserSession(),
\OC::$server->query(UserPluginManager::class)
);
$proxy = $this->userProxy;
$getMethod = 'getDisplayNames';
$printID = true;
}
Expand Down
8 changes: 2 additions & 6 deletions apps/user_ldap/lib/Group_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
private $backends = [];
private $refBackend = null;

/**
* Constructor
*
* @param string[] $serverConfigPrefixes array containing the config Prefixes
*/
public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
public function __construct(Helper $helper, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
parent::__construct($ldap);
$serverConfigPrefixes = $helper->getServerConfigurationPrefixes(true);
foreach ($serverConfigPrefixes as $configPrefix) {
$this->backends[$configPrefix] =
new \OCA\User_LDAP\Group_LDAP($this->getAccess($configPrefix), $groupPluginManager);
Expand Down
26 changes: 3 additions & 23 deletions apps/user_ldap/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(IConfig $config) {
* except the default (first) server shall be connected to.
*
*/
public function getServerConfigurationPrefixes($activeConfigurations = false) {
public function getServerConfigurationPrefixes($activeConfigurations = false): array {
$referenceConfigkey = 'ldap_configuration_active';

$keys = $this->getServersConfig($referenceConfigkey);
Expand Down Expand Up @@ -188,18 +188,11 @@ public function deleteServerConfiguration($prefix) {

/**
* checks whether there is one or more disabled LDAP configurations
*
* @return bool
* @throws \Exception
*/
public function haveDisabledConfigurations() {
public function haveDisabledConfigurations(): bool {
$all = $this->getServerConfigurationPrefixes(false);
$active = $this->getServerConfigurationPrefixes(true);

if (!is_array($all) || !is_array($active)) {
throw new \Exception('Unexpected Return Value');
}

return count($all) !== count($active) || count($all) === 0;
}

Expand Down Expand Up @@ -312,20 +305,7 @@ public static function loginName2UserName($param) {
throw new \Exception('key uid is expected to be set in $param');
}

//ain't it ironic?
$helper = new Helper(\OC::$server->getConfig());

$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
$ocConfig = \OC::$server->getConfig();
$notificationManager = \OC::$server->getNotificationManager();

$userSession = \OC::$server->getUserSession();
$userPluginManager = \OC::$server->query(UserPluginManager::class);

$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
);
$userBackend = \OC::$server->get(User_Proxy::class);
$uid = $userBackend->loginName2UserName($param['uid']);
if ($uid !== false) {
$param['uid'] = $uid;
Expand Down
13 changes: 2 additions & 11 deletions apps/user_ldap/lib/Jobs/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\User_Proxy;
use OCA\User_LDAP\UserPluginManager;

/**
* Class CleanUp
Expand Down Expand Up @@ -69,10 +68,11 @@ class CleanUp extends TimedJob {
/** @var DeletedUsersIndex */
protected $dui;

public function __construct() {
public function __construct(User_Proxy $userBackend) {
$minutes = \OC::$server->getConfig()->getSystemValue(
'ldapUserCleanupInterval', (string)$this->defaultIntervalMin);
$this->setInterval((int)$minutes * 60);
$this->userBackend = $userBackend;
}

/**
Expand All @@ -99,15 +99,6 @@ public function setArguments($arguments) {

if (isset($arguments['userBackend'])) {
$this->userBackend = $arguments['userBackend'];
} else {
$this->userBackend = new User_Proxy(
$this->ldapHelper->getServerConfigurationPrefixes(true),
new LDAP(),
$this->ocConfig,
\OC::$server->getNotificationManager(),
\OC::$server->getUserSession(),
\OC::$server->query(UserPluginManager::class)
);
}

if (isset($arguments['db'])) {
Expand Down
Loading