|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\samlp; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\SAML2\Constants; |
|
10
|
|
|
use SimpleSAML\SAML2\XML\ExtensionsTrait; |
|
11
|
|
|
use SimpleSAML\SAML2\XML\saml\Issuer; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Base class for all SAML 2 response messages. |
|
15
|
|
|
* |
|
16
|
|
|
* Implements samlp:StatusResponseType. All of the elements in that type is |
|
17
|
|
|
* stored in the \SimpleSAML\SAML2\Message class, and this class is therefore more |
|
18
|
|
|
* or less empty. It is included mainly to make it easy to separate requests from |
|
19
|
|
|
* responses. |
|
20
|
|
|
* |
|
21
|
|
|
* @package simplesamlphp/saml2 |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractStatusResponse extends AbstractMessage |
|
24
|
|
|
{ |
|
25
|
|
|
use ExtensionsTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The ID of the request this is a response to, or null if this is an unsolicited response. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string|null |
|
31
|
|
|
*/ |
|
32
|
|
|
protected ?string $inResponseTo; |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The status code of the response. |
|
37
|
|
|
* |
|
38
|
|
|
* @var \SimpleSAML\SAML2\XML\samlp\Status |
|
39
|
|
|
*/ |
|
40
|
|
|
protected Status $status; |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor for SAML 2 response messages. |
|
45
|
|
|
* |
|
46
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\Status $status |
|
47
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\Issuer|null $issuer |
|
48
|
|
|
* @param string|null $id |
|
49
|
|
|
* @param int|null $issueInstant |
|
50
|
|
|
* @param string|null $inResponseTo |
|
51
|
|
|
* @param string|null $destination |
|
52
|
|
|
* @param string|null $consent |
|
53
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\Extensions|null $extensions |
|
54
|
|
|
* @param string|null $relayState |
|
55
|
|
|
* |
|
56
|
|
|
* @throws \Exception |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function __construct( |
|
59
|
|
|
Status $status, |
|
60
|
|
|
?Issuer $issuer = null, |
|
61
|
|
|
?string $id = null, |
|
62
|
|
|
?int $issueInstant = null, |
|
63
|
|
|
?string $inResponseTo = null, |
|
64
|
|
|
?string $destination = null, |
|
65
|
|
|
?string $consent = null, |
|
66
|
|
|
?Extensions $extensions = null, |
|
67
|
|
|
?string $relayState = null |
|
68
|
|
|
) { |
|
69
|
|
|
parent::__construct($issuer, $id, $issueInstant, $destination, $consent, $extensions, $relayState); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->setStatus($status); |
|
72
|
|
|
$this->setInResponseTo($inResponseTo); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Determine whether this is a successful response. |
|
78
|
|
|
* |
|
79
|
|
|
* @return bool true if the status code is success, false if not. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function isSuccess(): bool |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->status->getStatusCode()->getValue() === Constants::STATUS_SUCCESS; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Retrieve the ID of the request this is a response to. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string|null The ID of the request. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getInResponseTo(): ?string |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->inResponseTo; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Set the ID of the request this is a response to. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string|null $inResponseTo The ID of the request. |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function setInResponseTo(?string $inResponseTo): void |
|
104
|
|
|
{ |
|
105
|
|
|
Assert::nullOrNotWhitespaceOnly($inResponseTo); |
|
106
|
|
|
Assert::nullOrNotContains($inResponseTo, ':'); |
|
107
|
|
|
|
|
108
|
|
|
$this->inResponseTo = $inResponseTo; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Retrieve the status code. |
|
114
|
|
|
* |
|
115
|
|
|
* @return \SimpleSAML\SAML2\XML\samlp\Status The status code. |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getStatus(): Status |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->status; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Set the status code. |
|
125
|
|
|
* |
|
126
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\Status $status The status code. |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function setStatus(Status $status): void |
|
129
|
|
|
{ |
|
130
|
|
|
$this->status = $status; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Convert this message to an unsigned XML document. |
|
136
|
|
|
* This method does not sign the resulting XML document. |
|
137
|
|
|
* |
|
138
|
|
|
* @return \DOMElement The root element of the DOM tree |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function toUnsignedXML(?DOMElement $parent = null): DOMElement |
|
141
|
|
|
{ |
|
142
|
|
|
$e = parent::toUnsignedXML($parent); |
|
143
|
|
|
|
|
144
|
|
|
if ($this->inResponseTo !== null) { |
|
145
|
|
|
$e->setAttribute('InResponseTo', $this->inResponseTo); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$this->status->toXML($e); |
|
149
|
|
|
|
|
150
|
|
|
return $e; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.