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