AuthenticationSuccess::getProxyGrantingTicket()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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