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