summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-06 00:44:18 +0100
committerGitHub <noreply@github.com>2018-11-06 00:44:18 +0100
commit411d2dece5b65ac92f508189647df5bf03b005db (patch)
tree7a86213b522ee0ae970837e0b042b9b9585e5cfe /lib
parentf350f2e3ec0bb9b06c7c585db0b9e33266f43021 (diff)
parent90c4b7db156c9aee6dc543032eabecc0b4364236 (diff)
downloadnextcloud-server-411d2dece5b65ac92f508189647df5bf03b005db.tar.gz
nextcloud-server-411d2dece5b65ac92f508189647df5bf03b005db.zip
Merge pull request #11786 from nextcloud/feature/password_confirmation_backend
Expose password confirmation capabilities in the user backend
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/Middleware/Security/PasswordConfirmationMiddleware.php8
-rw-r--r--lib/private/Template/JSConfigHelper.php13
-rw-r--r--lib/private/User/User.php4
-rw-r--r--lib/public/IUser.php7
-rw-r--r--lib/public/User/Backend/IPasswordConfirmationBackend.php36
7 files changed, 67 insertions, 3 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 6c2463939bd..317565a2f06 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -391,6 +391,7 @@ return array(
'OCP\\User\\Backend\\ICreateUserBackend' => $baseDir . '/lib/public/User/Backend/ICreateUserBackend.php',
'OCP\\User\\Backend\\IGetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
'OCP\\User\\Backend\\IGetHomeBackend' => $baseDir . '/lib/public/User/Backend/IGetHomeBackend.php',
+ 'OCP\\User\\Backend\\IPasswordConfirmationBackend' => $baseDir . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 847ae43fb65..ab8e5b21265 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -421,6 +421,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\User\\Backend\\ICreateUserBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICreateUserBackend.php',
'OCP\\User\\Backend\\IGetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetDisplayNameBackend.php',
'OCP\\User\\Backend\\IGetHomeBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetHomeBackend.php',
+ 'OCP\\User\\Backend\\IPasswordConfirmationBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordConfirmationBackend.php',
'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php',
diff --git a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php
index 7c1c4595e9a..d752a68cf32 100644
--- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php
@@ -29,6 +29,7 @@ use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ISession;
use OCP\IUserSession;
+use OCP\User\Backend\IPasswordConfirmationBackend;
class PasswordConfirmationMiddleware extends Middleware {
/** @var ControllerMethodReflector */
@@ -70,6 +71,13 @@ class PasswordConfirmationMiddleware extends Middleware {
$user = $this->userSession->getUser();
$backendClassName = '';
if ($user !== null) {
+ $backend = $user->getBackend();
+ if ($backend instanceof IPasswordConfirmationBackend) {
+ if (!$backend->canConfirmPassword($user->getUID())) {
+ return;
+ }
+ }
+
$backendClassName = $user->getBackendClassName();
}
diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php
index ad9ff0b6757..26da8fcc3c9 100644
--- a/lib/private/Template/JSConfigHelper.php
+++ b/lib/private/Template/JSConfigHelper.php
@@ -37,6 +37,7 @@ use OCP\IL10N;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUser;
+use OCP\User\Backend\IPasswordConfirmationBackend;
class JSConfigHelper {
@@ -109,12 +110,18 @@ class JSConfigHelper {
public function getConfig() {
+ $userBackendAllowsPasswordConfirmation = true;
if ($this->currentUser !== null) {
$uid = $this->currentUser->getUID();
- $userBackend = $this->currentUser->getBackendClassName();
+
+ $backend = $this->currentUser->getBackend();
+ if ($backend instanceof IPasswordConfirmationBackend) {
+ $userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid);
+ } else if (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) {
+ $userBackendAllowsPasswordConfirmation = false;
+ }
} else {
$uid = null;
- $userBackend = '';
}
// Get the config
@@ -161,7 +168,7 @@ class JSConfigHelper {
$array = [
"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
- "backendAllowsPasswordConfirmation" => !isset($this->excludedUserBackEnds[$userBackend]) ? 'true' : 'false',
+ "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false',
"oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false',
"oc_webroot" => "\"".\OC::$WEBROOT."\"",
"oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index e171a65f8ce..06dd47b0887 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -302,6 +302,10 @@ class User implements IUser {
return get_class($this->backend);
}
+ public function getBackend() {
+ return $this->backend;
+ }
+
/**
* check if the backend allows the user to change his avatar on Personal page
*
diff --git a/lib/public/IUser.php b/lib/public/IUser.php
index 3d8515a5e03..a3d7c6b71a6 100644
--- a/lib/public/IUser.php
+++ b/lib/public/IUser.php
@@ -109,6 +109,13 @@ interface IUser {
public function getBackendClassName();
/**
+ * Get the backend for the current user object
+ *
+ * @since 15.0.0
+ */
+ public function getBackend();
+
+ /**
* check if the backend allows the user to change his avatar on Personal page
*
* @return bool
diff --git a/lib/public/User/Backend/IPasswordConfirmationBackend.php b/lib/public/User/Backend/IPasswordConfirmationBackend.php
new file mode 100644
index 00000000000..021ca8ca25b
--- /dev/null
+++ b/lib/public/User/Backend/IPasswordConfirmationBackend.php
@@ -0,0 +1,36 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\User\Backend;
+
+/**
+ * @since 15.0.0
+ */
+interface IPasswordConfirmationBackend {
+
+ /**
+ * @since 15.0.0
+ */
+ public function canConfirmPassword(string $uid): bool;
+}