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
6 changes: 0 additions & 6 deletions appinfo/app.php

This file was deleted.

2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<screenshot>https://raw.githubusercontent.com/nextcloud/ldap_write_support/master/img/screenshots/settings.png</screenshot>
<screenshot>https://raw.githubusercontent.com/nextcloud/ldap_write_support/master/img/screenshots/users.png</screenshot>
<dependencies>
<nextcloud min-version="20" max-version="20"/>
<nextcloud min-version="20" max-version="21"/>
</dependencies>
<commands>
<command>OCA\LdapWriteSupport\Command\GroupAdminsToLdap</command>
Expand Down
84 changes: 14 additions & 70 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,35 @@

namespace OCA\LdapWriteSupport\AppInfo;

use Exception;
use OC;
use OC\Group\Group;
use OC\User\User;
use OCA\LdapWriteSupport\LDAPConnect;
use OCA\LdapWriteSupport\LDAPUserManager;
use OCA\LdapWriteSupport\LDAPGroupManager;
use OCA\LdapWriteSupport\Service\Configuration;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\UserPluginManager;
use OCA\LdapWriteSupport\Listener\UserBackendRegisteredListener;
use OCA\LdapWriteSupport\Listener\GroupBackendRegisteredListener;
use OCA\User_LDAP\Events\GroupBackendRegistered;
use OCA\User_LDAP\Events\UserBackendRegistered;
use OCP\AppFramework\App;
use OCP\AppFramework\QueryException;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;

class Application extends App {
class Application extends App implements IBootstrap {
/** @var LDAPUserManager */
protected $ldapUserManager;

/** @var LDAPGroupManager */
protected $ldapGroupManager;

/** @var bool */
protected $ldapEnabled = false;

const APP_ID = 'ldap_write_support';
public const APP_ID = 'ldap_write_support';

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
$this->ldapEnabled = OC::$server->getAppManager()->isEnabledForUser('user_ldap');
}

/**
* @throws QueryException
* @throws Exception
*/
public function registerLDAPPlugins(): void {
if(!$this->ldapEnabled) {
return;
}

if(!\OC_App::isAppLoaded('user_ldap')) {
\OC_App::loadApp('user_ldap');
}
$c = $this->getContainer();
$s = $this->getContainer()->getServer();
try {
$provider = $s->getLDAPProvider();
} catch (\Exception $e) {
if(strpos($e->getMessage(), 'user_ldap app must be enabled') !== false) {
$s->getLogger()->info (
'Not registering plugins, because there are no active LDAP configs',
['app' => self::APP_ID]
);
return;
}
throw $e;
}

$ldapConnect = new LDAPConnect($s->query(Helper::class), $s->getLogger());

// resolving LDAP provider fails indeed
$this->ldapUserManager = new LDAPUserManager(
$s->getUserManager(),
$s->getUserSession(),
$ldapConnect,
$provider,
$c->query(Configuration::class),
$s->getL10N(self::APP_ID),
$s->getLogger()
);

$this->ldapGroupManager = new LDAPGroupManager(
$s->getGroupManager(),
$ldapConnect,
$s->getLogger(),
$provider
);

/** @var UserPluginManager $userPluginManager */
$userPluginManager = OC::$server->query(UserPluginManager::class);
/** @var GroupPluginManager $groupPluginManager */
$groupPluginManager = OC::$server->query(GroupPluginManager::class);

$userPluginManager->register($this->ldapUserManager);
$groupPluginManager->register($this->ldapGroupManager);
public function register(IRegistrationContext $context): void {
$context->registerEventListener(UserBackendRegistered::class, UserBackendRegisteredListener::class);
$context->registerEventListener(GroupBackendRegistered::class, GroupBackendRegisteredListener::class);
}

public function boot(IBootContext $context): void {
}
}
4 changes: 2 additions & 2 deletions lib/LDAPGroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class LDAPGroupManager implements ILDAPGroupPlugin {
/** @var ILogger */
private $logger;

public function __construct(IGroupManager $groupManager, LDAPConnect $ldapConnect, ILogger $logger, ILDAPProvider $ldapProvider) {
public function __construct(IGroupManager $groupManager, LDAPConnect $ldapConnect, ILogger $logger, ILDAPProvider $LDAPProvider) {
$this->groupManager = $groupManager;
$this->ldapConnect = $ldapConnect;
$this->logger = $logger;
$this->ldapProvider = $ldapProvider;
$this->ldapProvider = $LDAPProvider;

if($this->ldapConnect->groupsEnabled()) {
$this->makeLdapBackendFirst();
Expand Down
4 changes: 2 additions & 2 deletions lib/LDAPUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class LDAPUserManager implements ILDAPUserPlugin {
* @param IL10N $l10n
* @param ILogger $logger
*/
public function __construct(IUserManager $userManager, IUserSession $userSession, LDAPConnect $ldapConnect, ILDAPProvider $ldapProvider, Configuration $configuration, IL10N $l10n, ILogger $logger) {
public function __construct(IUserManager $userManager, IUserSession $userSession, LDAPConnect $ldapConnect, ILDAPProvider $LDAPProvider, Configuration $configuration, IL10N $l10n, ILogger $logger) {
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->ldapConnect = $ldapConnect;
$this->ldapProvider = $ldapProvider;
$this->ldapProvider = $LDAPProvider;
$this->configuration = $configuration;
$this->l10n = $l10n;
$this->logger = $logger;
Expand Down
57 changes: 57 additions & 0 deletions lib/Listener/GroupBackendRegisteredListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\LdapWriteSupport\Listener;

use OCA\LdapWriteSupport\LDAPGroupManager;
use OCA\User_LDAP\Events\GroupBackendRegistered;
use OCP\App\IAppManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class GroupBackendRegisteredListener implements IEventListener {

/** @var IAppManager */
private $appManager;
/** @var LDAPGroupManager */
private $ldapGroupManager;

public function __construct(IAppManager $appManager, LDAPGroupManager $ldapGroupManager) {
$this->appManager = $appManager;
$this->ldapGroupManager = $ldapGroupManager;
}

/**
* @inheritDoc
*/
public function handle(Event $event): void {
if (!$event instanceof GroupBackendRegistered
|| !$this->appManager->isEnabledForUser('user_ldap')
) {
return;
}
$event->getPluginManager()->register($this->ldapGroupManager);
}
}
57 changes: 57 additions & 0 deletions lib/Listener/UserBackendRegisteredListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\LdapWriteSupport\Listener;

use OCA\LdapWriteSupport\LDAPUserManager;
use OCA\User_LDAP\Events\UserBackendRegistered;
use OCP\App\IAppManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class UserBackendRegisteredListener implements IEventListener {

/** @var IAppManager */
private $appManager;
/** @var LDAPUserManager */
private $ldapUserManager;

public function __construct(IAppManager $appManager, LDAPUserManager $ldapUserManager) {
$this->appManager = $appManager;
$this->ldapUserManager = $ldapUserManager;
}

/**
* @inheritDoc
*/
public function handle(Event $event): void {
if (!$event instanceof UserBackendRegistered
|| !$this->appManager->isEnabledForUser('user_ldap')
) {
return;
}
$event->getPluginManager()->register($this->ldapUserManager);
}
}