diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-09-29 18:57:00 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-09-30 11:47:29 +0200 |
commit | 259c0ce11dedeacd225c0776bfc783386f061c5f (patch) | |
tree | f4664c1873a3131cecd10af2e6177bdc663e3bde /lib/private/Authentication | |
parent | eec7f9ec28ec4fb7f1baa8e3536b74af08a552ec (diff) | |
download | nextcloud-server-259c0ce11dedeacd225c0776bfc783386f061c5f.tar.gz nextcloud-server-259c0ce11dedeacd225c0776bfc783386f061c5f.zip |
Add mandatory 2FA service/class
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Authentication')
-rw-r--r-- | lib/private/Authentication/TwoFactorAuth/Manager.php | 14 | ||||
-rw-r--r-- | lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php | 48 |
2 files changed, 60 insertions, 2 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 71cc5874e5d..2307a731002 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -57,6 +57,9 @@ class Manager { /** @var IRegistry */ private $providerRegistry; + /** @var MandatoryTwoFactor */ + private $mandatoryTwoFactor; + /** @var ISession */ private $session; @@ -79,10 +82,14 @@ class Manager { private $dispatcher; public function __construct(ProviderLoader $providerLoader, - IRegistry $providerRegistry, ISession $session, IConfig $config, + IRegistry $providerRegistry, + MandatoryTwoFactor $mandatoryTwoFactor, + ISession $session, IConfig $config, IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider, ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) { $this->providerLoader = $providerLoader; + $this->providerRegistry = $providerRegistry; + $this->mandatoryTwoFactor = $mandatoryTwoFactor; $this->session = $session; $this->config = $config; $this->activityManager = $activityManager; @@ -90,7 +97,6 @@ class Manager { $this->tokenProvider = $tokenProvider; $this->timeFactory = $timeFactory; $this->dispatcher = $eventDispatcher; - $this->providerRegistry = $providerRegistry; } /** @@ -100,6 +106,10 @@ class Manager { * @return boolean */ public function isTwoFactorAuthenticated(IUser $user): bool { + if ($this->mandatoryTwoFactor->isEnforced()) { + return true; + } + $providerStates = $this->providerRegistry->getProviderStates($user); $providers = $this->providerLoader->getProviders($user); $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); diff --git a/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php b/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php new file mode 100644 index 00000000000..a23a10a1be6 --- /dev/null +++ b/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php @@ -0,0 +1,48 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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 OC\Authentication\TwoFactorAuth; + +use OCP\IConfig; + +class MandatoryTwoFactor { + + /** @var IConfig */ + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + public function isEnforced(): bool { + return $this->config->getSystemValue('twofactor_enforced', 'false') === 'true'; + } + + public function setEnforced(bool $enforced) { + $this->config->setSystemValue('twofactor_enforced', $enforced ? 'true' : 'false'); + } + +} |