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