Files
nextcloud-server-mirror/apps/settings/lib/Controller/TwoFactorSettingsController.php
Ghassen kefi 81ce503a20 feat(settings): log credential, security and server settings changes
Audit entries are added for app password creation, deletion and scope
changes, remote wipe requests, WebAuthn devices, two-factor
enforcement, mail server settings and credentials, admin delegation,
presets, declarative settings and log file downloads.

The existing AI settings entry keeps its message and now carries an
operation (settings.ai.updated) and named parameters.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
2026-11-05 16:35:13 +01:00

55 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Controller;
use OC\Authentication\TwoFactorAuth\EnforcementState;
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\Log\Audit\CriticalActionPerformedEvent;
class TwoFactorSettingsController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private MandatoryTwoFactor $mandatoryTwoFactor,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct($appName, $request);
}
public function index(): JSONResponse {
return new JSONResponse($this->mandatoryTwoFactor->getState());
}
#[PasswordConfirmationRequired(strict: true)]
public function update(bool $enforced, array $enforcedGroups = [], array $excludedGroups = []): JSONResponse {
$this->mandatoryTwoFactor->setState(
new EnforcementState($enforced, $enforcedGroups, $excludedGroups)
);
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
'Two-factor authentication enforcement was set to "%s" with enforced groups "%s" and excluded groups "%s"',
[
'enforced' => $enforced ? 'enabled' : 'disabled',
'enforcedGroups' => implode(', ', $enforcedGroups),
'excludedGroups' => implode(', ', $excludedGroups),
],
false,
'auth.twofactor_enforcement.updated',
));
return new JSONResponse($this->mandatoryTwoFactor->getState());
}
}