|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
17
|
|
|
|
|
18
|
|
|
final class Configuration implements ConfigurationInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSource\JWKSourceInterface[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $jwk_sources; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource\JWKSetSourceInterface[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $jwk_set_sources; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $alias; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Configuration constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $alias |
|
39
|
|
|
* @param \SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSource\JWKSourceInterface[] $jwk_sources |
|
40
|
|
|
* @param \SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource\JWKSetSourceInterface[] $jwk_set_sources |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct($alias, array $jwk_sources, array $jwk_set_sources) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->alias = $alias; |
|
45
|
|
|
$this->jwk_sources = $jwk_sources; |
|
46
|
|
|
$this->jwk_set_sources = $jwk_set_sources; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getConfigTreeBuilder() |
|
53
|
|
|
{ |
|
54
|
|
|
$treeBuilder = new TreeBuilder(); |
|
55
|
|
|
$rootNode = $treeBuilder->root($this->alias); |
|
56
|
|
|
|
|
57
|
|
|
$this->addJWKSourcesSection($rootNode, $this->jwk_sources); |
|
58
|
|
|
$this->addJWKSetSourcesSection($rootNode, $this->jwk_set_sources); |
|
59
|
|
|
$this->addJWTLoaderSection($rootNode); |
|
60
|
|
|
$this->addJWTCreatorSection($rootNode); |
|
61
|
|
|
$this->addEncryptersSection($rootNode); |
|
62
|
|
|
$this->addDecryptersSection($rootNode); |
|
63
|
|
|
$this->addSignersSection($rootNode); |
|
64
|
|
|
$this->addVerifiersSection($rootNode); |
|
65
|
|
|
$this->addCheckersSection($rootNode); |
|
66
|
|
|
|
|
67
|
|
|
return $treeBuilder; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
72
|
|
|
* @param \SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSource\JWKSourceInterface[] $jwk_sources |
|
73
|
|
|
*/ |
|
74
|
|
|
private function addJWKSourcesSection(ArrayNodeDefinition $node, array $jwk_sources) |
|
75
|
|
|
{ |
|
76
|
|
|
$sourceNodeBuilder = $node |
|
77
|
|
|
->fixXmlConfig('source') |
|
78
|
|
|
->children() |
|
79
|
|
|
->arrayNode('keys') |
|
80
|
|
|
->useAttributeAsKey('name') |
|
81
|
|
|
->prototype('array') |
|
82
|
|
|
->performNoDeepMerging() |
|
83
|
|
|
->children(); |
|
84
|
|
|
foreach ($jwk_sources as $name => $source) { |
|
85
|
|
|
$sourceNode = $sourceNodeBuilder->arrayNode($name)->canBeUnset(); |
|
86
|
|
|
$source->addConfiguration($sourceNode); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
92
|
|
|
* @param \SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource\JWKSetSourceInterface[] $jwk_set_sources |
|
93
|
|
|
*/ |
|
94
|
|
|
private function addJWKSetSourcesSection(ArrayNodeDefinition $node, array $jwk_set_sources) |
|
95
|
|
|
{ |
|
96
|
|
|
$sourceNodeBuilder = $node |
|
97
|
|
|
->fixXmlConfig('source') |
|
98
|
|
|
->children() |
|
99
|
|
|
->arrayNode('key_sets') |
|
100
|
|
|
->useAttributeAsKey('name') |
|
101
|
|
|
->prototype('array') |
|
102
|
|
|
->performNoDeepMerging() |
|
103
|
|
|
->children(); |
|
104
|
|
|
foreach ($jwk_set_sources as $name => $source) { |
|
105
|
|
|
$sourceNode = $sourceNodeBuilder->arrayNode($name)->canBeUnset(); |
|
106
|
|
|
$source->addConfiguration($sourceNode); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
112
|
|
|
*/ |
|
113
|
|
|
private function addJWTCreatorSection(ArrayNodeDefinition $node) |
|
114
|
|
|
{ |
|
115
|
|
|
$node->children() |
|
116
|
|
|
->arrayNode('jwt_creators') |
|
117
|
|
|
->useAttributeAsKey('name') |
|
118
|
|
|
->prototype('array') |
|
119
|
|
|
->children() |
|
120
|
|
|
->scalarNode('signer')->isRequired()->end() |
|
121
|
|
|
->scalarNode('encrypter')->defaultNull()->end() |
|
122
|
|
|
->end() |
|
123
|
|
|
->end() |
|
124
|
|
|
->end() |
|
125
|
|
|
->end(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
130
|
|
|
*/ |
|
131
|
|
|
private function addJWTLoaderSection(ArrayNodeDefinition $node) |
|
132
|
|
|
{ |
|
133
|
|
|
$node->children() |
|
134
|
|
|
->arrayNode('jwt_loaders') |
|
135
|
|
|
->useAttributeAsKey('name') |
|
136
|
|
|
->prototype('array') |
|
137
|
|
|
->children() |
|
138
|
|
|
->scalarNode('verifier')->isRequired()->end() |
|
139
|
|
|
->scalarNode('checker')->isRequired()->end() |
|
140
|
|
|
->scalarNode('decrypter')->defaultNull()->end() |
|
141
|
|
|
->scalarNode('logger')->defaultNull()->end() |
|
142
|
|
|
->end() |
|
143
|
|
|
->end() |
|
144
|
|
|
->end() |
|
145
|
|
|
->end(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
150
|
|
|
*/ |
|
151
|
|
|
private function addDecryptersSection(ArrayNodeDefinition $node) |
|
152
|
|
|
{ |
|
153
|
|
|
$node->children() |
|
154
|
|
|
->arrayNode('decrypters') |
|
155
|
|
|
->useAttributeAsKey('name') |
|
156
|
|
|
->prototype('array') |
|
157
|
|
|
->children() |
|
158
|
|
|
->arrayNode('key_encryption_algorithms')->isRequired()->prototype('scalar')->end()->end() |
|
159
|
|
|
->arrayNode('content_encryption_algorithms')->isRequired()->prototype('scalar')->end()->end() |
|
160
|
|
|
->arrayNode('compression_methods')->defaultValue(['DEF'])->prototype('scalar')->end()->end() |
|
161
|
|
|
->scalarNode('logger')->defaultNull()->end() |
|
162
|
|
|
->booleanNode('create_decrypter')->defaultTrue()->end() |
|
163
|
|
|
->end() |
|
164
|
|
|
->end() |
|
165
|
|
|
->end() |
|
166
|
|
|
->end(); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
171
|
|
|
*/ |
|
172
|
|
|
private function addEncryptersSection(ArrayNodeDefinition $node) |
|
173
|
|
|
{ |
|
174
|
|
|
$node->children() |
|
175
|
|
|
->arrayNode('encrypters') |
|
176
|
|
|
->useAttributeAsKey('name') |
|
177
|
|
|
->prototype('array') |
|
178
|
|
|
->children() |
|
179
|
|
|
->arrayNode('key_encryption_algorithms')->isRequired()->prototype('scalar')->end()->end() |
|
180
|
|
|
->arrayNode('content_encryption_algorithms')->isRequired()->prototype('scalar')->end()->end() |
|
181
|
|
|
->arrayNode('compression_methods')->defaultValue(['DEF'])->prototype('scalar')->end()->end() |
|
182
|
|
|
->scalarNode('logger')->defaultNull()->end() |
|
183
|
|
|
->booleanNode('create_decrypter')->defaultTrue()->end() |
|
184
|
|
|
->end() |
|
185
|
|
|
->end() |
|
186
|
|
|
->end() |
|
187
|
|
|
->end(); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
192
|
|
|
*/ |
|
193
|
|
|
private function addSignersSection(ArrayNodeDefinition $node) |
|
194
|
|
|
{ |
|
195
|
|
|
$node->children() |
|
196
|
|
|
->arrayNode('signers') |
|
197
|
|
|
->useAttributeAsKey('name') |
|
198
|
|
|
->prototype('array') |
|
199
|
|
|
->children() |
|
200
|
|
|
->arrayNode('algorithms')->isRequired()->prototype('scalar')->end()->end() |
|
201
|
|
|
->scalarNode('logger')->defaultNull()->end() |
|
202
|
|
|
->booleanNode('create_verifier')->defaultTrue()->end() |
|
203
|
|
|
->end() |
|
204
|
|
|
->end() |
|
205
|
|
|
->end() |
|
206
|
|
|
->end(); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
211
|
|
|
*/ |
|
212
|
|
|
private function addCheckersSection(ArrayNodeDefinition $node) |
|
213
|
|
|
{ |
|
214
|
|
|
$node->children() |
|
215
|
|
|
->arrayNode('checkers') |
|
216
|
|
|
->useAttributeAsKey('name') |
|
217
|
|
|
->prototype('array') |
|
218
|
|
|
->children() |
|
219
|
|
|
->arrayNode('claims')->isRequired()->prototype('scalar')->end()->end() |
|
220
|
|
|
->arrayNode('headers')->isRequired()->prototype('scalar')->end()->end() |
|
221
|
|
|
->end() |
|
222
|
|
|
->end() |
|
223
|
|
|
->end() |
|
224
|
|
|
->end(); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
229
|
|
|
*/ |
|
230
|
|
|
private function addVerifiersSection(ArrayNodeDefinition $node) |
|
231
|
|
|
{ |
|
232
|
|
|
$node->children() |
|
233
|
|
|
->arrayNode('verifiers') |
|
234
|
|
|
->useAttributeAsKey('name') |
|
235
|
|
|
->prototype('array') |
|
236
|
|
|
->children() |
|
237
|
|
|
->arrayNode('algorithms')->isRequired()->prototype('scalar')->end()->end() |
|
238
|
|
|
->scalarNode('logger')->defaultNull()->end() |
|
239
|
|
|
->end() |
|
240
|
|
|
->end() |
|
241
|
|
|
->end() |
|
242
|
|
|
->end(); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|