FixtureService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 10
rs 10
1
<?php
2
3
/**
4
 * Copyright 2020 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\StepupGateway\Behat\Service;
20
21
use Exception;
22
use Surfnet\StepupGateway\Behat\Repository\InstitutionConfigurationRepository;
23
use Surfnet\StepupGateway\Behat\Repository\SamlEntityRepository;
24
use Surfnet\StepupGateway\Behat\Repository\SecondFactorRepository;
25
use Surfnet\StepupGateway\Behat\Repository\WhitelistRepository;
26
27
class FixtureService
28
{
29
    private $secondFactorRepository;
30
31
    private $samlEntityRepository;
32
33
    private $whitelistRepository;
34
35
    private $institutionConfigurationRepository;
36
37
    public function __construct(
38
        SecondFactorRepository $secondFactorRepository,
39
        SamlEntityRepository $samlRepository,
40
        WhitelistRepository $whitelistRepository,
41
        InstitutionConfigurationRepository $institutionConfigurationRepository
42
    ) {
43
        $this->secondFactorRepository = $secondFactorRepository;
44
        $this->samlEntityRepository = $samlRepository;
45
        $this->whitelistRepository = $whitelistRepository;
46
        $this->institutionConfigurationRepository = $institutionConfigurationRepository;
47
    }
48
49
    public function registerYubikeyToken(string $nameId, string $institution, bool $selfAsserted = false): array
50
    {
51
        if (!$this->secondFactorRepository->has($nameId, 'yubikey')) {
52
            return $this->secondFactorRepository->create($nameId, 'yubikey', $institution, $selfAsserted);
53
        }
54
        return $this->secondFactorRepository->findBy($nameId, 'yubikey');
55
56
    }
57
58
    /**
59
     * @param string $nameId
60
     * @param string $institution
61
     * @return array
62
     * @throws Exception
63
     */
64
    public function registerSmsToken(string $nameId, string $institution, bool $selfAsserted = false): array
65
    {
66
        if (!$this->secondFactorRepository->has($nameId, 'sms')) {
67
            return $this->secondFactorRepository->create($nameId, 'sms', $institution, $selfAsserted, '+31 (0) 606060606');
68
        }
69
        return $this->secondFactorRepository->findBy($nameId, 'sms');
70
    }
71
72
    /**
73
     * @param string $entityId
74
     * @param string $certificate
75
     * @param bool $sfoEnabled
76
     * @return array
77
     * @throws Exception
78
     */
79
    public function registerSP($entityId, $certificate, $sfoEnabled = false)
80
    {
81
        return $this->samlEntityRepository->createSpIfNotExists($entityId, $certificate, $sfoEnabled);
82
    }
83
84
    /**
85
     * @param string $entityId
86
     * @param string $certificate
87
     * @return array
88
     * @throws Exception
89
     */
90
    public function registerIdp($entityId, $certificate)
91
    {
92
        return $this->samlEntityRepository->createIdpIfNotExists($entityId, $certificate);
93
    }
94
95
    /**
96
     * @param string $institution
97
     * @return array
98
     * @throws Exception
99
     */
100
    public function whitelist($institution)
101
    {
102
        return $this->whitelistRepository->whitelist($institution);
103
    }
104
105
    public function registerTiqrToken(string $nameId, string $institution, bool $selfAsserted = false): array
106
    {
107
        if (!$this->secondFactorRepository->has($nameId, 'tiqr')) {
108
            return $this->secondFactorRepository->create($nameId, 'tiqr', $institution, $selfAsserted, 'foobar');
109
        }
110
        return $this->secondFactorRepository->findBy($nameId, 'tiqr');
111
    }
112
113
    public function configureBoolean(string $institution, string $option, bool $value): void
114
    {
115
        $this->institutionConfigurationRepository->configure($institution, $option, $value);
116
    }
117
}
118