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\StepupMiddlewareClient\Identity\Service; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupMiddlewareClient\Exception\AccessDeniedToResourceException; |
22
|
|
|
use Surfnet\StepupMiddlewareClient\Exception\MalformedResponseException; |
23
|
|
|
use Surfnet\StepupMiddlewareClient\Exception\ResourceReadException; |
24
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\UnverifiedSecondFactorSearchQuery; |
25
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\VerifiedSecondFactorOfIdentitySearchQuery; |
26
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\VerifiedSecondFactorSearchQuery; |
27
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\VettedSecondFactorSearchQuery; |
28
|
|
|
use Surfnet\StepupMiddlewareClient\Service\ApiService; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Provides remote read access to the Middleware's second factors. |
32
|
|
|
*/ |
33
|
|
|
class SecondFactorService |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var ApiService |
37
|
|
|
*/ |
38
|
|
|
private $apiService; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ApiService $apiService |
42
|
|
|
*/ |
43
|
|
|
public function __construct(ApiService $apiService) |
44
|
|
|
{ |
45
|
|
|
$this->apiService = $apiService; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $secondFactorId |
50
|
|
|
* @return null|array |
51
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
52
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
53
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
54
|
|
|
*/ |
55
|
|
|
public function getUnverified($secondFactorId) |
56
|
|
|
{ |
57
|
|
|
return $this->apiService->read('unverified-second-factor/%s', [$secondFactorId]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $secondFactorId |
62
|
|
|
* @return null|array |
63
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
64
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
65
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
66
|
|
|
*/ |
67
|
|
|
public function getVerified($secondFactorId) |
68
|
|
|
{ |
69
|
|
|
return $this->apiService->read('verified-second-factor/%s', [$secondFactorId]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $secondFactorId |
75
|
|
|
* @return null|array |
76
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
77
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
78
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
79
|
|
|
*/ |
80
|
|
|
public function getVerifiedCanSkipProvePossession($secondFactorId) |
81
|
|
|
{ |
82
|
|
|
return $this->apiService->read('verified-second-factor/%s/skip-prove-possession', [$secondFactorId]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $secondFactorId |
87
|
|
|
* @return null|array |
88
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
89
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
90
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
91
|
|
|
*/ |
92
|
|
|
public function getVetted($secondFactorId) |
93
|
|
|
{ |
94
|
|
|
return $this->apiService->read('vetted-second-factor/%s', [$secondFactorId]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param UnverifiedSecondFactorSearchQuery $query |
99
|
|
|
* @return null|array |
100
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
101
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
102
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
103
|
|
|
*/ |
104
|
|
|
public function searchUnverified(UnverifiedSecondFactorSearchQuery $query) |
105
|
|
|
{ |
106
|
|
|
return $this->apiService->read('unverified-second-factors' . $query->toHttpQuery()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param VerifiedSecondFactorSearchQuery $query |
111
|
|
|
* @return null|array |
112
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
113
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
114
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
115
|
|
|
*/ |
116
|
|
|
public function searchVerified(VerifiedSecondFactorSearchQuery $query) |
117
|
|
|
{ |
118
|
|
|
return $this->apiService->read('verified-second-factors' . $query->toHttpQuery()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param VerifiedSecondFactorOfIdentitySearchQuery $query |
123
|
|
|
* @return null|array |
124
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
125
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
126
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
127
|
|
|
*/ |
128
|
|
|
public function searchOwnVerified(VerifiedSecondFactorOfIdentitySearchQuery $query) |
129
|
|
|
{ |
130
|
|
|
return $this->apiService->read('verified-second-factors-of-identity' . $query->toHttpQuery()); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param VettedSecondFactorSearchQuery $query |
135
|
|
|
* @return null|array |
136
|
|
|
* @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
137
|
|
|
* @throws ResourceReadException When the server doesn't respond with the resource. |
138
|
|
|
* @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON. |
139
|
|
|
*/ |
140
|
|
|
public function searchVetted(VettedSecondFactorSearchQuery $query) |
141
|
|
|
{ |
142
|
|
|
return $this->apiService->read('vetted-second-factors' . $query->toHttpQuery()); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|