|
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\JWKSource\JWKSourceInterface[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $jwk_sources; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $alias; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Configuration constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $alias |
|
34
|
|
|
* @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[] $jwk_sources |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct($alias, array $jwk_sources) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->alias = $alias; |
|
39
|
|
|
$this->jwk_sources = $jwk_sources; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getConfigTreeBuilder() |
|
46
|
|
|
{ |
|
47
|
|
|
$treeBuilder = new TreeBuilder(); |
|
48
|
|
|
$rootNode = $treeBuilder->root($this->alias); |
|
49
|
|
|
|
|
50
|
|
|
$this->addJWKSourcesSection($rootNode, $this->jwk_sources); |
|
51
|
|
|
|
|
52
|
|
|
$rootNode |
|
53
|
|
|
->children() |
|
54
|
|
|
->arrayNode('compression_methods') |
|
55
|
|
|
->info('A list of enabled compression methods. Supported methods are: "DEF" (recommended), "GZ" and "ZLIB".') |
|
56
|
|
|
->prototype('scalar') |
|
57
|
|
|
->end() |
|
58
|
|
|
->treatNullLike([]) |
|
59
|
|
|
->end() |
|
60
|
|
|
->arrayNode('key_sets') |
|
61
|
|
|
->defaultValue([]) |
|
62
|
|
|
->useAttributeAsKey('key') |
|
63
|
|
|
->prototype('array') |
|
64
|
|
|
->prototype('scalar') |
|
65
|
|
|
->end() |
|
66
|
|
|
->end() |
|
67
|
|
|
->end() |
|
68
|
|
|
->arrayNode('storage') |
|
69
|
|
|
->addDefaultsIfNotSet() |
|
70
|
|
|
->validate() |
|
71
|
|
|
->ifTrue(function ($value) { |
|
72
|
|
|
return true === $value['enabled'] && null !== $value['class'] && !class_exists($value['class']); |
|
73
|
|
|
}) |
|
74
|
|
|
->thenInvalid('The class does not exist') |
|
75
|
|
|
->end() |
|
76
|
|
|
->children() |
|
77
|
|
|
->booleanNode('enabled') |
|
78
|
|
|
->info('If true, the storage is used and "jti" header parameter is added.') |
|
79
|
|
|
->defaultFalse() |
|
80
|
|
|
->end() |
|
81
|
|
|
->scalarNode('manager') |
|
82
|
|
|
->info('The "jot" manager.') |
|
83
|
|
|
->defaultValue('jose.jot_manager.default') |
|
84
|
|
|
->cannotBeEmpty() |
|
85
|
|
|
->end() |
|
86
|
|
|
->scalarNode('class') |
|
87
|
|
|
->info('The "jot" class.') |
|
88
|
|
|
->defaultNull() |
|
89
|
|
|
->end() |
|
90
|
|
|
->end() |
|
91
|
|
|
->end() |
|
92
|
|
|
->end(); |
|
93
|
|
|
|
|
94
|
|
|
return $treeBuilder; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
|
99
|
|
|
* @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[] $jwk_sources |
|
100
|
|
|
*/ |
|
101
|
|
|
private function addJWKSourcesSection(ArrayNodeDefinition $node, array $jwk_sources) |
|
102
|
|
|
{ |
|
103
|
|
|
$sourceNodeBuilder = $node |
|
104
|
|
|
->fixXmlConfig('source') |
|
105
|
|
|
->children() |
|
106
|
|
|
->arrayNode('keys') |
|
107
|
|
|
->useAttributeAsKey('name') |
|
108
|
|
|
->prototype('array') |
|
109
|
|
|
->performNoDeepMerging() |
|
110
|
|
|
->children(); |
|
111
|
|
|
foreach ($jwk_sources as $name => $source) { |
|
112
|
|
|
$sourceNode = $sourceNodeBuilder->arrayNode($name)->canBeUnset(); |
|
113
|
|
|
$source->addConfiguration($sourceNode); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|