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\Dto; |
20
|
|
|
|
21
|
|
|
use Assert; |
22
|
|
|
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery; |
23
|
|
|
|
24
|
|
|
final class RaSecondFactorSearchQuery implements HttpQuery |
25
|
|
|
{ |
26
|
|
|
const STATUS_UNVERIFIED = 'unverified'; |
27
|
|
|
const STATUS_VERIFIED = 'verified'; |
28
|
|
|
const STATUS_VETTED = 'vetted'; |
29
|
|
|
const STATUS_REVOKED = 'revoked'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $name; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string|null |
38
|
|
|
*/ |
39
|
|
|
private $type; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string|null The second factor type's ID (eg. Yubikey public ID) |
43
|
|
|
*/ |
44
|
|
|
private $secondFactorId; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string|null |
48
|
|
|
*/ |
49
|
|
|
private $email; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string|null One of the STATUS_* constants. |
53
|
|
|
*/ |
54
|
|
|
private $status; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string|null |
58
|
|
|
*/ |
59
|
|
|
private $institution; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string|null |
63
|
|
|
*/ |
64
|
|
|
private $orderBy; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var string|null |
68
|
|
|
*/ |
69
|
|
|
private $orderDirection; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var int |
73
|
|
|
*/ |
74
|
|
|
private $pageNumber; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
private $actorId; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param int $pageNumber |
83
|
|
|
* @param string $actorId |
84
|
|
|
*/ |
85
|
|
|
public function __construct($pageNumber, $actorId) |
86
|
|
|
{ |
87
|
|
|
Assert\that($pageNumber) |
88
|
|
|
->integer('Page number must be an integer') |
89
|
|
|
->min(1, 'Page number must be greater than or equal to 1'); |
90
|
|
|
|
91
|
|
|
$this->actorId = $actorId; |
92
|
|
|
$this->pageNumber = $pageNumber; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $actorId |
97
|
|
|
* @return VerifiedSecondFactorSearchQuery |
|
|
|
|
98
|
|
|
*/ |
99
|
|
|
public function setActorId($actorId) |
100
|
|
|
{ |
101
|
|
|
$this->assertNonEmptyString($actorId, 'actorId'); |
102
|
|
|
|
103
|
|
|
$this->actorId = $actorId; |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return null|string |
110
|
|
|
*/ |
111
|
|
|
public function getName() |
112
|
|
|
{ |
113
|
|
|
return $this->name; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param null|string $name |
118
|
|
|
*/ |
119
|
|
|
public function setName($name) |
120
|
|
|
{ |
121
|
|
|
$this->assertNonEmptyString($name, 'name'); |
122
|
|
|
|
123
|
|
|
$this->name = $name; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return null|string |
128
|
|
|
*/ |
129
|
|
|
public function getType() |
130
|
|
|
{ |
131
|
|
|
return $this->type; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param null|string $type |
136
|
|
|
*/ |
137
|
|
|
public function setType($type) |
138
|
|
|
{ |
139
|
|
|
$this->assertNonEmptyString($type, 'type'); |
140
|
|
|
|
141
|
|
|
$this->type = $type; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return null|string |
146
|
|
|
*/ |
147
|
|
|
public function getSecondFactorId() |
148
|
|
|
{ |
149
|
|
|
return $this->secondFactorId; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param null|string $secondFactorId |
154
|
|
|
*/ |
155
|
|
|
public function setSecondFactorId($secondFactorId) |
156
|
|
|
{ |
157
|
|
|
$this->assertNonEmptyString($secondFactorId, 'secondFactorId'); |
158
|
|
|
|
159
|
|
|
$this->secondFactorId = $secondFactorId; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return null|string |
164
|
|
|
*/ |
165
|
|
|
public function getEmail() |
166
|
|
|
{ |
167
|
|
|
return $this->email; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param null|string $email |
172
|
|
|
*/ |
173
|
|
|
public function setEmail($email) |
174
|
|
|
{ |
175
|
|
|
$this->assertNonEmptyString($email, 'email'); |
176
|
|
|
|
177
|
|
|
$this->email = $email; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return null|string |
182
|
|
|
*/ |
183
|
|
|
public function getStatus() |
184
|
|
|
{ |
185
|
|
|
return $this->status; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $status |
190
|
|
|
*/ |
191
|
|
View Code Duplication |
public function setStatus($status) |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
Assert\that($status)->choice( |
194
|
|
|
[self::STATUS_UNVERIFIED, self::STATUS_VERIFIED, self::STATUS_VETTED, self::STATUS_REVOKED, ''], |
195
|
|
|
'Invalid second factor status, must be one of the STATUS constants' |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
$this->status = $status ?: null; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return null|string |
203
|
|
|
*/ |
204
|
|
|
public function getInstitution() |
205
|
|
|
{ |
206
|
|
|
return $this->institution; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param null|string $institution |
211
|
|
|
*/ |
212
|
|
|
public function setInstitution($institution) |
213
|
|
|
{ |
214
|
|
|
$this->institution = $institution; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param string $orderBy |
219
|
|
|
*/ |
220
|
|
|
public function setOrderBy($orderBy) |
221
|
|
|
{ |
222
|
|
|
$this->assertNonEmptyString($orderBy, 'orderBy'); |
223
|
|
|
|
224
|
|
|
$this->orderBy = $orderBy; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param string|null $orderDirection |
229
|
|
|
*/ |
230
|
|
View Code Duplication |
public function setOrderDirection($orderDirection) |
|
|
|
|
231
|
|
|
{ |
232
|
|
|
Assert\that($orderDirection)->choice( |
233
|
|
|
['asc', 'desc', '', null], |
234
|
|
|
"Invalid order direction, must be one of 'asc', 'desc'" |
235
|
|
|
); |
236
|
|
|
|
237
|
|
|
$this->orderDirection = $orderDirection ?: null; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
private function assertNonEmptyString($value, $name) |
241
|
|
|
{ |
242
|
|
|
$message = sprintf( |
243
|
|
|
'"%s" must be a non-empty string, "%s" given', |
244
|
|
|
$name, |
245
|
|
|
(is_object($value) ? get_class($value) : gettype($value)) |
246
|
|
|
); |
247
|
|
|
|
248
|
|
|
Assert\that($value)->string($message)->notEmpty($message); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Return the Http Query string as should be used, MUST include the '?' prefix. |
253
|
|
|
* |
254
|
|
|
* @return string |
255
|
|
|
*/ |
256
|
|
View Code Duplication |
public function toHttpQuery() |
|
|
|
|
257
|
|
|
{ |
258
|
|
|
return '?' . http_build_query( |
259
|
|
|
array_filter( |
260
|
|
|
[ |
261
|
|
|
'actorId' => $this->actorId, |
262
|
|
|
'name' => $this->name, |
263
|
|
|
'type' => $this->type, |
264
|
|
|
'secondFactorId' => $this->secondFactorId, |
265
|
|
|
'email' => $this->email, |
266
|
|
|
'status' => $this->status, |
267
|
|
|
'institution' => $this->institution, |
268
|
|
|
'orderBy' => $this->orderBy, |
269
|
|
|
'orderDirection' => $this->orderDirection, |
270
|
|
|
'p' => $this->pageNumber, |
271
|
|
|
], |
272
|
|
|
function ($value) { |
273
|
|
|
return !is_null($value); |
274
|
|
|
} |
275
|
|
|
) |
276
|
|
|
); |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.