1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2019 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\ServerBundle\Component\Endpoint\Authorization; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper; |
17
|
|
|
use OAuth2Framework\ServerBundle\Component\Component; |
18
|
|
|
use OAuth2Framework\ServerBundle\Component\Endpoint\Authorization\Compiler\RequestObjectEncryptionCompilerPass; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
|
22
|
|
|
class RequestObjectEncryptionSource implements Component |
23
|
|
|
{ |
24
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
25
|
|
|
{ |
26
|
|
|
$config = $configs['endpoint']['authorization']['request_object']['encryption']; |
27
|
|
|
if (false === $config['enabled']) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
foreach (['required', 'key_set', 'key_encryption_algorithms', 'content_encryption_algorithms'] as $k) { |
31
|
|
|
$container->setParameter('oauth2_server.endpoint.authorization.request_object.encryption.'.$k, $config[$k]); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function name(): string |
36
|
|
|
{ |
37
|
|
|
return 'encryption'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode): void |
41
|
|
|
{ |
42
|
|
|
$node->children() |
43
|
|
|
->arrayNode($this->name()) |
44
|
|
|
->canBeEnabled() |
45
|
|
|
->children() |
46
|
|
|
->booleanNode('required') |
47
|
|
|
->info('If true, incoming request objects must be encrypted.') |
48
|
|
|
->defaultFalse() |
49
|
|
|
->end() |
50
|
|
|
->scalarNode('key_set') |
|
|
|
|
51
|
|
|
->info('The encryption private keys.') |
52
|
|
|
->isRequired() |
53
|
|
|
->end() |
54
|
|
|
->arrayNode('key_encryption_algorithms') |
55
|
|
|
->info('Supported key encryption algorithms.') |
56
|
|
|
->useAttributeAsKey('name') |
57
|
|
|
->scalarPrototype()->end() |
58
|
|
|
->treatNullLike([]) |
59
|
|
|
->end() |
60
|
|
|
->arrayNode('content_encryption_algorithms') |
61
|
|
|
->info('Supported content encryption algorithms.') |
62
|
|
|
->useAttributeAsKey('name') |
63
|
|
|
->scalarPrototype()->end() |
64
|
|
|
->treatNullLike([]) |
65
|
|
|
->end() |
66
|
|
|
->end() |
67
|
|
|
->end() |
68
|
|
|
->end() |
69
|
|
|
; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
73
|
|
|
{ |
74
|
|
|
$sourceConfig = $config['endpoint']['authorization']['request_object']['encryption']; |
75
|
|
|
if (true === $sourceConfig['enabled']) { |
76
|
|
|
ConfigurationHelper::addKeyset($container, 'oauth2_server.endpoint.authorization.request_object', 'jwkset', ['value' => $sourceConfig['key_set']]); |
77
|
|
|
ConfigurationHelper::addJWELoader($container, 'oauth2_server.endpoint.authorization.request_object', ['jwe_compact'], $sourceConfig['key_encryption_algorithms'], $sourceConfig['content_encryption_algorithms'], ['DEF'], [], false); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return []; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function build(ContainerBuilder $container): void |
84
|
|
|
{ |
85
|
|
|
$container->addCompilerPass(new RequestObjectEncryptionCompilerPass()); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|