1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 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\Server\DependencyInjection\Source\Endpoint; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\Server\DependencyInjection\Source\ActionableSource; |
17
|
|
|
use SpomkyLabs\JoseBundle\Helper\ConfigurationHelper; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
21
|
|
|
|
22
|
|
|
final class SignedMetadataEndpointSource extends ActionableSource |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
28
|
|
|
{ |
29
|
|
|
$container->setParameter($path.'.algorithm', $config['algorithm']); |
30
|
|
|
$container->setAlias($path.'.key_set', $config['key_set']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
protected function name(): string |
37
|
|
|
{ |
38
|
|
|
return 'signature'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function continueConfiguration(NodeDefinition $node) |
45
|
|
|
{ |
46
|
|
|
parent::continueConfiguration($node); |
47
|
|
|
$node |
48
|
|
|
->validate() |
49
|
|
|
->ifTrue(function ($config) { |
50
|
|
|
return true === $config['enabled'] && empty($config['algorithm']); |
51
|
|
|
}) |
52
|
|
|
->thenInvalid('The parameter "algorithm" must be set.') |
53
|
|
|
->end() |
54
|
|
|
->validate() |
55
|
|
|
->ifTrue(function ($config) { |
56
|
|
|
return true === $config['enabled'] && empty($config['key_set']); |
57
|
|
|
}) |
58
|
|
|
->thenInvalid('The parameter "key_set" must be set.') |
59
|
|
|
->end() |
60
|
|
|
->children() |
61
|
|
|
->scalarNode('algorithm') |
62
|
|
|
->info('Signature algorithm used to sign the metadata.') |
63
|
|
|
->end() |
64
|
|
|
->scalarNode('key_set') |
65
|
|
|
->info('Signature key set.') |
66
|
|
|
->end() |
67
|
|
|
->end(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
71
|
|
|
{ |
72
|
|
|
parent::prepend($bundleConfig, $path, $container); |
73
|
|
|
$currentPath = $path.'['.$this->name().']'; |
74
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
75
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
76
|
|
|
$this->updateJoseBundleConfigurationForSigner($container, $sourceConfig); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param ContainerBuilder $container |
81
|
|
|
* @param array $sourceConfig |
82
|
|
|
*/ |
83
|
|
|
private function updateJoseBundleConfigurationForSigner(ContainerBuilder $container, array $sourceConfig) |
84
|
|
|
{ |
85
|
|
|
ConfigurationHelper::addSigner($container, 'metadata_signature', [$sourceConfig['algorithm']], false, false); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|