From 5ee9e1f78467d1004177012978160731606f204e Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 16 Apr 2021 14:52:59 +0200 Subject: Move 2FA registration to IBootstrap Signed-off-by: Roeland Jago Douma --- .../AppFramework/Bootstrap/RegistrationContext.php | 23 +++++++++++++++++++++- .../TwoFactorAuth/ProviderLoader.php | 18 ++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 662296b8dd6..d056c088a9f 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -92,7 +92,10 @@ class RegistrationContext { private $templateProviders = []; /** @var ServiceRegistration[] */ - private $notifierServices; + private $notifierServices = []; + + /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ + private $twoFactorProviders = []; /** @var ILogger */ private $logger; @@ -217,6 +220,13 @@ class RegistrationContext { $notifierClass ); } + + public function registerTwoFactorProvider(string $twoFactorProviderClass): void { + $this->context->registerTwoFactorProvider( + $this->appId, + $twoFactorProviderClass + ); + } }; } @@ -288,6 +298,10 @@ class RegistrationContext { $this->notifierServices[] = new ServiceRegistration($appId, $class); } + public function registerTwoFactorProvider(string $appId, string $class): void { + $this->twoFactorProviders[] = new ServiceRegistration($appId, $class); + } + /** * @param App[] $apps */ @@ -479,4 +493,11 @@ class RegistrationContext { public function getNotifierServices(): array { return $this->notifierServices; } + + /** + * @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] + */ + public function getTwoFactorProviders(): array { + return $this->twoFactorProviders; + } } diff --git a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php index 40385d737ae..57b9413feb4 100644 --- a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php +++ b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php @@ -40,8 +40,12 @@ class ProviderLoader { /** @var IAppManager */ private $appManager; - public function __construct(IAppManager $appManager) { + /** @var OC\AppFramework\Bootstrap\Coordinator */ + private $coordinator; + + public function __construct(IAppManager $appManager, OC\AppFramework\Bootstrap\Coordinator $coordinator) { $this->appManager = $appManager; + $this->coordinator = $coordinator; } /** @@ -72,6 +76,18 @@ class ProviderLoader { } } + $registeredProviders = $this->coordinator->getRegistrationContext()->getTwoFactorProvider(); + foreach ($registeredProviders as $provider) { + try { + $this->loadTwoFactorApp($provider->getAppId()); + $provider = OC::$server->query($provider->getService()); + $providers[$provider->getId()] = $provider; + } catch (QueryException $exc) { + // Provider class can not be resolved + throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); + } + } + return $providers; } -- cgit v1.2.3