1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML2\Constants as C; |
10
|
|
|
use SimpleSAML\SAML2\Utils; |
11
|
|
|
use SimpleSAML\SAML2\XML\ExtensionPointInterface; |
12
|
|
|
use SimpleSAML\SAML2\XML\ExtensionPointTrait; |
13
|
|
|
use SimpleSAML\SAML2\XML\saml\Statement; |
14
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
15
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
16
|
|
|
|
17
|
|
|
use function count; |
18
|
|
|
use function explode; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class implementing the <saml:Statement> extension point. |
22
|
|
|
* |
23
|
|
|
* @package simplesamlphp/saml2 |
24
|
|
|
*/ |
25
|
|
|
abstract class Statement extends AbstractStatementType implements ExtensionPointInterface |
26
|
|
|
{ |
27
|
|
|
use ExtensionPointTrait; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
public const LOCALNAME = 'Statement'; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Convert an XML element into a Statement. |
35
|
|
|
* |
36
|
|
|
* @param \DOMElement $xml The root XML element |
37
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\Statement The condition |
38
|
|
|
* |
39
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException if the qualified name of the supplied element is wrong |
40
|
|
|
*/ |
41
|
|
|
public static function fromXML(DOMElement $xml): object |
42
|
|
|
{ |
43
|
|
|
Assert::same($xml->localName, 'Statement', InvalidDOMElementException::class); |
44
|
|
|
Assert::same($xml->namespaceURI, C::NS_SAML, InvalidDOMElementException::class); |
45
|
|
|
Assert::true( |
46
|
|
|
$xml->hasAttributeNS(C::NS_XSI, 'type'), |
47
|
|
|
'Missing required xsi:type in <saml:Statement> element.', |
48
|
|
|
SchemaViolationException::class |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$type = $xml->getAttributeNS(C::NS_XSI, 'type'); |
52
|
|
|
Assert::validQName($type, SchemaViolationException::class); |
53
|
|
|
|
54
|
|
|
$qname = explode(':', $type, 2); |
55
|
|
|
if (count($qname) === 2) { |
56
|
|
|
list($prefix, $element) = $qname; |
57
|
|
|
} else { |
58
|
|
|
$prefix = null; |
59
|
|
|
list($element) = $qname; |
60
|
|
|
} |
61
|
|
|
$ns = $xml->lookupNamespaceUri($prefix); |
62
|
|
|
$handler = Utils::getContainer()->getElementHandler($ns, $element); |
63
|
|
|
|
64
|
|
|
Assert::notNull($handler, 'Unknown Statement type `' . $type . '`.'); |
65
|
|
|
Assert::isAOf($handler, Statement::class); |
66
|
|
|
|
67
|
|
|
return $handler::fromXML($xml); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Convert this Statement to XML. |
73
|
|
|
* |
74
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
75
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this Statement. |
76
|
|
|
*/ |
77
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
78
|
|
|
{ |
79
|
|
|
$e = $this->instantiateParentElement($parent); |
80
|
|
|
|
81
|
|
|
$e->setAttribute('xmlns:' . static::NS_XSI_TYPE_PREFIX, static::NS_XSI_TYPE_NAMESPACE); |
|
|
|
|
82
|
|
|
$e->setAttributeNS(C::NS_XSI, 'xsi:type', static::getXsiType()); |
|
|
|
|
83
|
|
|
|
84
|
|
|
return $e; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|