|
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\ChildDefinition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Form login factory for Ldap. |
|
13
|
|
|
* |
|
14
|
|
|
* @author DarwinOnLine |
|
15
|
|
|
* @author Maks3w |
|
16
|
|
|
* |
|
17
|
|
|
* @see https://github.com/DarwinOnLine/DoLLdapBundle |
|
18
|
|
|
*/ |
|
19
|
|
|
class FormLoginLdapFactory 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
|
|
|
// authentication listener |
|
27
|
|
|
$listenerId = $this->createListener($container, $id, $config); |
|
28
|
|
|
|
|
29
|
|
|
return [$authProviderId, $listenerId, $defaultEntryPointId]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getPosition() |
|
33
|
|
|
{ |
|
34
|
|
|
return 'pre_auth'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getKey() |
|
38
|
|
|
{ |
|
39
|
|
|
return 'dol_ldap'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function addConfiguration(NodeDefinition $node) |
|
43
|
|
|
{ |
|
44
|
|
|
// Without Configuration |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function createAuthProvider(ContainerBuilder $container, $id, $userProviderId) |
|
48
|
|
|
{ |
|
49
|
|
|
$provider = 'dol_ldap.security.authentication.provider'; |
|
50
|
|
|
$providerId = $provider.'.'.$id; |
|
51
|
|
|
|
|
52
|
|
|
$container |
|
53
|
|
|
->setDefinition($providerId, new ChildDefinition($provider)) |
|
54
|
|
|
->replaceArgument(1, $id) // Provider Key |
|
55
|
|
|
->replaceArgument(2, new Reference($userProviderId)) // User Provider |
|
56
|
|
|
; |
|
57
|
|
|
|
|
58
|
|
|
return $providerId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function createListener(ContainerBuilder $container, $id, $config) |
|
62
|
|
|
{ |
|
63
|
|
|
$listenerId = 'security.authentication.listener.form'; |
|
64
|
|
|
|
|
65
|
|
|
$listener = new ChildDefinition($listenerId); |
|
66
|
|
|
$listener->replaceArgument(4, $id); |
|
67
|
|
|
$listener->replaceArgument(5, $config); |
|
68
|
|
|
|
|
69
|
|
|
$listenerId .= '.'.$id; |
|
70
|
|
|
$container |
|
71
|
|
|
->setDefinition($listenerId, $listener) |
|
72
|
|
|
; |
|
73
|
|
|
|
|
74
|
|
|
return $listenerId; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|