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