mirror of
https://github.com/nextcloud/server.git
synced 2026-04-29 10:03:32 -04:00
feat: Add SetupCheck to warn about missing second factor provider
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
4faad01d3c
commit
cc53fb2735
5 changed files with 59 additions and 2 deletions
|
|
@ -140,6 +140,7 @@ return array(
|
|||
'OCA\\Settings\\SetupChecks\\TaskProcessingSuccessRate' => $baseDir . '/../lib/SetupChecks/TaskProcessingSuccessRate.php',
|
||||
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => $baseDir . '/../lib/SetupChecks/TempSpaceAvailable.php',
|
||||
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => $baseDir . '/../lib/SetupChecks/TransactionIsolation.php',
|
||||
'OCA\\Settings\\SetupChecks\\TwoFactorConfiguration' => $baseDir . '/../lib/SetupChecks/TwoFactorConfiguration.php',
|
||||
'OCA\\Settings\\SetupChecks\\WellKnownUrls' => $baseDir . '/../lib/SetupChecks/WellKnownUrls.php',
|
||||
'OCA\\Settings\\SetupChecks\\Woff2Loading' => $baseDir . '/../lib/SetupChecks/Woff2Loading.php',
|
||||
'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php',
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ class ComposerStaticInitSettings
|
|||
'OCA\\Settings\\SetupChecks\\TaskProcessingSuccessRate' => __DIR__ . '/..' . '/../lib/SetupChecks/TaskProcessingSuccessRate.php',
|
||||
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => __DIR__ . '/..' . '/../lib/SetupChecks/TempSpaceAvailable.php',
|
||||
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => __DIR__ . '/..' . '/../lib/SetupChecks/TransactionIsolation.php',
|
||||
'OCA\\Settings\\SetupChecks\\TwoFactorConfiguration' => __DIR__ . '/..' . '/../lib/SetupChecks/TwoFactorConfiguration.php',
|
||||
'OCA\\Settings\\SetupChecks\\WellKnownUrls' => __DIR__ . '/..' . '/../lib/SetupChecks/WellKnownUrls.php',
|
||||
'OCA\\Settings\\SetupChecks\\Woff2Loading' => __DIR__ . '/..' . '/../lib/SetupChecks/Woff2Loading.php',
|
||||
'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php',
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ use OCA\Settings\SetupChecks\SystemIs64bit;
|
|||
use OCA\Settings\SetupChecks\TaskProcessingPickupSpeed;
|
||||
use OCA\Settings\SetupChecks\TempSpaceAvailable;
|
||||
use OCA\Settings\SetupChecks\TransactionIsolation;
|
||||
use OCA\Settings\SetupChecks\TwoFactorConfiguration;
|
||||
use OCA\Settings\SetupChecks\WellKnownUrls;
|
||||
use OCA\Settings\SetupChecks\Woff2Loading;
|
||||
use OCA\Settings\UserMigration\AccountMigrator;
|
||||
|
|
@ -218,6 +219,7 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerSetupCheck(TaskProcessingPickupSpeed::class);
|
||||
$context->registerSetupCheck(TempSpaceAvailable::class);
|
||||
$context->registerSetupCheck(TransactionIsolation::class);
|
||||
$context->registerSetupCheck(TwoFactorConfiguration::class);
|
||||
$context->registerSetupCheck(PushService::class);
|
||||
$context->registerSetupCheck(WellKnownUrls::class);
|
||||
$context->registerSetupCheck(Woff2Loading::class);
|
||||
|
|
|
|||
49
apps/settings/lib/SetupChecks/TwoFactorConfiguration.php
Normal file
49
apps/settings/lib/SetupChecks/TwoFactorConfiguration.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCA\Settings\SetupChecks;
|
||||
|
||||
use OC\Authentication\TwoFactorAuth\ProviderLoader;
|
||||
use OCP\IL10N;
|
||||
use OCP\SetupCheck\ISetupCheck;
|
||||
use OCP\SetupCheck\SetupResult;
|
||||
|
||||
class TwoFactorConfiguration implements ISetupCheck {
|
||||
public function __construct(
|
||||
private IL10N $l10n,
|
||||
private ProviderLoader $providerLoader,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->l10n->t('Two factor configuration');
|
||||
}
|
||||
|
||||
public function getCategory(): string {
|
||||
return 'security';
|
||||
}
|
||||
|
||||
public function run(): SetupResult {
|
||||
$providers = $this->providerLoader->getProviders();
|
||||
if (count($providers) === 0) {
|
||||
return SetupResult::warning($this->l10n->t('This instance has no second factor provider available.'));
|
||||
} else {
|
||||
return SetupResult::success(
|
||||
$this->l10n->t(
|
||||
'Second factor providers are available: %s.',
|
||||
[
|
||||
implode(', ', array_map(
|
||||
fn ($p) => '"' . $p->getDisplayName() . '"',
|
||||
$providers)
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,12 @@ class ProviderLoader {
|
|||
* @return IProvider[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getProviders(IUser $user): array {
|
||||
$allApps = $this->appManager->getEnabledAppsForUser($user);
|
||||
public function getProviders(?IUser $user = null): array {
|
||||
if ($user === null) {
|
||||
$allApps = $this->appManager->getEnabledApps();
|
||||
} else {
|
||||
$allApps = $this->appManager->getEnabledAppsForUser($user);
|
||||
}
|
||||
$providers = [];
|
||||
|
||||
foreach ($allApps as $appId) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue