Completed
Push — master ( fe5c1f...228ee9 )
by Nic
05:10 queued 02:42
created

parseSecondFactorTestIdentityProviderConfiguration()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 17
nc 3
nop 2
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\DependencyInjection;
20
21
use Surfnet\SamlBundle\Entity\IdentityProvider;
22
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
23
use Symfony\Component\Config\FileLocator;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
use Symfony\Component\DependencyInjection\Definition;
26
use Symfony\Component\DependencyInjection\Loader;
27
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
28
29
/**
30
 * This is the class that loads and manages your bundle configuration
31
 *
32
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
33
 */
34
class SurfnetStepupSelfServiceSelfServiceExtension extends Extension
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function load(array $configs, ContainerBuilder $container)
40
    {
41
        $configuration = new Configuration();
42
        $config = $this->processConfiguration($configuration, $configs);
43
44
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
45
        $loader->load('services.yml');
46
        $loader->load('security.yml');
47
48
        $container->getDefinition('self_service.locale.request_stack_locale_provider')
49
            ->replaceArgument(1, $container->getParameter('default_locale'))
50
            ->replaceArgument(2, $container->getParameter('locales'));
51
52
        $container->setParameter('ss.enabled_second_factors', $config['enabled_second_factors']);
53
54
        $container->setParameter(
55
            'self_service.security.authentication.session.maximum_absolute_lifetime_in_seconds',
56
            $config['session_lifetimes']['max_absolute_lifetime']
57
        );
58
        $container->setParameter(
59
            'self_service.security.authentication.session.maximum_relative_lifetime_in_seconds',
60
            $config['session_lifetimes']['max_relative_lifetime']
61
        );
62
63
        $this->parseSecondFactorTestIdentityProviderConfiguration(
64
            $config['second_factor_test_identity_provider'],
65
            $container
66
        );
67
    }
68
69
    /**
70
     * @param array            $identityProvider
71
     * @param ContainerBuilder $container
72
     */
73
    private function parseSecondFactorTestIdentityProviderConfiguration(
74
        array $identityProvider,
75
        ContainerBuilder $container
76
    ) {
77
        $definition = new Definition('Surfnet\SamlBundle\Entity\IdentityProvider');
78
        $configuration = [
79
            'entityId' => $identityProvider['entity_id'],
80
            'ssoUrl' => $identityProvider['sso_url'],
81
        ];
82
83
        if (isset($identityProvider['certificate_file']) && !isset($identityProvider['certificate'])) {
84
            $configuration['certificateFile'] = $identityProvider['certificate_file'];
85
        } elseif (isset($identityProvider['certificate'])) {
86
            $configuration['certificateData'] = $identityProvider['certificate'];
87
        } else {
88
            throw new InvalidConfigurationException(
89
                'Either "certificate_file" or "certificate" must be set in the ' .
90
                'surfnet_stepup_self_service_self_service.second_factor_test_identity_provider configuration.'
91
            );
92
        }
93
94
        $definition->setArguments([$configuration]);
95
        $container->setDefinition('self_service.second_factor_test_idp', $definition);
96
    }
97
}
98