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 Assert\Assertion; |
17
|
|
|
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper; |
18
|
|
|
use OAuth2Framework\Bundle\Server\DependencyInjection\Source\ActionableSource; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
22
|
|
|
|
23
|
|
|
final class SignedMetadataEndpointSource extends ActionableSource |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
29
|
|
|
{ |
30
|
|
|
$container->setParameter($path.'.algorithm', $config['algorithm']); |
31
|
|
|
//$container->setAlias($path.'.key_set', 'jose.key_set.signed_metadata_endpoint.key_set.signature'); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
protected function name(): string |
38
|
|
|
{ |
39
|
|
|
return 'signature'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
protected function continueConfiguration(NodeDefinition $node) |
46
|
|
|
{ |
47
|
|
|
parent::continueConfiguration($node); |
48
|
|
|
$node |
|
|
|
|
49
|
|
|
->validate() |
50
|
|
|
->ifTrue(function ($config) { |
51
|
|
|
return true === $config['enabled'] && empty($config['algorithm']); |
52
|
|
|
}) |
53
|
|
|
->thenInvalid('The parameter "algorithm" must be set.') |
54
|
|
|
->end() |
55
|
|
|
->children() |
56
|
|
|
->scalarNode('algorithm') |
57
|
|
|
->info('Signature algorithm used to sign the metadata.') |
58
|
|
|
->end() |
59
|
|
|
->end(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
63
|
|
|
{ |
64
|
|
|
parent::prepend($bundleConfig, $path, $container); |
65
|
|
|
$currentPath = $path.'['.$this->name().']'; |
66
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
67
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
68
|
|
|
|
69
|
|
|
ConfigurationHelper::addJWSBuilder($container, 'metadata_signature', [$sourceConfig['algorithm']], false); |
70
|
|
|
|
71
|
|
|
Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.'); |
72
|
|
|
//ConfigurationHelper::addKeyset($container, 'signed_metadata_endpoint.key_set.signature', 'jwkset', ['value' => $bundleConfig['key_set']['signature']]); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.