1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\XML\saml; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\SAML11\Type\{SAMLAnyURIValue, SAMLDateTimeValue}; |
10
|
|
|
use SimpleSAML\XMLSchema\Exception\{ |
11
|
|
|
InvalidDOMElementException, |
12
|
|
|
MissingElementException, |
13
|
|
|
SchemaViolationException, |
14
|
|
|
TooManyElementsException, |
15
|
|
|
}; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* SAML AuthenticationStatementType abstract data type. |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/saml11 |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractAuthenticationStatementType extends AbstractSubjectStatementType |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Initialize a saml:AuthenticationStatementType from scratch |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\SAML11\XML\saml\Subject $subject |
28
|
|
|
* @param \SimpleSAML\SAML11\Type\SAMLAnyURIValue $authenticationMethod |
29
|
|
|
* @param \SimpleSAML\SAML11\Type\SAMLDateTimeValue $authenticationInstant |
30
|
|
|
* @param \SimpleSAML\SAML11\XML\saml\SubjectLocality|null $subjectLocality |
31
|
|
|
* @param array<\SimpleSAML\SAML11\XML\saml\AuthorityBinding> $authorityBinding |
32
|
|
|
*/ |
33
|
|
|
final public function __construct( |
34
|
|
|
Subject $subject, |
35
|
|
|
protected SAMLAnyURIValue $authenticationMethod, |
36
|
|
|
protected SAMLDateTimeValue $authenticationInstant, |
37
|
|
|
protected ?SubjectLocality $subjectLocality = null, |
38
|
|
|
protected array $authorityBinding = [], |
39
|
|
|
) { |
40
|
|
|
Assert::allIsInstanceOf($authorityBinding, AuthorityBinding::class, SchemaViolationException::class); |
41
|
|
|
|
42
|
|
|
parent::__construct($subject); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Collect the value of the authorityBinding-property |
48
|
|
|
* |
49
|
|
|
* @return array<\SimpleSAML\SAML11\XML\saml\AuthorityBinding> |
50
|
|
|
*/ |
51
|
|
|
public function getAuthorityBinding(): array |
52
|
|
|
{ |
53
|
|
|
return $this->authorityBinding; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Collect the value of the subjectLocality-property |
59
|
|
|
* |
60
|
|
|
* @return \SimpleSAML\SAML11\XML\saml\SubjectLocality|null |
61
|
|
|
*/ |
62
|
|
|
public function getSubjectLocality(): ?SubjectLocality |
63
|
|
|
{ |
64
|
|
|
return $this->subjectLocality; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Collect the value of the authenticationMethod-property |
70
|
|
|
* |
71
|
|
|
* @return \SimpleSAML\SAML11\Type\SAMLAnyURIValue |
72
|
|
|
*/ |
73
|
|
|
public function getAuthenticationMethod(): SAMLAnyURIValue |
74
|
|
|
{ |
75
|
|
|
return $this->authenticationMethod; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Collect the value of the authenticationInstant-property |
81
|
|
|
* |
82
|
|
|
* @return \SimpleSAML\SAML11\Type\SAMLDateTimeValue |
83
|
|
|
*/ |
84
|
|
|
public function getAuthenticationInstant(): SAMLDateTimeValue |
85
|
|
|
{ |
86
|
|
|
return $this->authenticationInstant; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Convert XML into an AuthenticationStatementType |
92
|
|
|
* |
93
|
|
|
* @param \DOMElement $xml The XML element we should load |
94
|
|
|
* @return static |
95
|
|
|
* |
96
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
97
|
|
|
* if the qualified name of the supplied element is wrong |
98
|
|
|
*/ |
99
|
|
|
public static function fromXML(DOMElement $xml): static |
100
|
|
|
{ |
101
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
102
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
103
|
|
|
|
104
|
|
|
$authorityBinding = AuthorityBinding::getChildrenOfClass($xml); |
105
|
|
|
$subjectLocality = SubjectLocality::getChildrenOfClass($xml); |
106
|
|
|
Assert::maxCount($subjectLocality, 1, TooManyElementsException::class); |
107
|
|
|
|
108
|
|
|
$subject = Subject::getChildrenOfClass($xml); |
109
|
|
|
Assert::minCount($subject, 1, MissingElementException::class); |
110
|
|
|
Assert::maxCount($subject, 1, TooManyElementsException::class); |
111
|
|
|
|
112
|
|
|
return new static( |
113
|
|
|
array_pop($subject), |
114
|
|
|
self::getAttribute($xml, 'AuthenticationMethod', SAMLAnyURIValue::class), |
115
|
|
|
self::getAttribute($xml, 'AuthenticationInstant', SAMLDateTimeValue::class), |
116
|
|
|
array_pop($subjectLocality), |
117
|
|
|
$authorityBinding, |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Convert this AuthenticationStatementType to XML. |
124
|
|
|
* |
125
|
|
|
* @param \DOMElement $parent The element we are converting to XML. |
126
|
|
|
* @return \DOMElement The XML element after adding the data corresponding to this AuthenticationStatementType. |
127
|
|
|
*/ |
128
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
129
|
|
|
{ |
130
|
|
|
$e = parent::toXML($parent); |
131
|
|
|
|
132
|
|
|
$e->setAttribute('AuthenticationMethod', strval($this->getAuthenticationMethod())); |
133
|
|
|
$e->setAttribute('AuthenticationInstant', strval($this->getAuthenticationInstant())); |
134
|
|
|
|
135
|
|
|
$this->getSubjectLocality()?->toXML($e); |
136
|
|
|
|
137
|
|
|
foreach ($this->getAuthorityBinding() as $ab) { |
138
|
|
|
$ab->toXML($e); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $e; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|