Loading lib/AppInfo/Application.php +0 −3 Original line number Diff line number Diff line Loading @@ -31,8 +31,6 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\User\Events\UserDeletedEvent; use OCA\EcloudAccounts\Listeners\UserDeletedListener; use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Service\LDAPConnectionService; use OCP\User\Events\BeforeUserDeletedEvent; Loading @@ -52,7 +50,6 @@ class Application extends App implements IBootstrap public function register(IRegistrationContext $context): void { $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); } Loading lib/Db/MailboxMapper.php +11 −3 Original line number Diff line number Diff line Loading @@ -19,10 +19,18 @@ class MailboxMapper { $this->config = $config; $this->logger = $logger; $this->initConnection(); } private function initConnection() { try { $params = $this->getConnectionParams(); $this->conn = DriverManager::getConnection($params); } catch(Exception $e) { $this->logger->info('Error connecting to SQL raw backend: ' . $e->getMessage()); } } private function getConnectionParams() { Loading lib/Listeners/BeforeUserDeletedListener.php +61 −1 Original line number Diff line number Diff line Loading @@ -5,12 +5,16 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; use Exception; use Curl; use OCA\EcloudAccounts\AppInfo\Application; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\ILogger; use OCP\User\Events\BeforeUserDeletedEvent; use OCA\EcloudAccounts\Service\LDAPConnectionService; require_once 'curl.class.php'; class BeforeUserDeletedListener implements IEventListener { private $logger; Loading @@ -32,9 +36,19 @@ class BeforeUserDeletedListener implements IEventListener $user = $event->getUser(); $email = $user->getEMailAddress(); $uid = $user->getUID(); $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); $this->logger->info("PostDelete user {user}", array('user' => $uid)); $this->ecloudDelete( $uid, $this->config->getSystemValue('e_welcome_domain'), $this->config->getSystemValue('e_welcome_secret'), $email, $isUserOnLDAP ); try { if ($this->LDAPConnectionService->isLDAPEnabled() && $this->LDAPConnectionService->isUserOnLDAPBackend($user)) { if ($this->LDAPConnectionService->isLDAPEnabled() && $isUserOnLDAP) { $conn = $this->LDAPConnectionService->getLDAPConnection(); $this->deleteAliasEntries($conn, $email); $this->LDAPConnectionService->closeLDAPConnection($conn); Loading @@ -44,6 +58,52 @@ class BeforeUserDeletedListener implements IEventListener } } /** * Once NC deleted the account, * perform specific ecloud selfhosting actions * post delete action is delegated to the welcome container * * @param $userID string * @param $welcomeDomain string main NC domain (welcome container) * @param $welcomeSecret string generated at ecloud selfhosting install and added as a custom var in NC's config * @return mixed response of the external endpoint */ public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret, string $email, bool $isUserOnLDAP = false) { $endpoint = 'postDelete.php'; if ($isUserOnLDAP) { $endpoint = 'postDeleteLDAP.php'; } $postDeleteUrl = "https://" . $welcomeDomain . $endpoint; $curl = new Curl(); /** * send action to docker_welcome * Handling the non NC part of deletion process */ try { $params = [ 'sec' => $welcomeSecret, 'uid' => $userID, 'email' => $email ]; $headers = array( 'Content-Type: application/json' ); $answer = $curl->post($postDeleteUrl, $params, $headers); return json_decode($answer, true); } catch (\Exception $e) { $this->logger->error('There has been an issue while contacting the external deletion script'); $this->logger->logException($e, ['app' => Application::APP_ID]); } return null; } private function deleteAliasEntries($conn, string $email) { $aliasBaseDn = getenv('LDAP_ALIASES_BASE_DN'); Loading Loading
lib/AppInfo/Application.php +0 −3 Original line number Diff line number Diff line Loading @@ -31,8 +31,6 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\User\Events\UserDeletedEvent; use OCA\EcloudAccounts\Listeners\UserDeletedListener; use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Service\LDAPConnectionService; use OCP\User\Events\BeforeUserDeletedEvent; Loading @@ -52,7 +50,6 @@ class Application extends App implements IBootstrap public function register(IRegistrationContext $context): void { $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); } Loading
lib/Db/MailboxMapper.php +11 −3 Original line number Diff line number Diff line Loading @@ -19,10 +19,18 @@ class MailboxMapper { $this->config = $config; $this->logger = $logger; $this->initConnection(); } private function initConnection() { try { $params = $this->getConnectionParams(); $this->conn = DriverManager::getConnection($params); } catch(Exception $e) { $this->logger->info('Error connecting to SQL raw backend: ' . $e->getMessage()); } } private function getConnectionParams() { Loading
lib/Listeners/BeforeUserDeletedListener.php +61 −1 Original line number Diff line number Diff line Loading @@ -5,12 +5,16 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; use Exception; use Curl; use OCA\EcloudAccounts\AppInfo\Application; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\ILogger; use OCP\User\Events\BeforeUserDeletedEvent; use OCA\EcloudAccounts\Service\LDAPConnectionService; require_once 'curl.class.php'; class BeforeUserDeletedListener implements IEventListener { private $logger; Loading @@ -32,9 +36,19 @@ class BeforeUserDeletedListener implements IEventListener $user = $event->getUser(); $email = $user->getEMailAddress(); $uid = $user->getUID(); $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); $this->logger->info("PostDelete user {user}", array('user' => $uid)); $this->ecloudDelete( $uid, $this->config->getSystemValue('e_welcome_domain'), $this->config->getSystemValue('e_welcome_secret'), $email, $isUserOnLDAP ); try { if ($this->LDAPConnectionService->isLDAPEnabled() && $this->LDAPConnectionService->isUserOnLDAPBackend($user)) { if ($this->LDAPConnectionService->isLDAPEnabled() && $isUserOnLDAP) { $conn = $this->LDAPConnectionService->getLDAPConnection(); $this->deleteAliasEntries($conn, $email); $this->LDAPConnectionService->closeLDAPConnection($conn); Loading @@ -44,6 +58,52 @@ class BeforeUserDeletedListener implements IEventListener } } /** * Once NC deleted the account, * perform specific ecloud selfhosting actions * post delete action is delegated to the welcome container * * @param $userID string * @param $welcomeDomain string main NC domain (welcome container) * @param $welcomeSecret string generated at ecloud selfhosting install and added as a custom var in NC's config * @return mixed response of the external endpoint */ public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret, string $email, bool $isUserOnLDAP = false) { $endpoint = 'postDelete.php'; if ($isUserOnLDAP) { $endpoint = 'postDeleteLDAP.php'; } $postDeleteUrl = "https://" . $welcomeDomain . $endpoint; $curl = new Curl(); /** * send action to docker_welcome * Handling the non NC part of deletion process */ try { $params = [ 'sec' => $welcomeSecret, 'uid' => $userID, 'email' => $email ]; $headers = array( 'Content-Type: application/json' ); $answer = $curl->post($postDeleteUrl, $params, $headers); return json_decode($answer, true); } catch (\Exception $e) { $this->logger->error('There has been an issue while contacting the external deletion script'); $this->logger->logException($e, ['app' => Application::APP_ID]); } return null; } private function deleteAliasEntries($conn, string $email) { $aliasBaseDn = getenv('LDAP_ALIASES_BASE_DN'); Loading