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