FormLoginLdapFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 5
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
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