|
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\OpenIdConnect; |
|
15
|
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper; |
|
17
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
|
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
|
21
|
|
|
|
|
22
|
|
|
final class UserinfoEndpointEncryptionSource implements Component |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function name(): string |
|
28
|
|
|
{ |
|
29
|
|
|
return 'encryption'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
|
36
|
|
|
{ |
|
37
|
|
|
$container->setParameter($path.'.key_encryption_algorithms', $config['key_encryption_algorithms']); |
|
38
|
|
|
$container->setParameter($path.'.content_encryption_algorithms', $config['content_encryption_algorithms']); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
$node |
|
48
|
|
|
->validate() |
|
49
|
|
|
->ifTrue(function ($config) { |
|
50
|
|
|
return true === $config['enabled'] && empty($config['key_encryption_algorithms']); |
|
51
|
|
|
}) |
|
52
|
|
|
->thenInvalid('You must set at least one key encryption algorithm.') |
|
53
|
|
|
->end() |
|
54
|
|
|
->validate() |
|
55
|
|
|
->ifTrue(function ($config) { |
|
56
|
|
|
return true === $config['enabled'] && empty($config['content_encryption_algorithms']); |
|
57
|
|
|
}) |
|
58
|
|
|
->thenInvalid('You must set at least one content encryption algorithm.') |
|
59
|
|
|
->end() |
|
60
|
|
|
->children() |
|
61
|
|
|
->arrayNode('key_encryption_algorithms') |
|
62
|
|
|
->info('Supported key encryption algorithms.') |
|
63
|
|
|
->useAttributeAsKey('name') |
|
64
|
|
|
->prototype('scalar')->end() |
|
65
|
|
|
->treatNullLike([]) |
|
66
|
|
|
->end() |
|
67
|
|
|
->arrayNode('content_encryption_algorithms') |
|
68
|
|
|
->info('Supported content encryption algorithms.') |
|
69
|
|
|
->useAttributeAsKey('name') |
|
70
|
|
|
->prototype('scalar')->end() |
|
71
|
|
|
->treatNullLike([]) |
|
72
|
|
|
->end() |
|
73
|
|
|
->end(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
|
80
|
|
|
{ |
|
81
|
|
|
parent::prepend($bundleConfig, $path, $container); |
|
82
|
|
|
$currentPath = $path.'['.$this->name().']'; |
|
83
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
|
84
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
|
85
|
|
|
|
|
86
|
|
|
ConfigurationHelper::addJWEBuilder($container, 'oauth2_server.userinfo', $sourceConfig['key_encryption_algorithms'], $sourceConfig['content_encryption_algorithms'], ['DEF'], false); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|