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\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class representing a SAML2 AttributeStatement |
14
|
|
|
* |
15
|
|
|
* @package simplesamlphp/saml2 |
16
|
|
|
*/ |
17
|
|
|
class AttributeStatement extends AbstractStatementType |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* AttributeStatement constructor. |
21
|
|
|
* |
22
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\Attribute[] $attributes |
23
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\EncryptedAttribute[] $encryptedAttributes |
24
|
|
|
*/ |
25
|
|
|
public function __construct( |
26
|
|
|
protected array $attributes = [], |
27
|
|
|
protected array $encryptedAttributes = [], |
28
|
|
|
) { |
29
|
|
|
Assert::true(!empty($attributes) || !empty($encryptedAttributes)); |
30
|
|
|
Assert::allIsInstanceOf($attributes, Attribute::class); |
31
|
|
|
Assert::allIsInstanceOf($encryptedAttributes, EncryptedAttribute::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\Attribute[] |
37
|
|
|
*/ |
38
|
|
|
public function getAttributes(): array |
39
|
|
|
{ |
40
|
|
|
return $this->attributes; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return \SimpleSAML\SAML2\XML\saml\EncryptedAttribute[] |
46
|
|
|
*/ |
47
|
|
|
public function getEncryptedAttributes(): array |
48
|
|
|
{ |
49
|
|
|
return $this->encryptedAttributes; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function hasEncryptedAttributes(): bool |
57
|
|
|
{ |
58
|
|
|
return !empty($this->encryptedAttributes); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param \DOMElement $xml |
64
|
|
|
* @return static |
65
|
|
|
* |
66
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
67
|
|
|
* if the qualified name of the supplied element is wrong |
68
|
|
|
*/ |
69
|
|
|
public static function fromXML(DOMElement $xml): static |
70
|
|
|
{ |
71
|
|
|
Assert::same($xml->localName, 'AttributeStatement', InvalidDOMElementException::class); |
72
|
|
|
Assert::same($xml->namespaceURI, AttributeStatement::NS, InvalidDOMElementException::class); |
73
|
|
|
|
74
|
|
|
return new static( |
75
|
|
|
Attribute::getChildrenOfClass($xml), |
76
|
|
|
EncryptedAttribute::getChildrenOfClass($xml), |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Convert this Attribute to XML. |
83
|
|
|
* |
84
|
|
|
* @param \DOMElement|null $parent The element we should append this Attribute to. |
85
|
|
|
* @return \DOMElement |
86
|
|
|
*/ |
87
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
88
|
|
|
{ |
89
|
|
|
$e = $this->instantiateParentElement($parent); |
90
|
|
|
|
91
|
|
|
foreach ($this->getAttributes() as $attribute) { |
92
|
|
|
$attribute->toXML($e); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
foreach ($this->getEncryptedAttributes() as $encryptedAttribute) { |
96
|
|
|
$encryptedAttribute->toXML($e); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $e; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|