1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OsLabSecurityApiBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) OsLab <https://github.com/OsLab> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OsLab\SecurityApiBundle\DependencyInjection\Security\UserProvider; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* InMemoryApiFactory creates services for the memory api provider. |
22
|
|
|
* |
23
|
|
|
* @author Michael COULLERET <[email protected]> |
24
|
|
|
* @author Florent DESPIERRES <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class InMemoryApiFactory implements UserProviderFactoryInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Creates the userProvider. |
30
|
|
|
* |
31
|
|
|
* @param ContainerBuilder $container instance of container |
32
|
|
|
* @param string $id the service id for concrete user provider |
33
|
|
|
* @param array $config configuration of current factory |
34
|
|
|
*/ |
35
|
3 |
|
public function create(ContainerBuilder $container, $id, $config) |
36
|
|
|
{ |
37
|
3 |
|
$definition = $container->setDefinition($id, new DefinitionDecorator('oslab_security_api.security.user.provider')); |
|
|
|
|
38
|
|
|
|
39
|
3 |
|
foreach ($config['users'] as $username => $user) { |
40
|
3 |
|
$userId = $id.'_'.$username; |
41
|
|
|
|
42
|
|
|
$container |
43
|
3 |
|
->setDefinition($userId, new DefinitionDecorator('security.user.provider.in_memory.user')) |
|
|
|
|
44
|
3 |
|
->setArguments([$username, (string) $user['password'], $user['roles']]) |
45
|
|
|
; |
46
|
|
|
|
47
|
3 |
|
$definition->addMethodCall('createUser', [new Reference($userId)]); |
48
|
|
|
} |
49
|
3 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns the key of current factory. |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
3 |
|
public function getKey() |
57
|
|
|
{ |
58
|
3 |
|
return 'memory_api'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Adds configuration nodes to current user provider. |
63
|
|
|
* |
64
|
|
|
* @param NodeDefinition $node |
65
|
|
|
*/ |
66
|
3 |
|
public function addConfiguration(NodeDefinition $node) |
67
|
|
|
{ |
68
|
|
|
$node |
69
|
3 |
|
->fixXmlConfig('user') |
70
|
3 |
|
->children() |
71
|
3 |
|
->arrayNode('users') |
72
|
3 |
|
->useAttributeAsKey('name') |
73
|
3 |
|
->prototype('array') |
74
|
3 |
|
->children() |
75
|
3 |
|
->scalarNode('password')->defaultValue(uniqid('', true))->end() |
76
|
3 |
|
->arrayNode('roles') |
77
|
3 |
|
->beforeNormalization()->ifString()->then(function ($v) { |
78
|
|
|
return preg_split('/\s*,\s*/', $v); |
79
|
3 |
|
}) |
80
|
3 |
|
->end() |
81
|
3 |
|
->prototype('scalar')->end() |
82
|
3 |
|
->end() |
83
|
3 |
|
->end() |
84
|
3 |
|
->end() |
85
|
3 |
|
->end() |
86
|
3 |
|
->end() |
87
|
|
|
; |
88
|
3 |
|
} |
89
|
|
|
} |
90
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.