1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 SURFnet B.V. |
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\GatewayBundle\Entity; |
20
|
|
|
|
21
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
22
|
|
|
use Psr\Log\LoggerInterface; |
23
|
|
|
use Surfnet\StepupBundle\Service\SecondFactorTypeService; |
24
|
|
|
use Surfnet\StepupBundle\Value\Loa; |
25
|
|
|
|
26
|
|
|
final class EnabledSecondFactorRepository implements SecondFactorRepository |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var \Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactorRepository |
30
|
|
|
*/ |
31
|
|
|
private $secondFactorRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string[] |
35
|
|
|
*/ |
36
|
|
|
private $enabledTypes; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var LoggerInterface |
40
|
|
|
*/ |
41
|
|
|
private $logger; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param SecondFactorRepository $secondFactorRepository |
45
|
|
|
* @param string[] $enabledTypes |
46
|
|
|
* @param LoggerInterface $logger |
47
|
|
|
*/ |
48
|
|
|
public function __construct( |
49
|
|
|
SecondFactorRepository $secondFactorRepository, |
50
|
|
|
array $enabledTypes, |
51
|
|
|
LoggerInterface $logger |
52
|
|
|
) { |
53
|
|
|
$this->secondFactorRepository = $secondFactorRepository; |
54
|
|
|
$this->enabledTypes = array_combine($enabledTypes, $enabledTypes); |
55
|
|
|
$this->logger = $logger; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getAllMatchingFor(Loa $highestLoa, $identityNameId, SecondFactorTypeService $service) |
59
|
|
|
{ |
60
|
|
|
$enabledSecondFactors = new ArrayCollection(); |
61
|
|
|
|
62
|
|
|
foreach ($this->secondFactorRepository->getAllMatchingFor($highestLoa, $identityNameId, $service) as $secondFactor) { |
|
|
|
|
63
|
|
|
if (!array_key_exists($secondFactor->secondFactorType, $this->enabledTypes)) { |
64
|
|
|
$this->logger->info( |
65
|
|
|
sprintf( |
66
|
|
|
'Discarding second factor; its second factor type "%s" is not enabled', |
67
|
|
|
$secondFactor->secondFactorType |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
continue; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$enabledSecondFactors->add($secondFactor); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $enabledSecondFactors; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function findOneBySecondFactorId($secondFactorId) |
81
|
|
|
{ |
82
|
|
|
$secondFactor = $this->secondFactorRepository->findOneBySecondFactorId($secondFactorId); |
83
|
|
|
|
84
|
|
|
if (!$secondFactor || !array_key_exists($secondFactor->secondFactorType, $this->enabledTypes)) { |
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $secondFactor; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getAllInstitutions($identityNameId) |
92
|
|
|
{ |
93
|
|
|
return $this->secondFactorRepository->getAllInstitutions($identityNameId); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.