1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\CAS\XML\cas; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
|
12
|
|
|
use function array_pop; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class for CAS authenticationSuccess |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/cas |
18
|
|
|
*/ |
19
|
|
|
final class AuthenticationSuccess extends AbstractResponse |
20
|
|
|
{ |
21
|
|
|
/** @var string */ |
22
|
|
|
final public const LOCALNAME = 'authenticationSuccess'; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initialize a cas:authenticationSuccess element |
27
|
|
|
* |
28
|
|
|
* @param \SimpleSAML\CAS\XML\cas\User $user |
29
|
|
|
* @param \SimpleSAML\CAS\XML\cas\Attributes $attributes |
30
|
|
|
* @param \SimpleSAML\CAS\XML\cas\ProxyGrantingTicket|null $proxyGrantingTicket |
31
|
|
|
* @param \SimpleSAML\CAS\XML\cas\Proxies|null $proxies |
32
|
|
|
*/ |
33
|
|
|
final public function __construct( |
34
|
|
|
protected User $user, |
35
|
|
|
protected Attributes $attributes, |
36
|
|
|
protected ?ProxyGrantingTicket $proxyGrantingTicket = null, |
37
|
|
|
protected ?Proxies $proxies = null, |
38
|
|
|
) { |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \SimpleSAML\CAS\XML\cas\User |
44
|
|
|
*/ |
45
|
|
|
public function getUser(): User |
46
|
|
|
{ |
47
|
|
|
return $this->user; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return \SimpleSAML\CAS\XML\cas\Attributes |
53
|
|
|
*/ |
54
|
|
|
public function getAttributes(): Attributes |
55
|
|
|
{ |
56
|
|
|
return $this->attributes; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return \SimpleSAML\CAS\XML\cas\ProxyGrantingTicket |
62
|
|
|
*/ |
63
|
|
|
public function getProxyGrantingTicket(): ?ProxyGrantingTicket |
64
|
|
|
{ |
65
|
|
|
return $this->proxyGrantingTicket; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return \SimpleSAML\CAS\XML\cas\Proxies |
71
|
|
|
*/ |
72
|
|
|
public function getProxies(): ?Proxies |
73
|
|
|
{ |
74
|
|
|
return $this->proxies; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Convert XML into a cas:authenticationSuccess-element |
80
|
|
|
* |
81
|
|
|
* @param \DOMElement $xml The XML element we should load |
82
|
|
|
* @return static |
83
|
|
|
* |
84
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
85
|
|
|
* if the qualified name of the supplied element is wrong |
86
|
|
|
* @throws \SimpleSAML\XML\Exception\MissingAttributeException |
87
|
|
|
* if the supplied element is missing one of the mandatory attributes |
88
|
|
|
*/ |
89
|
|
|
public static function fromXML(DOMElement $xml): static |
90
|
|
|
{ |
91
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
92
|
|
|
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
93
|
|
|
|
94
|
|
|
$user = User::getChildrenOfClass($xml); |
95
|
|
|
Assert::count( |
96
|
|
|
$user, |
97
|
|
|
1, |
98
|
|
|
'Exactly one <cas:user> must be specified.', |
99
|
|
|
MissingElementException::class, |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$attributes = Attributes::getChildrenOfClass($xml); |
103
|
|
|
Assert::count( |
104
|
|
|
$attributes, |
105
|
|
|
1, |
106
|
|
|
'Exactly one <cas:attributes> must be specified.', |
107
|
|
|
MissingElementException::class, |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$proxyGrantingTicket = ProxyGrantingTicket::getChildrenOfClass($xml); |
111
|
|
|
$proxies = Proxies::getChildrenOfClass($xml); |
112
|
|
|
|
113
|
|
|
return new static( |
114
|
|
|
array_pop($user), |
115
|
|
|
array_pop($attributes), |
116
|
|
|
array_pop($proxyGrantingTicket), |
117
|
|
|
array_pop($proxies), |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Convert this AuthenticationSuccess to XML. |
124
|
|
|
* |
125
|
|
|
* @param \DOMElement|null $parent The element we should append this AuthenticationSuccess to. |
126
|
|
|
* @return \DOMElement |
127
|
|
|
*/ |
128
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
129
|
|
|
{ |
130
|
|
|
$e = $this->instantiateParentElement($parent); |
131
|
|
|
|
132
|
|
|
$this->getUser()->toXML($e); |
133
|
|
|
$this->getAttributes()->toXML($e); |
134
|
|
|
$this->getProxyGrantingTicket()?->toXML($e); |
135
|
|
|
$this->getProxies()?->toXML($e); |
136
|
|
|
|
137
|
|
|
return $e; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|