|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\XML\samlp; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
|
8
|
|
|
use DOMElement; |
|
9
|
|
|
use SimpleSAML\Assert\Assert; |
|
10
|
|
|
use SimpleSAML\SAML11\XML\saml\AssertionIDReference; |
|
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
12
|
|
|
|
|
13
|
|
|
use function array_pop; |
|
14
|
|
|
use function is_array; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Base class for all SAML 1.1 requests. |
|
18
|
|
|
* |
|
19
|
|
|
* @package simplesamlphp/saml11 |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AbstractRequestType extends AbstractRequestAbstractType |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Initialize a request. |
|
25
|
|
|
* |
|
26
|
|
|
* @param ( |
|
27
|
|
|
* \SimpleSAML\SAML11\XML\samlp\AbstractQueryAbstractType| |
|
28
|
|
|
* array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference>| |
|
29
|
|
|
* array<\SimpleSAML\SAML11\XML\samlp\AssertionArtifact> |
|
30
|
|
|
* ) $request |
|
31
|
|
|
* @param string $id |
|
32
|
|
|
* @param int $majorVersion |
|
33
|
|
|
* @param int $minorVersion |
|
34
|
|
|
* @param \DateTimeImmutable $issueInstant |
|
35
|
|
|
* @param array<\SimpleSAML\SAML11\XML\samlp\RespondWith> $respondWith |
|
36
|
|
|
* |
|
37
|
|
|
* @throws \Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function __construct( |
|
40
|
|
|
protected AbstractQueryAbstractType|array $request, |
|
41
|
|
|
string $id, |
|
42
|
|
|
int $majorVersion, |
|
43
|
|
|
int $minorVersion, |
|
44
|
|
|
DateTimeImmutable $issueInstant, |
|
45
|
|
|
array $respondWith = [], |
|
46
|
|
|
) { |
|
47
|
|
|
if (is_array($request)) { |
|
|
|
|
|
|
48
|
|
|
Assert::minCount($request, 1, SchemaViolationException::class); |
|
49
|
|
|
|
|
50
|
|
|
$req = array_pop($request); |
|
51
|
|
|
if ($req instanceof AssertionIDReference) { |
|
52
|
|
|
Assert::allIsInstanceOf($request, AssertionIDReference::class, SchemaViolationException::class); |
|
53
|
|
|
} elseif ($req instanceof AssertionArtifact) { |
|
54
|
|
|
Assert::allIsInstanceOf($request, AssertionArtifact::class, SchemaViolationException::class); |
|
55
|
|
|
} else { |
|
56
|
|
|
throw new SchemaViolationException(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
parent::__construct($id, $majorVersion, $minorVersion, $issueInstant, $respondWith); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Retrieve the request inside this request. |
|
66
|
|
|
* |
|
67
|
|
|
* @return ( |
|
|
|
|
|
|
68
|
|
|
* \SimpleSAML\SAML11\XML\samlp\AbstractQueryAbstractType| |
|
69
|
|
|
* array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference>| |
|
70
|
|
|
* array<\SimpleSAML\SAML11\XML\samlp\AssertionArtifact> |
|
71
|
|
|
* ) |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getRequest(): AbstractQueryAbstractType|array |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->request; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Convert this message to an unsigned XML document. |
|
81
|
|
|
* This method does not sign the resulting XML document. |
|
82
|
|
|
* |
|
83
|
|
|
* @return \DOMElement The root element of the DOM tree |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function toUnsignedXML(?DOMElement $parent = null): DOMElement |
|
86
|
|
|
{ |
|
87
|
|
|
$e = parent::toUnsignedXML($parent); |
|
88
|
|
|
|
|
89
|
|
|
$request = $this->getRequest(); |
|
90
|
|
|
$request = is_array($request) ? $request : [$request]; |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
foreach ($this->getRequest() as $request) { |
|
93
|
|
|
$request->toXML($e); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $e; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|