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\Source\JWKSetSource; |
13
|
|
|
|
14
|
|
|
use SpomkyLabs\JoseBundle\DependencyInjection\Source\AbstractSource; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
|
20
|
|
|
final class RandomKeySet extends AbstractSource implements JWKSetSourceInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function createDefinition(ContainerBuilder $container, array $config) |
26
|
|
|
{ |
27
|
|
|
if (true === $config['is_rotatable']) { |
28
|
|
|
$definition = new Definition('Jose\Object\RotatableJWKSet'); |
29
|
|
|
$method = 'createRotatableKeySet'; |
30
|
|
|
} else { |
31
|
|
|
$definition = new Definition('Jose\Object\StorableJWKSet'); |
32
|
|
|
$method = 'createStorableKeySet'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$definition->setFactory([ |
36
|
|
|
new Reference('jose.factory.jwk'), |
37
|
|
|
$method, |
38
|
|
|
]); |
39
|
|
|
$definition->setArguments([ |
40
|
|
|
$config['storage_path'], |
41
|
|
|
$config['key_configuration'], |
42
|
|
|
$config['nb_keys'], |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
return $definition; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getKeySet() |
52
|
|
|
{ |
53
|
|
|
return 'auto'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function addConfiguration(NodeDefinition $node) |
60
|
|
|
{ |
61
|
|
|
parent::addConfiguration($node); |
62
|
|
|
$node |
63
|
|
|
->children() |
64
|
|
|
->booleanNode('is_rotatable') |
65
|
|
|
->info('If true, the service will be a rotatable key, else just storable.') |
66
|
|
|
->defaultFalse() |
67
|
|
|
->end() |
68
|
|
|
->integerNode('nb_keys') |
69
|
|
|
->info('Number of keys in the key set.') |
70
|
|
|
->isRequired() |
71
|
|
|
->min(1) |
72
|
|
|
->end() |
73
|
|
|
->scalarNode('storage_path')->isRequired()->end() |
74
|
|
|
->arrayNode('key_configuration') |
75
|
|
|
->defaultValue([]) |
76
|
|
|
->useAttributeAsKey('key') |
77
|
|
|
->prototype('variable')->end() |
78
|
|
|
->end() |
79
|
|
|
->end(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|