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\Grant; |
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
|
|
|
|
22
|
|
|
final class JwtBearerEncryptionSource extends ActionableSource |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
28
|
|
|
{ |
29
|
|
|
foreach (['key_encryption_algorithms', 'content_encryption_algorithms', 'required'] as $k) { |
30
|
|
|
$container->setParameter($path.'.'.$k, $config[$k]); |
31
|
|
|
} |
32
|
|
|
//$container->setAlias($path.'.key_set', 'jose.key_set.jwt_bearer.key_set.encryption'); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
protected function name(): string |
39
|
|
|
{ |
40
|
|
|
return 'encryption'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function continueConfiguration(NodeDefinition $node) |
44
|
|
|
{ |
45
|
|
|
parent::continueConfiguration($node); |
46
|
|
|
$node |
|
|
|
|
47
|
|
|
->children() |
48
|
|
|
->booleanNode('required') |
49
|
|
|
->info('If set to true, all ID Token sent to the server must be encrypted.') |
50
|
|
|
->defaultFalse() |
51
|
|
|
->end() |
52
|
|
|
->arrayNode('key_encryption_algorithms') |
53
|
|
|
->info('Supported key encryption algorithms.') |
54
|
|
|
->useAttributeAsKey('name') |
55
|
|
|
->prototype('scalar')->end() |
56
|
|
|
->treatNullLike([]) |
57
|
|
|
->end() |
58
|
|
|
->arrayNode('content_encryption_algorithms') |
59
|
|
|
->info('Supported content encryption algorithms.') |
60
|
|
|
->useAttributeAsKey('name') |
61
|
|
|
->prototype('scalar')->end() |
62
|
|
|
->treatNullLike([]) |
63
|
|
|
->end() |
64
|
|
|
->end(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
71
|
|
|
{ |
72
|
|
|
parent::prepend($bundleConfig, $path, $container); |
73
|
|
|
|
74
|
|
|
Assertion::keyExists($bundleConfig['key_set'], 'encryption', 'The encryption key set must be enabled.'); |
75
|
|
|
//ConfigurationHelper::addKeyset($container, 'jwt_bearer.key_set.encryption', 'jwkset', ['value' => $bundleConfig['key_set']['encryption']]); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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.