Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
'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',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
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;
Expand Down Expand Up @@ -218,6 +219,7 @@ public function register(IRegistrationContext $context): void {
$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);
Expand Down
65 changes: 65 additions & 0 deletions apps/settings/lib/SetupChecks/TwoFactorConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Settings\SetupChecks;

use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OC\Authentication\TwoFactorAuth\ProviderLoader;
use OC\Authentication\TwoFactorAuth\ProviderSet;
use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class TwoFactorConfiguration implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private ProviderLoader $providerLoader,
private MandatoryTwoFactor $mandatoryTwoFactor,
) {
}

public function getName(): string {
return $this->l10n->t('Second factor configuration');
}

public function getCategory(): string {
return 'security';
}

public function run(): SetupResult {
$providers = $this->providerLoader->getProviders();
$providerSet = new ProviderSet($providers, false);
$primaryProviders = $providerSet->getPrimaryProviders();
if (count($primaryProviders) === 0) {
return SetupResult::warning($this->l10n->t('This instance has no second factor provider available.'));
}

$state = $this->mandatoryTwoFactor->getState();

if (!$state->isEnforced()) {
return SetupResult::info(
$this->l10n->t(
'Second factor providers are available but two-factor authentication is not enforced.'
)
);
} else {
return SetupResult::success(
$this->l10n->t(
'Second factor providers are available and enforced: %s.',
[
implode(', ', array_map(
fn ($p) => '"' . $p->getDisplayName() . '"',
$primaryProviders)
)
]
)
);
}
}
}
8 changes: 6 additions & 2 deletions lib/private/Authentication/TwoFactorAuth/ProviderLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ public function __construct(
* @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) {
Expand Down
Loading