2018-05-22 02:52:16 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-06-25 01:38:52 -04:00
|
|
|
declare(strict_types=1);
|
2018-05-22 02:52:16 -04:00
|
|
|
|
|
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-05-22 02:52:16 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Authentication\TwoFactorAuth;
|
|
|
|
|
|
2018-08-08 09:25:59 -04:00
|
|
|
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
|
2018-05-22 02:52:16 -04:00
|
|
|
use OCP\Authentication\TwoFactorAuth\IProvider;
|
2023-11-23 04:22:34 -05:00
|
|
|
use function array_filter;
|
2018-05-22 02:52:16 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains all two-factor provider information for the two-factor login challenge
|
|
|
|
|
*/
|
|
|
|
|
class ProviderSet {
|
|
|
|
|
/** @var IProvider */
|
|
|
|
|
private $providers;
|
|
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
|
private $providerMissing;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param IProvider[] $providers
|
|
|
|
|
* @param bool $providerMissing
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(array $providers, bool $providerMissing) {
|
|
|
|
|
$this->providers = [];
|
|
|
|
|
foreach ($providers as $provider) {
|
|
|
|
|
$this->providers[$provider->getId()] = $provider;
|
|
|
|
|
}
|
|
|
|
|
$this->providerMissing = $providerMissing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $providerId
|
|
|
|
|
* @return IProvider|null
|
|
|
|
|
*/
|
|
|
|
|
public function getProvider(string $providerId) {
|
|
|
|
|
return $this->providers[$providerId] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return IProvider[]
|
|
|
|
|
*/
|
|
|
|
|
public function getProviders(): array {
|
|
|
|
|
return $this->providers;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-08 09:25:59 -04:00
|
|
|
/**
|
|
|
|
|
* @return IProvider[]
|
|
|
|
|
*/
|
2018-08-08 14:28:21 -04:00
|
|
|
public function getPrimaryProviders(): array {
|
2020-04-09 07:53:40 -04:00
|
|
|
return array_filter($this->providers, function (IProvider $provider) {
|
2018-08-08 09:25:59 -04:00
|
|
|
return !($provider instanceof BackupCodesProvider);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 02:52:16 -04:00
|
|
|
public function isProviderMissing(): bool {
|
|
|
|
|
return $this->providerMissing;
|
|
|
|
|
}
|
|
|
|
|
}
|