GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — release-1.x ( a5e082...76423c )
by Boy
05:57 queued 02:54
created

SurfnetStepupExtension::defineLoas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
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\StepupBundle\DependencyInjection;
20
21
use Surfnet\StepupBundle\Value\Loa;
22
use Symfony\Component\Config\Definition\Processor;
23
use Symfony\Component\Config\FileLocator;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
use Symfony\Component\DependencyInjection\Definition;
26
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
27
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
28
use Symfony\Component\DependencyInjection\Reference;
29
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
30
31
class SurfnetStepupExtension extends Extension
32
{
33
    public function load(array $config, ContainerBuilder $container)
34
    {
35
        $processor = new Processor();
36
        $config = $processor->processConfiguration(new Configuration(), $config);
37
38
        $container->setParameter('logging.application_name', $config['logging']['application_name']);
39
40
        $loader = new YamlFileLoader(
41
            $container,
42
            new FileLocator(__DIR__ . '/../Resources/config')
43
        );
44
        $loader->load('services.yml');
45
46
        if (isset($config['loa_definition'])) {
47
            $this->defineLoas($config['loa_definition'], $container);
48
        } else {
49
            $container->removeDefinition('surfnet_stepup.service.loa_resolution');
50
        }
51
52
        if ($config['sms']['enabled'] === false) {
53
            $container->removeDefinition('surfnet_stepup.service.sms_second_factor');
54
            $container->removeDefinition('surfnet_stepup.service.challenge_handler');
55
            $container->removeDefinition('surfnet_stepup.service.sms_second_factor');
56
        } else {
57
            $smsSecondFactorService = $container->getDefinition('surfnet_stepup.service.sms_second_factor');
58
            $smsSecondFactorService->replaceArgument(2, $config['sms']['originator']);
59
60
            $container
61
                ->getDefinition('surfnet_stepup.service.challenge_handler')
62
                ->replaceArgument(2, $config['sms']['otp_expiry_interval'])
63
                ->replaceArgument(3, $config['sms']['maximum_otp_requests']);
64
65
            $container
66
                ->getDefinition('surfnet_stepup.service.sms_second_factor')
67
                ->replaceArgument(0, new Reference($config['sms']['service']));
68
69
            if (!$config['gateway_api']['enabled'] && $config['sms']['service'] === Configuration::DEFAULT_SMS_SERVICE) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
70
                throw new RuntimeException('The gateway API is not enabled and no replacement SMS service is configured');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
71
            }
72
        }
73
74
        if ($config['gateway_api']['enabled']) {
75
            # Configure the Gateway API SMS service's Guzzle client.
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
76
            $gatewayGuzzleOptions = [
77
                'base_url' => $config['gateway_api']['url'],
78
                'defaults' => [
79
                    'auth'    => [
80
                        $config['gateway_api']['credentials']['username'],
81
                        $config['gateway_api']['credentials']['password'],
82
                        'basic'
83
                    ],
84
                    'headers' => [
85
                        'Accept' => 'application/json'
86
                    ]
87
                ]
88
            ];
89
90
            $gatewayGuzzle = $container->getDefinition('surfnet_stepup.guzzle.gateway_api');
91
            $gatewayGuzzle->replaceArgument(0, $gatewayGuzzleOptions);
92
        } else {
93
            # Remove the Gateway API SMS service and its Guzzle client.
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
94
            $container->removeDefinition('surfnet_stepup.service.gateway_api_sms');
95
            $container->removeDefinition('surfnet_stepup.guzzle.gateway_api');
96
        }
97
98
        $container->getDefinition('surfnet_stepup.locale_cookie_settings')
99
            ->setArguments(
100
                [
101
                    $config['locale_cookie']['name'],
102
                    null,
103
                    $config['locale_cookie']['expire'],
104
                    $config['locale_cookie']['path'],
105
                    $config['locale_cookie']['domain'],
106
                    $config['locale_cookie']['secure'],
107
                    $config['locale_cookie']['http_only'],
108
                ]
109
            );
110
111
        $container->getDefinition('surfnet_stepup.form.choice_list.locales')
112
            ->replaceArgument(0, $container->getParameter('locales'));
113
    }
114
115
    private function defineLoas(array $loaDefinitions, ContainerBuilder $container)
116
    {
117
        $loaService = $container->getDefinition('surfnet_stepup.service.loa_resolution');
118
119
        $loa1 = new Definition('Surfnet\StepupBundle\Value\Loa', [Loa::LOA_1, $loaDefinitions['loa1']]);
120
        $loa2 = new Definition('Surfnet\StepupBundle\Value\Loa', [Loa::LOA_2, $loaDefinitions['loa2']]);
121
        $loa3 = new Definition('Surfnet\StepupBundle\Value\Loa', [Loa::LOA_3, $loaDefinitions['loa3']]);
122
123
        $loaService->addArgument([$loa1, $loa2, $loa3]);
124
    }
125
}
126