|
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
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Core\DependencyInjection; |
|
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; |
|
25
|
|
|
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderManifest; |
|
26
|
|
|
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry; |
|
27
|
|
|
use TYPO3\CMS\Core\Service\DependencyOrderingService; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Compiler pass to register tagged MFA providers |
|
32
|
|
|
* |
|
33
|
|
|
* @internal |
|
34
|
|
|
*/ |
|
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
|
|
|
} |
|
90
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: