|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoL\LdapBundle\Security\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* HTTP Basic factory for Ldap. |
|
13
|
|
|
* |
|
14
|
|
|
* @author DarwinOnLine |
|
15
|
|
|
* @author Maks3w |
|
16
|
|
|
* |
|
17
|
|
|
* @see https://github.com/DarwinOnLine/DoLLdapBundle |
|
18
|
|
|
*/ |
|
19
|
|
|
class HttpBasicLdapFactory implements SecurityFactoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public function create(ContainerBuilder $container, $id, $config, $userProviderId, $defaultEntryPointId) |
|
22
|
|
|
{ |
|
23
|
|
|
// authentication provider |
|
24
|
|
|
$authProviderId = $this->createAuthProvider($container, $id, $userProviderId); |
|
25
|
|
|
|
|
26
|
|
|
// entry point |
|
27
|
|
|
$entryPointId = $this->createEntryPoint($container, $id, $config, $defaultEntryPointId); |
|
28
|
|
|
|
|
29
|
|
|
// authentication listener |
|
30
|
|
|
$listenerId = $this->createListener($container, $id, $entryPointId); |
|
31
|
|
|
|
|
32
|
|
|
return [$authProviderId, $listenerId, $entryPointId]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getPosition() |
|
36
|
|
|
{ |
|
37
|
|
|
return 'http'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getKey() |
|
41
|
|
|
{ |
|
42
|
|
|
return 'dol_ldap_httpbasic'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function addConfiguration(NodeDefinition $node) |
|
46
|
|
|
{ |
|
47
|
|
|
$node |
|
48
|
|
|
->children() |
|
49
|
|
|
->scalarNode('provider')->end() |
|
50
|
|
|
->scalarNode('realm')->defaultValue('Secured Area')->end() |
|
51
|
|
|
->end() |
|
52
|
|
|
; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function createAuthProvider(ContainerBuilder $container, $id, $userProviderId) |
|
56
|
|
|
{ |
|
57
|
|
|
$provider = 'dol_ldap.security.authentication.provider'; |
|
58
|
|
|
$providerId = $provider.'.'.$id; |
|
59
|
|
|
|
|
60
|
|
|
$container |
|
61
|
|
|
->setDefinition($providerId, new ChildDefinition($provider)) |
|
62
|
|
|
->replaceArgument(1, $id) // Provider Key |
|
63
|
|
|
->replaceArgument(2, new Reference($userProviderId)) // User Provider |
|
64
|
|
|
; |
|
65
|
|
|
|
|
66
|
|
|
return $providerId; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function createListener(ContainerBuilder $container, $id, $entryPointId) |
|
70
|
|
|
{ |
|
71
|
|
|
// listener |
|
72
|
|
|
$listenerId = 'security.authentication.listener.basic.'.$id; |
|
73
|
|
|
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.basic')); |
|
74
|
|
|
$listener->replaceArgument(2, $id); |
|
75
|
|
|
$listener->replaceArgument(3, new Reference($entryPointId)); |
|
76
|
|
|
|
|
77
|
|
|
return $listenerId; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function createEntryPoint(ContainerBuilder $container, $id, $config, $defaultEntryPoint) |
|
81
|
|
|
{ |
|
82
|
|
|
if (null !== $defaultEntryPoint) { |
|
83
|
|
|
return $defaultEntryPoint; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$entryPointId = 'security.authentication.basic_entry_point.'.$id; |
|
87
|
|
|
$container |
|
88
|
|
|
->setDefinition($entryPointId, new ChildDefinition('security.authentication.basic_entry_point')) |
|
89
|
|
|
->addArgument($config['realm']) |
|
90
|
|
|
; |
|
91
|
|
|
|
|
92
|
|
|
return $entryPointId; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|