|
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 Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption; |
|
15
|
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source; |
|
17
|
|
|
use Jose\Component\Encryption\NestedTokenBuilderFactory; |
|
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
22
|
|
|
|
|
23
|
|
|
class NestedTokenBuilder implements Source |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function name(): string |
|
29
|
|
|
{ |
|
30
|
|
|
return 'builders'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
37
|
|
|
{ |
|
38
|
|
|
foreach ($configs[$this->name()] as $name => $itemConfig) { |
|
39
|
|
|
$service_id = sprintf('jose.nested_token_builder.%s', $name); |
|
40
|
|
|
$definition = new Definition(self::class); |
|
41
|
|
|
$definition |
|
42
|
|
|
->setFactory([new Reference(NestedTokenBuilderFactory::class), 'create']) |
|
43
|
|
|
->setArguments([ |
|
44
|
|
|
$itemConfig['jwe_serializers'], |
|
45
|
|
|
$itemConfig['key_encryption_algorithms'], |
|
46
|
|
|
$itemConfig['content_encryption_algorithms'], |
|
47
|
|
|
$itemConfig['compression_methods'], |
|
48
|
|
|
$itemConfig['jws_serializers'], |
|
49
|
|
|
$itemConfig['signature_algorithms'], |
|
50
|
|
|
]) |
|
51
|
|
|
->addTag('jose.nested_token_builder') |
|
52
|
|
|
->setPublic($itemConfig['is_public']); |
|
53
|
|
|
foreach ($itemConfig['tags'] as $id => $attributes) { |
|
54
|
|
|
$definition->addTag($id, $attributes); |
|
55
|
|
|
} |
|
56
|
|
|
$container->setDefinition($service_id, $definition); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
61
|
|
|
{ |
|
62
|
|
|
$node->children() |
|
63
|
|
|
->arrayNode($this->name()) |
|
64
|
|
|
->treatNullLike([]) |
|
65
|
|
|
->treatFalseLike([]) |
|
66
|
|
|
->useAttributeAsKey('name') |
|
67
|
|
|
->arrayPrototype() |
|
68
|
|
|
->children() |
|
69
|
|
|
->booleanNode('is_public') |
|
70
|
|
|
->info('If true, the service will be public, else private.') |
|
71
|
|
|
->defaultTrue() |
|
72
|
|
|
->end() |
|
73
|
|
|
->arrayNode('signature_algorithms') |
|
74
|
|
|
->info('A list of signature algorithm aliases.') |
|
75
|
|
|
->useAttributeAsKey('name') |
|
76
|
|
|
->isRequired() |
|
77
|
|
|
->scalarPrototype()->end() |
|
78
|
|
|
->end() |
|
79
|
|
|
->arrayNode('key_encryption_algorithms') |
|
80
|
|
|
->info('A list of key encryption algorithm aliases.') |
|
81
|
|
|
->useAttributeAsKey('name') |
|
82
|
|
|
->isRequired() |
|
83
|
|
|
->scalarPrototype()->end() |
|
84
|
|
|
->end() |
|
85
|
|
|
->arrayNode('content_encryption_algorithms') |
|
86
|
|
|
->info('A list of key encryption algorithm aliases.') |
|
87
|
|
|
->useAttributeAsKey('name') |
|
88
|
|
|
->isRequired() |
|
89
|
|
|
->scalarPrototype()->end() |
|
90
|
|
|
->end() |
|
91
|
|
|
->arrayNode('compression_methods') |
|
92
|
|
|
->info('A list of compression method aliases.') |
|
93
|
|
|
->useAttributeAsKey('name') |
|
94
|
|
|
->defaultValue(['DEF']) |
|
95
|
|
|
->scalarPrototype()->end() |
|
96
|
|
|
->end() |
|
97
|
|
|
->arrayNode('jws_serializers') |
|
98
|
|
|
->info('A list of JWS serializer aliases.') |
|
99
|
|
|
->useAttributeAsKey('name') |
|
100
|
|
|
->treatNullLike([]) |
|
101
|
|
|
->treatFalseLike([]) |
|
102
|
|
|
->isRequired() |
|
103
|
|
|
->requiresAtLeastOneElement() |
|
104
|
|
|
->scalarPrototype()->end() |
|
105
|
|
|
->end() |
|
106
|
|
|
->arrayNode('jwe_serializers') |
|
107
|
|
|
->info('A list of JWE serializer aliases.') |
|
108
|
|
|
->useAttributeAsKey('name') |
|
109
|
|
|
->treatNullLike([]) |
|
110
|
|
|
->treatFalseLike([]) |
|
111
|
|
|
->isRequired() |
|
112
|
|
|
->requiresAtLeastOneElement() |
|
113
|
|
|
->scalarPrototype()->end() |
|
114
|
|
|
->end() |
|
115
|
|
|
->arrayNode('tags') |
|
116
|
|
|
->info('A list of tags to be associated to the service.') |
|
117
|
|
|
->useAttributeAsKey('name') |
|
118
|
|
|
->treatNullLike([]) |
|
119
|
|
|
->treatFalseLike([]) |
|
120
|
|
|
->variablePrototype()->end() |
|
121
|
|
|
->end() |
|
122
|
|
|
->end() |
|
123
|
|
|
->end() |
|
124
|
|
|
->end(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* {@inheritdoc} |
|
129
|
|
|
*/ |
|
130
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
|
131
|
|
|
{ |
|
132
|
|
|
return []; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|