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\StepupRa\RaBundle\Service; |
20
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Surfnet\StepupMiddlewareClient\Exception\StepupMiddlewareClientException; |
23
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\VerifiedSecondFactorSearchQuery; |
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\VerifiedSecondFactor; |
25
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\SecondFactorService as ApiSecondFactorService; |
26
|
|
|
use Surfnet\StepupRa\RaBundle\Exception\RuntimeException; |
27
|
|
|
|
28
|
|
|
class SecondFactorService |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var \Surfnet\StepupMiddlewareClientBundle\Identity\Service\SecondFactorService |
32
|
|
|
*/ |
33
|
|
|
private $apiSecondFactorService; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Psr\Log\LoggerInterface |
37
|
|
|
*/ |
38
|
|
|
private $logger; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ApiSecondFactorService $apiSecondFactorService |
42
|
|
|
* @param LoggerInterface $logger |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
ApiSecondFactorService $apiSecondFactorService, |
46
|
|
|
LoggerInterface $logger |
47
|
|
|
) { |
48
|
|
|
$this->apiSecondFactorService = $apiSecondFactorService; |
49
|
|
|
$this->logger = $logger; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $registrationCode |
54
|
|
|
* @param string $actorInstitution |
|
|
|
|
55
|
|
|
* @param string $actorId |
56
|
|
|
* @return null|VerifiedSecondFactor |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
public function findVerifiedSecondFactorByRegistrationCode($registrationCode, $actorId) |
59
|
|
|
{ |
60
|
|
|
$query = new VerifiedSecondFactorSearchQuery(); |
61
|
|
|
$query->setActorId($actorId); |
62
|
|
|
$query->setRegistrationCode($registrationCode); |
63
|
|
|
|
64
|
|
|
try { |
65
|
|
|
$result = $this->apiSecondFactorService->searchVerified($query); |
66
|
|
|
} catch (StepupMiddlewareClientException $e) { |
67
|
|
|
$message = sprintf('Exception when searching verified second factors: "%s"', $e->getMessage()); |
68
|
|
|
$this->logger->critical($message); |
69
|
|
|
throw new RuntimeException($message, 0, $e); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** @var VerifiedSecondFactor[] $elements */ |
73
|
|
|
$elements = $result->getElements(); |
74
|
|
|
$elementCount = count($elements); |
75
|
|
|
|
76
|
|
|
if ($elementCount === 1) { |
77
|
|
|
return reset($elements); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($elementCount === 0) { |
81
|
|
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
throw new RuntimeException( |
85
|
|
|
sprintf('Got an unexpected amount of identities, expected 0 or 1, got "%d"', $elementCount) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.