1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Bundle\DependencyInjection\Component\Endpoint; |
15
|
|
|
|
16
|
|
|
use Fluent\PhpConfigFileLoader; |
17
|
|
|
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper; |
18
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
20
|
|
|
use Symfony\Component\Config\FileLocator; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
23
|
|
|
|
24
|
|
|
final class ClientRegistrationSoftwareStatementSource implements Component |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
30
|
|
|
{ |
31
|
|
|
foreach (['required', 'allowed_signature_algorithms'] as $k) { |
32
|
|
|
$container->setParameter($path.'.'.$k, $config[$k]); |
33
|
|
|
} |
34
|
|
|
$container->setAlias($path.'.key_set', 'jose.key_set.client_registration_software_statement.key_set.signature'); |
35
|
|
|
|
36
|
|
|
$loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint')); |
37
|
|
|
$loader->load('client_registration_software_statement.php'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function name(): string |
44
|
|
|
{ |
45
|
|
|
return 'software_statement'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
52
|
|
|
{ |
53
|
|
|
|
54
|
|
|
$node |
55
|
|
|
->validate() |
56
|
|
|
->ifTrue(function ($config) { |
57
|
|
|
return true === $config['enabled'] && empty($config['key_set']); |
58
|
|
|
}) |
59
|
|
|
->thenInvalid('The option "key_set" must be set.') |
60
|
|
|
->end() |
61
|
|
|
->validate() |
62
|
|
|
->ifTrue(function ($config) { |
63
|
|
|
return true === $config['enabled'] && empty($config['allowed_signature_algorithms']); |
64
|
|
|
}) |
65
|
|
|
->thenInvalid('At least one signature algorithm must be set.') |
66
|
|
|
->end() |
67
|
|
|
->children() |
68
|
|
|
->booleanNode('required')->defaultFalse()->end() |
69
|
|
|
->scalarNode('key_set')->end() |
70
|
|
|
->arrayNode('allowed_signature_algorithms') |
71
|
|
|
->info('Signature algorithms allowed for the software statements. The algorithm "none" should not be used.') |
72
|
|
|
->useAttributeAsKey('name') |
73
|
|
|
->prototype('scalar')->end() |
74
|
|
|
->treatNullLike([]) |
75
|
|
|
->end() |
76
|
|
|
->end(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
83
|
|
|
{ |
84
|
|
|
parent::prepend($bundleConfig, $path, $container); |
85
|
|
|
$currentPath = $path.'['.$this->name().']'; |
86
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
87
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
88
|
|
|
|
89
|
|
|
if (true === $sourceConfig['enabled']) { |
90
|
|
|
// FIXME |
91
|
|
|
ConfigurationHelper::addJWSLoader($container, $this->name(), $sourceConfig['allowed_signature_algorithms'], [], ['jws_compact'], false); |
|
|
|
|
92
|
|
|
ConfigurationHelper::addKeyset($container, 'client_registration_software_statement.key_set.signature', 'jwkset', ['value' => $sourceConfig['key_set']]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|