|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Model\Protocol; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Model\Assertion\Conditions; |
|
15
|
|
|
use LightSaml\Model\Assertion\Subject; |
|
16
|
|
|
use LightSaml\Model\Context\DeserializationContext; |
|
17
|
|
|
use LightSaml\Model\Context\SerializationContext; |
|
18
|
|
|
use LightSaml\SamlConstants; |
|
19
|
|
|
|
|
20
|
|
|
class AuthnRequest extends AbstractRequest |
|
21
|
|
|
{ |
|
22
|
|
|
//region Attributes |
|
23
|
|
|
|
|
24
|
|
|
/** @var bool|null */ |
|
25
|
|
|
protected $forceAuthn; |
|
26
|
|
|
|
|
27
|
|
|
/** @var bool|null */ |
|
28
|
|
|
protected $isPassive; |
|
29
|
|
|
|
|
30
|
|
|
/** @var int|null */ |
|
31
|
|
|
protected $assertionConsumerServiceIndex; |
|
32
|
|
|
|
|
33
|
|
|
/** @var string|null */ |
|
34
|
|
|
protected $assertionConsumerServiceURL; |
|
35
|
|
|
|
|
36
|
|
|
/** @var int|null */ |
|
37
|
|
|
protected $attributeConsumingServiceIndex; |
|
38
|
|
|
|
|
39
|
|
|
/** @var string|null */ |
|
40
|
|
|
protected $protocolBinding; |
|
41
|
|
|
|
|
42
|
|
|
/** @var string|null */ |
|
43
|
|
|
protected $providerName; |
|
44
|
|
|
|
|
45
|
|
|
//endregion |
|
46
|
|
|
|
|
47
|
|
|
//region Elements |
|
48
|
|
|
|
|
49
|
|
|
/** @var Conditions|null */ |
|
50
|
|
|
protected $conditions; |
|
51
|
|
|
|
|
52
|
|
|
/** @var NameIDPolicy|null */ |
|
53
|
|
|
protected $nameIDPolicy; |
|
54
|
|
|
|
|
55
|
|
|
/** @var Subject|null */ |
|
56
|
|
|
protected $subject; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param Subject|null $subject |
|
60
|
|
|
* |
|
61
|
|
|
* @return AuthnRequest |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setSubject(Subject $subject) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->subject = $subject; |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return Subject|null |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getSubject() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->subject; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string|null $providerName |
|
80
|
|
|
* |
|
81
|
|
|
* @return AuthnRequest |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setProviderName($providerName) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->providerName = (string) $providerName; |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string|null |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getProviderName() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->providerName; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param string|null $protocolBinding |
|
100
|
|
|
* |
|
101
|
|
|
* @return AuthnRequest |
|
102
|
|
|
*/ |
|
103
|
|
|
public function setProtocolBinding($protocolBinding) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->protocolBinding = (string) $protocolBinding; |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return string|null |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getProtocolBinding() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->protocolBinding; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param NameIDPolicy|null $nameIDPolicy |
|
120
|
|
|
* |
|
121
|
|
|
* @return AuthnRequest |
|
122
|
|
|
*/ |
|
123
|
|
|
public function setNameIDPolicy(NameIDPolicy $nameIDPolicy) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->nameIDPolicy = $nameIDPolicy; |
|
126
|
|
|
|
|
127
|
|
|
return $this; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return NameIDPolicy|null |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getNameIDPolicy() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->nameIDPolicy; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param bool|null $isPassive |
|
140
|
|
|
* |
|
141
|
|
|
* @return AuthnRequest |
|
142
|
|
|
*/ |
|
143
|
|
|
public function setIsPassive($isPassive) |
|
144
|
|
|
{ |
|
145
|
|
|
$this->isPassive = 0 == strcasecmp($isPassive, 'true') || true === $isPassive || 1 == $isPassive; |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return bool|null |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getIsPassive() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->isPassive; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return string|null |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getIsPassiveString() |
|
162
|
|
|
{ |
|
163
|
|
|
if (null === $this->isPassive) { |
|
164
|
|
|
return null; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
return $this->isPassive ? 'true' : 'false'; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param bool|null $forceAuthn |
|
172
|
|
|
* |
|
173
|
|
|
* @return AuthnRequest |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setForceAuthn($forceAuthn) |
|
176
|
|
|
{ |
|
177
|
|
|
$this->forceAuthn = 0 == strcasecmp($forceAuthn, 'true') || true === $forceAuthn || 1 == $forceAuthn; |
|
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
return $this; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return bool|null |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getForceAuthn() |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->forceAuthn; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return string|null |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getForceAuthnString() |
|
194
|
|
|
{ |
|
195
|
|
|
if (null === $this->forceAuthn) { |
|
196
|
|
|
return null; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
return $this->forceAuthn ? 'true' : 'false'; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @param Conditions|null $conditions |
|
204
|
|
|
* |
|
205
|
|
|
* @return AuthnRequest |
|
206
|
|
|
*/ |
|
207
|
|
|
public function setConditions($conditions) |
|
208
|
|
|
{ |
|
209
|
|
|
$this->conditions = $conditions; |
|
210
|
|
|
|
|
211
|
|
|
return $this; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return \LightSaml\Model\Assertion\Conditions|null |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getConditions() |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->conditions; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @param int|null $attributeConsumingServiceIndex |
|
224
|
|
|
* |
|
225
|
|
|
* @return AuthnRequest |
|
226
|
|
|
*/ |
|
227
|
|
|
public function setAttributeConsumingServiceIndex($attributeConsumingServiceIndex) |
|
228
|
|
|
{ |
|
229
|
|
|
$this->attributeConsumingServiceIndex = null !== $attributeConsumingServiceIndex |
|
230
|
|
|
? intval(((string) $attributeConsumingServiceIndex)) |
|
231
|
|
|
: null; |
|
232
|
|
|
|
|
233
|
|
|
return $this; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @return int|null |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getAttributeConsumingServiceIndex() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->attributeConsumingServiceIndex; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @param string|null $assertionConsumerServiceURL |
|
246
|
|
|
* |
|
247
|
|
|
* @return AuthnRequest |
|
248
|
|
|
*/ |
|
249
|
|
|
public function setAssertionConsumerServiceURL($assertionConsumerServiceURL) |
|
250
|
|
|
{ |
|
251
|
|
|
$this->assertionConsumerServiceURL = (string) $assertionConsumerServiceURL; |
|
252
|
|
|
|
|
253
|
|
|
return $this; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @return string|null |
|
258
|
|
|
*/ |
|
259
|
|
|
public function getAssertionConsumerServiceURL() |
|
260
|
|
|
{ |
|
261
|
|
|
return $this->assertionConsumerServiceURL; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* @param int|null $assertionConsumerServiceIndex |
|
266
|
|
|
* |
|
267
|
|
|
* @return AuthnRequest |
|
268
|
|
|
*/ |
|
269
|
|
|
public function setAssertionConsumerServiceIndex($assertionConsumerServiceIndex) |
|
270
|
|
|
{ |
|
271
|
|
|
$this->assertionConsumerServiceIndex = null !== $assertionConsumerServiceIndex |
|
272
|
|
|
? intval((string) $assertionConsumerServiceIndex) |
|
273
|
|
|
: null; |
|
274
|
|
|
|
|
275
|
|
|
return $this; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @return int|null |
|
280
|
|
|
*/ |
|
281
|
|
|
public function getAssertionConsumerServiceIndex() |
|
282
|
|
|
{ |
|
283
|
|
|
return $this->assertionConsumerServiceIndex; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
//endregion |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @return void |
|
290
|
|
|
*/ |
|
291
|
|
|
public function serialize(\DOMNode $parent, SerializationContext $context) |
|
292
|
|
|
{ |
|
293
|
|
|
$result = $this->createElement('AuthnRequest', SamlConstants::NS_PROTOCOL, $parent, $context); |
|
294
|
|
|
|
|
295
|
|
|
parent::serialize($result, $context); |
|
296
|
|
|
|
|
297
|
|
|
$this->attributesToXml([ |
|
298
|
|
|
'ForceAuthn', 'IsPassive', 'ProtocolBinding', 'AssertionConsumerServiceIndex', |
|
299
|
|
|
'AssertionConsumerServiceURL', 'AttributeConsumingServiceIndex', 'ProviderName', |
|
300
|
|
|
], $result); |
|
301
|
|
|
|
|
302
|
|
|
$this->singleElementsToXml(['Subject', 'NameIDPolicy', 'Conditions'], $result, $context); |
|
303
|
|
|
|
|
304
|
|
|
// must be last in order signature to include them all |
|
305
|
|
|
$this->singleElementsToXml(['Signature'], $result, $context); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
public function deserialize(\DOMNode $node, DeserializationContext $context) |
|
309
|
|
|
{ |
|
310
|
|
|
$this->checkXmlNodeName($node, 'AuthnRequest', SamlConstants::NS_PROTOCOL); |
|
311
|
|
|
|
|
312
|
|
|
parent::deserialize($node, $context); |
|
313
|
|
|
|
|
314
|
|
|
$this->attributesFromXml($node, [ |
|
315
|
|
|
'ForceAuthn', 'IsPassive', 'ProtocolBinding', 'AssertionConsumerServiceIndex', |
|
316
|
|
|
'AssertionConsumerServiceURL', 'AttributeConsumingServiceIndex', 'ProviderName', |
|
317
|
|
|
]); |
|
318
|
|
|
|
|
319
|
|
|
$this->singleElementsFromXml($node, $context, [ |
|
320
|
|
|
'Subject' => ['saml', 'LightSaml\Model\Assertion\Subject'], |
|
321
|
|
|
'NameIDPolicy' => ['samlp', 'LightSaml\Model\Protocol\NameIDPolicy'], |
|
322
|
|
|
'Conditions' => ['saml', 'LightSaml\Model\Assertion\Conditions'], |
|
323
|
|
|
]); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|