Skip to content

Commit 462ea0e

Browse files
authored
Merge pull request #58119 from nextcloud/backport/57854/stable32
[stable32] feat: Add SetupCheck to warn about missing second factor provider
2 parents 204c809 + f062358 commit 462ea0e

5 files changed

Lines changed: 75 additions & 2 deletions

File tree

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
'OCA\\Settings\\SetupChecks\\TaskProcessingSuccessRate' => $baseDir . '/../lib/SetupChecks/TaskProcessingSuccessRate.php',
139139
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => $baseDir . '/../lib/SetupChecks/TempSpaceAvailable.php',
140140
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => $baseDir . '/../lib/SetupChecks/TransactionIsolation.php',
141+
'OCA\\Settings\\SetupChecks\\TwoFactorConfiguration' => $baseDir . '/../lib/SetupChecks/TwoFactorConfiguration.php',
141142
'OCA\\Settings\\SetupChecks\\WellKnownUrls' => $baseDir . '/../lib/SetupChecks/WellKnownUrls.php',
142143
'OCA\\Settings\\SetupChecks\\Woff2Loading' => $baseDir . '/../lib/SetupChecks/Woff2Loading.php',
143144
'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class ComposerStaticInitSettings
153153
'OCA\\Settings\\SetupChecks\\TaskProcessingSuccessRate' => __DIR__ . '/..' . '/../lib/SetupChecks/TaskProcessingSuccessRate.php',
154154
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => __DIR__ . '/..' . '/../lib/SetupChecks/TempSpaceAvailable.php',
155155
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => __DIR__ . '/..' . '/../lib/SetupChecks/TransactionIsolation.php',
156+
'OCA\\Settings\\SetupChecks\\TwoFactorConfiguration' => __DIR__ . '/..' . '/../lib/SetupChecks/TwoFactorConfiguration.php',
156157
'OCA\\Settings\\SetupChecks\\WellKnownUrls' => __DIR__ . '/..' . '/../lib/SetupChecks/WellKnownUrls.php',
157158
'OCA\\Settings\\SetupChecks\\Woff2Loading' => __DIR__ . '/..' . '/../lib/SetupChecks/Woff2Loading.php',
158159
'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
use OCA\Settings\SetupChecks\TaskProcessingPickupSpeed;
7575
use OCA\Settings\SetupChecks\TempSpaceAvailable;
7676
use OCA\Settings\SetupChecks\TransactionIsolation;
77+
use OCA\Settings\SetupChecks\TwoFactorConfiguration;
7778
use OCA\Settings\SetupChecks\WellKnownUrls;
7879
use OCA\Settings\SetupChecks\Woff2Loading;
7980
use OCA\Settings\UserMigration\AccountMigrator;
@@ -213,6 +214,7 @@ public function register(IRegistrationContext $context): void {
213214
$context->registerSetupCheck(TaskProcessingPickupSpeed::class);
214215
$context->registerSetupCheck(TempSpaceAvailable::class);
215216
$context->registerSetupCheck(TransactionIsolation::class);
217+
$context->registerSetupCheck(TwoFactorConfiguration::class);
216218
$context->registerSetupCheck(PushService::class);
217219
$context->registerSetupCheck(WellKnownUrls::class);
218220
$context->registerSetupCheck(Woff2Loading::class);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Settings\SetupChecks;
11+
12+
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
13+
use OC\Authentication\TwoFactorAuth\ProviderLoader;
14+
use OC\Authentication\TwoFactorAuth\ProviderSet;
15+
use OCP\IL10N;
16+
use OCP\SetupCheck\ISetupCheck;
17+
use OCP\SetupCheck\SetupResult;
18+
19+
class TwoFactorConfiguration implements ISetupCheck {
20+
public function __construct(
21+
private IL10N $l10n,
22+
private ProviderLoader $providerLoader,
23+
private MandatoryTwoFactor $mandatoryTwoFactor,
24+
) {
25+
}
26+
27+
public function getName(): string {
28+
return $this->l10n->t('Second factor configuration');
29+
}
30+
31+
public function getCategory(): string {
32+
return 'security';
33+
}
34+
35+
public function run(): SetupResult {
36+
$providers = $this->providerLoader->getProviders();
37+
$providerSet = new ProviderSet($providers, false);
38+
$primaryProviders = $providerSet->getPrimaryProviders();
39+
if (count($primaryProviders) === 0) {
40+
return SetupResult::warning($this->l10n->t('This instance has no second factor provider available.'));
41+
}
42+
43+
$state = $this->mandatoryTwoFactor->getState();
44+
45+
if (!$state->isEnforced()) {
46+
return SetupResult::info(
47+
$this->l10n->t(
48+
'Second factor providers are available but two-factor authentication is not enforced.'
49+
)
50+
);
51+
} else {
52+
return SetupResult::success(
53+
$this->l10n->t(
54+
'Second factor providers are available and enforced: %s.',
55+
[
56+
implode(', ', array_map(
57+
fn ($p) => '"' . $p->getDisplayName() . '"',
58+
$primaryProviders)
59+
)
60+
]
61+
)
62+
);
63+
}
64+
}
65+
}

lib/private/Authentication/TwoFactorAuth/ProviderLoader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ public function __construct(
3030
* @return IProvider[]
3131
* @throws Exception
3232
*/
33-
public function getProviders(IUser $user): array {
34-
$allApps = $this->appManager->getEnabledAppsForUser($user);
33+
public function getProviders(?IUser $user = null): array {
34+
if ($user === null) {
35+
$allApps = $this->appManager->getEnabledApps();
36+
} else {
37+
$allApps = $this->appManager->getEnabledAppsForUser($user);
38+
}
3539
$providers = [];
3640

3741
foreach ($allApps as $appId) {

0 commit comments

Comments
 (0)