Skip to content
Merged
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
Only check the twofactor state once per request
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Dec 1, 2021
commit febca701ee9768563fb8102a46a1aa68e1247072
10 changes: 9 additions & 1 deletion lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Manager {
/** @var EventDispatcherInterface */
private $legacyDispatcher;

/** @psalm-var array<string, bool> */
private $userIsTwoFactorAuthenticated = [];

public function __construct(ProviderLoader $providerLoader,
IRegistry $providerRegistry,
MandatoryTwoFactor $mandatoryTwoFactor,
Expand Down Expand Up @@ -118,6 +121,10 @@ public function __construct(ProviderLoader $providerLoader,
* @return boolean
*/
public function isTwoFactorAuthenticated(IUser $user): bool {
if (isset($this->userIsTwoFactorAuthenticated[$user->getUID()])) {
return $this->userIsTwoFactorAuthenticated[$user->getUID()];
}

if ($this->mandatoryTwoFactor->isEnforcedFor($user)) {
return true;
}
Expand All @@ -129,7 +136,8 @@ public function isTwoFactorAuthenticated(IUser $user): bool {
$providerIds = array_keys($enabled);
$providerIdsWithoutBackupCodes = array_diff($providerIds, [self::BACKUP_CODES_PROVIDER_ID]);

return !empty($providerIdsWithoutBackupCodes);
$this->userIsTwoFactorAuthenticated[$user->getUID()] = !empty($providerIdsWithoutBackupCodes);
return $this->userIsTwoFactorAuthenticated[$user->getUID()];
}

/**
Expand Down