SurfnetStepupSelfServiceSelfServiceExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 34 1
A parseActivationFlowPreferenceConfiguration() 0 9 1
A parseSecondFactorTestIdentityProviderConfiguration() 0 24 4
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2014 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\DependencyInjection;
22
23
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ActivationFlowService;
24
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
25
use Symfony\Component\Config\FileLocator;
26
use Symfony\Component\DependencyInjection\ContainerBuilder;
27
use Symfony\Component\DependencyInjection\Definition;
28
use Symfony\Component\DependencyInjection\Loader;
29
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
30
use Surfnet\SamlBundle\Entity\IdentityProvider;
31
32
/**
33
 * This is the class that loads and manages your bundle configuration
34
 *
35
 * @SuppressWarnings(PHPMD.LongClassName)
36
 *
37
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
38
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
39
class SurfnetStepupSelfServiceSelfServiceExtension extends Extension
40
{
41
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $configs should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $container should have a doc-comment as per coding-style.
Loading history...
42
     * {@inheritdoc}
43
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
44
    public function load(array $configs, ContainerBuilder $container): void
45
    {
46
        $configuration = new Configuration();
47
        $config = $this->processConfiguration($configuration, $configs);
48
49
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
50
        $loader->load('services.yaml');
51
        $loader->load('security.yaml');
52
53
        $container->getDefinition('self_service.locale.request_stack_locale_provider')
54
            ->replaceArgument(1, $container->getParameter('default_locale'))
55
            ->replaceArgument(2, $container->getParameter('locales'));
56
        // Enabled second factor types (specific and generic) are merged into 'ss.enabled_second_factors'
57
        $gssfSecondFactors = array_keys($config['enabled_generic_second_factors']);
58
        $container->setParameter(
59
            'ss.enabled_second_factors',
60
            array_unique(array_merge($config['enabled_second_factors'], $gssfSecondFactors))
61
        );
62
63
        $container->setParameter(
64
            'self_service.security.authentication.session.maximum_absolute_lifetime_in_seconds',
65
            $config['session_lifetimes']['max_absolute_lifetime']
66
        );
67
        $container->setParameter(
68
            'self_service.security.authentication.session.maximum_relative_lifetime_in_seconds',
69
            $config['session_lifetimes']['max_relative_lifetime']
70
        );
71
        $this->parseSecondFactorTestIdentityProviderConfiguration(
72
            $config['second_factor_test_identity_provider'],
73
            $container
74
        );
75
        $this->parseActivationFlowPreferenceConfiguration(
76
            $config['preferred_activation_flow'],
77
            $container
78
        );
79
    }
80
81
    private function parseSecondFactorTestIdentityProviderConfiguration(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function parseSecondFactorTestIdentityProviderConfiguration()
Loading history...
Coding Style introduced by
Private method name "SurfnetStepupSelfServiceSelfServiceExtension::parseSecondFactorTestIdentityProviderConfiguration" must be prefixed with an underscore
Loading history...
82
        array $identityProvider,
83
        ContainerBuilder $container
84
    ): void {
85
        $definition = new Definition(IdentityProvider::class);
86
        $configuration = [
87
            'entityId' => $identityProvider['entity_id'],
88
            'ssoUrl' => $identityProvider['sso_url'],
89
        ];
90
91
        if (isset($identityProvider['certificate_file']) && !isset($identityProvider['certificate'])) {
92
            $configuration['certificateFile'] = $identityProvider['certificate_file'];
93
        } elseif (isset($identityProvider['certificate'])) {
94
            $configuration['certificateData'] = $identityProvider['certificate'];
95
        } else {
96
            throw new InvalidConfigurationException(
97
                'Either "certificate_file" or "certificate" must be set in the ' .
98
                'surfnet_stepup_self_service_self_service.second_factor_test_identity_provider configuration.'
99
            );
100
        }
101
102
        $definition->setArguments([$configuration]);
103
        $definition->setPublic(true);
104
        $container->setDefinition('self_service.second_factor_test_idp', $definition);
105
    }
106
107
    private function parseActivationFlowPreferenceConfiguration(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function parseActivationFlowPreferenceConfiguration()
Loading history...
Coding Style introduced by
Private method name "SurfnetStepupSelfServiceSelfServiceExtension::parseActivationFlowPreferenceConfiguration" must be prefixed with an underscore
Loading history...
108
        array $preferenceConfig,
109
        ContainerBuilder $container
110
    ): void {
111
        $container->getDefinition(ActivationFlowService::class)
112
            ->replaceArgument(3, $preferenceConfig['query_string_field_name'])
113
            ->replaceArgument(4, $preferenceConfig['options'])
114
            ->replaceArgument(5, $preferenceConfig['saml_attribute_field_name'])
115
            ->replaceArgument(6, $preferenceConfig['saml_attributes']);
116
    }
117
}
118