createListener()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace Kuleuven\AuthenticationBundle\Security;
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\DefinitionDecorator;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
class ShibbolethAuthenticationListenerFactory implements SecurityFactoryInterface
12
{
13
    protected $key = 'kuleuven_authentication';
14
15
    public function getKey()
16
    {
17
        return $this->key;
18
    }
19
20
    public function getPosition()
21
    {
22
        return 'pre_auth';
23
    }
24
25
    public function addConfiguration(NodeDefinition $node)
26
    {
27
        $node
28
            ->children()
29
            ->scalarNode('provider')->defaultValue('kuleuven_authentication.service.shibboleth_user_provider')->end()
30
            ->arrayNode('default_roles')->prototype('scalar')->end()->defaultValue([])->end()
31
            ->end();
32
    }
33
34 View Code Duplication
    protected function createAuthenticationProvider(ContainerBuilder $container, $id, $userProvider)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $providerId = 'security.authentication.provider.' . $this->key . '.' . $id;
37
        $container
38
            ->setDefinition($providerId, new DefinitionDecorator($this->key . '.security.authentication.provider'))
39
            ->replaceArgument(0, new Reference($userProvider))
40
            ->replaceArgument(2, $this->key);
41
        return $providerId;
42
    }
43
44
    protected function createEntryPoint(ContainerBuilder $container, $id, $defaultEntryPoint)
45
    {
46
        if (null !== $defaultEntryPoint) {
47
            return $defaultEntryPoint;
48
        }
49
        $entryPointId = 'security.authentication.entry_point.' . $this->key . '.' . $id;
50
        $container->setDefinition($entryPointId, new DefinitionDecorator($this->key . '.security.authentication.entry_point'));
51
        return $entryPointId;
52
    }
53
54 View Code Duplication
    protected function createListener(ContainerBuilder $container, $id, $defaultRoles)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $listenerId = 'security.authentication.listener.' . $this->key . '.' . $id;
57
        $container
58
            ->setDefinition($listenerId, new DefinitionDecorator($this->key . '.security.authentication.listener'))
59
            ->replaceArgument(5, $defaultRoles)
60
            ->replaceArgument(6, $this->key);
61
62
        return $listenerId;
63
    }
64
65
    public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
66
    {
67
        $providerId = $this->createAuthenticationProvider($container, $id, $userProvider);
68
        $entryPointId = $this->createEntryPoint($container, $id, $defaultEntryPoint);
69
        $listenerId = $this->createListener($container, $id, $config['default_roles']);
70
71
        return [$providerId, $listenerId, $entryPointId];
72
    }
73
}
74