‪TYPO3CMS  11.5
MfaProviderPass.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
21 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22 use Symfony\Component\DependencyInjection\ContainerBuilder;
23 use Symfony\Component\DependencyInjection\Definition;
24 use Symfony\Component\DependencyInjection\Reference;
29 
35 final class ‪MfaProviderPass implements CompilerPassInterface
36 {
37  protected string ‪$tagName;
38 
39  public function ‪__construct(string ‪$tagName)
40  {
41  $this->tagName = ‪$tagName;
42  }
43 
44  public function ‪process(ContainerBuilder $container): void
45  {
46  $mfaProviderRegistryDefinition = $container->findDefinition(MfaProviderRegistry::class);
47  $providers = [];
48 
49  foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tags) {
50  $definition = $container->findDefinition($id);
51  if (!$definition->isAutoconfigured() || $definition->isAbstract()) {
52  continue;
53  }
54 
55  $definition->setPublic(true);
56 
57  foreach ($tags as $attributes) {
58  $identifier = $attributes['identifier'] ?? $id;
59  $providers[$identifier] = [
60  'title' => $attributes['title'] ?? '',
61  'description' => $attributes['description'] ?? '',
62  'setupInstructions' => $attributes['setupInstructions'] ?? '',
63  'iconIdentifier' => $attributes['icon'] ?? '',
64  'isDefaultProviderAllowed' => (bool)($attributes['defaultProviderAllowed'] ?? true),
65  'before' => ‪GeneralUtility::trimExplode(',', $attributes['before'] ?? '', true),
66  'after' => ‪GeneralUtility::trimExplode(',', $attributes['after'] ?? '', true),
67  'serviceName' => $id,
68  ];
69  }
70  }
71 
72  foreach ((new ‪DependencyOrderingService())->orderByDependencies($providers) as $identifier => $properties) {
73  $manifest = new Definition(MfaProviderManifest::class);
74  $manifest->setArguments([
75  $identifier,
76  $properties['title'],
77  $properties['description'],
78  $properties['setupInstructions'],
79  $properties['iconIdentifier'],
80  $properties['isDefaultProviderAllowed'],
81  $properties['serviceName'],
82  new Reference(ContainerInterface::class),
83  ]);
84  $manifest->setShared(false);
85 
86  $mfaProviderRegistryDefinition->addMethodCall('registerProvider', [$manifest]);
87  }
88  }
89 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Core\DependencyInjection\MfaProviderPass\__construct
‪__construct(string $tagName)
Definition: MfaProviderPass.php:39
‪TYPO3\CMS\Core\DependencyInjection\MfaProviderPass\$tagName
‪string $tagName
Definition: MfaProviderPass.php:37
‪TYPO3\CMS\Core\DependencyInjection\MfaProviderPass\process
‪process(ContainerBuilder $container)
Definition: MfaProviderPass.php:44
‪TYPO3\CMS\Core\DependencyInjection
Definition: AutowireInjectMethodsPass.php:18
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Core\Authentication\Mfa\MfaProviderManifest
Definition: MfaProviderManifest.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\DependencyInjection\MfaProviderPass
Definition: MfaProviderPass.php:36
‪TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry
Definition: MfaProviderRegistry.php:28