1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 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\SecondFactorOnlyBundle\Service; |
20
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Surfnet\StepupBundle\Service\LoaResolutionService as BaseResolutionService; |
23
|
|
|
|
24
|
|
|
class LoaResolutionService |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var LoggerInterface |
28
|
|
|
*/ |
29
|
|
|
private $logger; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var LoaAliasLookupService |
33
|
|
|
*/ |
34
|
|
|
private $loaAliasLookup; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var BaseResolutionService |
38
|
|
|
*/ |
39
|
|
|
private $loaResolution; |
40
|
|
|
|
41
|
|
|
public function __construct( |
42
|
|
|
LoggerInterface $logger, |
43
|
|
|
LoaAliasLookupService $loaAliasLookup, |
44
|
|
|
BaseResolutionService $loaResolution |
45
|
|
|
) { |
46
|
|
|
$this->logger = $logger; |
47
|
|
|
$this->loaAliasLookup = $loaAliasLookup; |
48
|
|
|
$this->loaResolution = $loaResolution; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param LoggerInterface $logger |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function with(LoggerInterface $logger) |
56
|
|
|
{ |
57
|
|
|
$this->logger = $logger; |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Resolves a LOA id. |
63
|
|
|
* |
64
|
|
|
* Returns the LOA id or an empty string if there is an issue. |
65
|
|
|
* |
66
|
|
|
* @param string $loaId |
67
|
|
|
* AuthnContextClassRef provided in AuthnRequest. |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
* LOA Id |
71
|
|
|
*/ |
72
|
|
|
public function resolve($loaId) |
73
|
|
|
{ |
74
|
|
|
if (empty($loaId)) { |
75
|
|
|
$this->logger->notice('No LOA requested, sending response with status Requester Error'); |
76
|
|
|
return ''; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$derefLoaId = $this->loaAliasLookup->findLoaIdByAlias($loaId); |
80
|
|
|
|
81
|
|
|
if (!$derefLoaId) { |
82
|
|
|
$this->logger->notice(sprintf( |
83
|
|
|
'Requested required Loa "%s" does not have a second factor alias', |
84
|
|
|
$loaId |
85
|
|
|
)); |
86
|
|
|
return ''; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if (!$this->loaResolution->hasLoa($derefLoaId)) { |
90
|
|
|
$this->logger->notice(sprintf( |
91
|
|
|
'Requested required Loa "%s" does not exist', |
92
|
|
|
$derefLoaId |
93
|
|
|
)); |
94
|
|
|
return ''; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $derefLoaId; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|