Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-07-20 15:20:03 +0300
committerGitHub <noreply@github.com>2020-07-20 15:20:03 +0300
commit9ae75a3ca9785a0400f81854b906c1e5ecb48edb (patch)
tree0d64dfb3d89a755af101e1b17e1973e05061d49c /lib
parent84ca5863d7e124acfb75e0a9d505ab25f713b590 (diff)
parent0dfcc132caaeda7553c06b7a146641c69c41111d (diff)
Merge pull request #21850 from nextcloud/techdebt/noid/register-alternative-logins
Allow to register AlternativeLogin on RegistrationContext
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php24
-rw-r--r--lib/private/legacy/OC_App.php50
-rw-r--r--lib/public/AppFramework/Bootstrap/IRegistrationContext.php13
-rw-r--r--lib/public/Authentication/IAlternativeLogin.php58
6 files changed, 145 insertions, 2 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index e60cb4c6b0e..94e35bf1b13 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -83,6 +83,7 @@ return array(
'OCP\\Authentication\\Events\\LoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/LoginFailedEvent.php',
'OCP\\Authentication\\Exceptions\\CredentialsUnavailableException' => $baseDir . '/lib/public/Authentication/Exceptions/CredentialsUnavailableException.php',
'OCP\\Authentication\\Exceptions\\PasswordUnavailableException' => $baseDir . '/lib/public/Authentication/Exceptions/PasswordUnavailableException.php',
+ 'OCP\\Authentication\\IAlternativeLogin' => $baseDir . '/lib/public/Authentication/IAlternativeLogin.php',
'OCP\\Authentication\\IApacheBackend' => $baseDir . '/lib/public/Authentication/IApacheBackend.php',
'OCP\\Authentication\\LoginCredentials\\ICredentials' => $baseDir . '/lib/public/Authentication/LoginCredentials/ICredentials.php',
'OCP\\Authentication\\LoginCredentials\\IStore' => $baseDir . '/lib/public/Authentication/LoginCredentials/IStore.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index b8944cfe716..1892c3bc96a 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -112,6 +112,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Authentication\\Events\\LoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/LoginFailedEvent.php',
'OCP\\Authentication\\Exceptions\\CredentialsUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/CredentialsUnavailableException.php',
'OCP\\Authentication\\Exceptions\\PasswordUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/PasswordUnavailableException.php',
+ 'OCP\\Authentication\\IAlternativeLogin' => __DIR__ . '/../../..' . '/lib/public/Authentication/IAlternativeLogin.php',
'OCP\\Authentication\\IApacheBackend' => __DIR__ . '/../../..' . '/lib/public/Authentication/IApacheBackend.php',
'OCP\\Authentication\\LoginCredentials\\ICredentials' => __DIR__ . '/../../..' . '/lib/public/Authentication/LoginCredentials/ICredentials.php',
'OCP\\Authentication\\LoginCredentials\\IStore' => __DIR__ . '/../../..' . '/lib/public/Authentication/LoginCredentials/IStore.php',
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 270035a2908..efcf9175b97 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -63,6 +63,9 @@ class RegistrationContext {
/** @var array[] */
private $searchProviders = [];
+ /** @var array[] */
+ private $alternativeLogins = [];
+
/** @var ILogger */
private $logger;
@@ -151,6 +154,13 @@ class RegistrationContext {
$class
);
}
+
+ public function registerAlternativeLogin(string $class): void {
+ $this->context->registerAlternativeLogin(
+ $this->appId,
+ $class
+ );
+ }
};
}
@@ -223,6 +233,13 @@ class RegistrationContext {
];
}
+ public function registerAlternativeLogin(string $appId, string $class): void {
+ $this->alternativeLogins[] = [
+ 'appId' => $appId,
+ 'class' => $class,
+ ];
+ }
+
/**
* @param App[] $apps
*/
@@ -386,4 +403,11 @@ class RegistrationContext {
public function getSearchProviders(): array {
return $this->searchProviders;
}
+
+ /**
+ * @return array[]
+ */
+ public function getAlternativeLogins(): array {
+ return $this->alternativeLogins;
+ }
}
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index 4110bee114d..5851fc01379 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -52,11 +52,14 @@ declare(strict_types=1);
*/
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
+use OC\AppFramework\Bootstrap\Coordinator;
use OC\DB\MigrationService;
use OC\Installer;
use OC\Repair;
use OC\ServerNotAvailableException;
use OCP\App\ManagerEvent;
+use OCP\AppFramework\QueryException;
+use OCP\Authentication\IAlternativeLogin;
use OCP\ILogger;
/**
@@ -149,8 +152,8 @@ class OC_App {
// in case someone calls loadApp() directly
self::registerAutoloading($app, $appPath);
- /** @var \OC\AppFramework\Bootstrap\Coordinator $coordinator */
- $coordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class);
+ /** @var Coordinator $coordinator */
+ $coordinator = \OC::$server->query(Coordinator::class);
$isBootable = $coordinator->isBootable($app);
$hasAppPhpFile = is_file($appPath . '/appinfo/app.php');
@@ -672,8 +675,10 @@ class OC_App {
/**
* @param array $entry
+ * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface
*/
public static function registerLogIn(array $entry) {
+ \OC::$server->getLogger()->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface');
self::$altLogin[] = $entry;
}
@@ -681,6 +686,47 @@ class OC_App {
* @return array
*/
public static function getAlternativeLogIns(): array {
+ /** @var Coordinator $bootstrapCoordinator */
+ $bootstrapCoordinator = \OC::$server->query(Coordinator::class);
+
+ foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) {
+ if (!in_array(IAlternativeLogin::class, class_implements($registration['class']), true)) {
+ \OC::$server->getLogger()->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [
+ 'option' => $registration['class'],
+ 'interface' => IAlternativeLogin::class,
+ 'app' => $registration['app'],
+ ]);
+ continue;
+ }
+
+ try {
+ /** @var IAlternativeLogin $provider */
+ $provider = \OC::$server->query($registration['class']);
+ } catch (QueryException $e) {
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Alternative login option {option} can not be initialised.',
+ 'option' => $registration['class'],
+ 'app' => $registration['app'],
+ ]);
+ }
+
+ try {
+ $provider->load();
+
+ self::$altLogin[] = [
+ 'name' => $provider->getLabel(),
+ 'href' => $provider->getLink(),
+ 'style' => $provider->getClass(),
+ ];
+ } catch (Throwable $e) {
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Alternative login option {option} had an error while loading.',
+ 'option' => $registration['class'],
+ 'app' => $registration['app'],
+ ]);
+ }
+ }
+
return self::$altLogin;
}
diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
index 8ce140996b7..94e3aed17e2 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -139,4 +139,17 @@ interface IRegistrationContext {
* @since 20.0.0
*/
public function registerSearchProvider(string $class): void;
+
+ /**
+ * Register an alternative login option
+ *
+ * It is allowed to register more than one option per app.
+ *
+ * @param string $class
+ *
+ * @return void
+ *
+ * @since 20.0.0
+ */
+ public function registerAlternativeLogin(string $class): void;
}
diff --git a/lib/public/Authentication/IAlternativeLogin.php b/lib/public/Authentication/IAlternativeLogin.php
new file mode 100644
index 00000000000..2b584a86066
--- /dev/null
+++ b/lib/public/Authentication/IAlternativeLogin.php
@@ -0,0 +1,58 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
+ *
+ * @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 OCP\Authentication;
+
+/**
+ * @since 20.0.0
+ */
+interface IAlternativeLogin {
+
+ /**
+ * Label shown on the login option
+ * @return string
+ * @since 20.0.0
+ */
+ public function getLabel(): string;
+
+ /**
+ * Relative link to the login option
+ * @return string
+ * @since 20.0.0
+ */
+ public function getLink(): string;
+
+ /**
+ * CSS classes added to the alternative login option on the login screen
+ * @return string
+ * @since 20.0.0
+ */
+ public function getClass(): string;
+
+ /**
+ * Load necessary resources to present the login option, e.g. style-file to style the getClass()
+ * @since 20.0.0
+ */
+ public function load(): void;
+}