1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2021 SURF 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\StepupSelfService\SelfServiceBundle\Service; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupBundle\Service\SecondFactorTypeService; |
22
|
|
|
use Surfnet\StepupBundle\Value\SecondFactorType; |
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\VettedSecondFactor; |
25
|
|
|
|
26
|
|
|
class SelfVetMarshaller implements VettingMarshaller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var SecondFactorService |
30
|
|
|
*/ |
31
|
|
|
private $secondFactorService; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var SecondFactorTypeService |
35
|
|
|
*/ |
36
|
|
|
private $secondFactorTypeService; |
37
|
|
|
|
38
|
|
|
public function __construct( |
39
|
|
|
SecondFactorService $secondFactorService, |
40
|
|
|
SecondFactorTypeService $secondFactorTypeService |
41
|
|
|
) { |
42
|
|
|
$this->secondFactorService = $secondFactorService; |
43
|
|
|
$this->secondFactorTypeService = $secondFactorTypeService; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* You are allowed to self vet when: |
48
|
|
|
* 1. You already have a vetted token |
49
|
|
|
* 2. The vetted token has higher LoA (or equal) to the one being vetted |
50
|
|
|
*/ |
51
|
|
|
public function isAllowed(Identity $identity, string $secondFactorId): bool |
52
|
|
|
{ |
53
|
|
|
$vettedSecondFactors = $this->secondFactorService->findVettedByIdentity($identity->id); |
54
|
|
|
if ($vettedSecondFactors->getTotalItems() === 0) { |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
$candidateToken = $this->secondFactorService->findOneVerified($secondFactorId); |
58
|
|
|
if ($candidateToken) { |
59
|
|
|
/** @var VettedSecondFactor $authoringSecondFactor */ |
60
|
|
|
foreach ($vettedSecondFactors->getElements() as $authoringSecondFactor) { |
61
|
|
|
$hasSuitableToken = $this->secondFactorTypeService->hasEqualOrLowerLoaComparedTo( |
62
|
|
|
new SecondFactorType($candidateToken->type), |
63
|
|
|
new SecondFactorType($authoringSecondFactor->type) |
64
|
|
|
); |
65
|
|
|
if ($hasSuitableToken) { |
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|