Passed
Pull Request — master (#280)
by Tim
02:41
created

AbstractSSODescriptor::toXML()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 16
nop 1
dl 0
loc 21
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML2\Constants;
10
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
11
use SimpleSAML\XML\Utils as XMLUtils;
12
13
/**
14
 * Class representing SAML 2 SSODescriptorType.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
abstract class AbstractSSODescriptor extends AbstractRoleDescriptor
19
{
20
    /**
21
     * List of ArtifactResolutionService endpoints.
22
     *
23
     * @var \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[]
24
     */
25
    protected array $artifactResolutionServiceEndpoints = [];
26
27
    /**
28
     * List of SingleLogoutService endpoints.
29
     *
30
     * @var \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
31
     */
32
    protected array $sloServiceEndpoints = [];
33
34
    /**
35
     * List of ManageNameIDService endpoints.
36
     *
37
     * @var \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
38
     */
39
    protected array $manageNameIDServiceEndpoints = [];
40
41
    /**
42
     * List of supported NameID formats.
43
     *
44
     * Array of strings.
45
     *
46
     * @var \SimpleSAML\SAML2\XML\md\NameIDFormat[]
47
     */
48
    protected array $nameIDFormats = [];
49
50
51
    /**
52
     * Initialize a RoleDescriptor.
53
     *
54
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
55
     * @param string|null $ID The ID for this document. Defaults to null.
56
     * @param int|null $validUntil Unix time of validity for this document. Defaults to null.
57
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
58
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An array of extensions. Defaults to an empty array.
59
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
60
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements.
61
     *   Defaults to an empty array.
62
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization The organization running this entity. Defaults to null.
63
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity.
64
     *   Defaults to an empty array.
65
     * @param \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[] $artifactResolutionService An array of
66
     *   ArtifactResolutionEndpoint. Defaults to an empty array.
67
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $singleLogoutService An array of SingleLogoutEndpoint.
68
     *   Defaults to an empty array.
69
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $manageNameIDService An array of ManageNameIDService.
70
     *   Defaults to an empty array.
71
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormat An array of supported NameID formats.
72
     *   Defaults to an empty array.
73
     */
74
    public function __construct(
75
        array $protocolSupportEnumeration,
76
        ?string $ID = null,
77
        ?int $validUntil = null,
78
        ?string $cacheDuration = null,
79
        ?Extensions $extensions = null,
80
        ?string $errorURL = null,
81
        array $keyDescriptors = [],
82
        ?Organization $organization = null,
83
        array $contacts = [],
84
        array $artifactResolutionService = [],
85
        array $singleLogoutService = [],
86
        array $manageNameIDService = [],
87
        array $nameIDFormat = []
88
    ) {
89
        parent::__construct(
90
            $protocolSupportEnumeration,
91
            $ID,
92
            $validUntil,
93
            $cacheDuration,
94
            $extensions,
95
            $errorURL,
96
            $keyDescriptors,
97
            $organization,
98
            $contacts
99
        );
100
101
        $this->setArtifactResolutionServices($artifactResolutionService);
102
        $this->setSingleLogoutServices($singleLogoutService);
103
        $this->setManageNameIDServices($manageNameIDService);
104
        $this->setNameIDFormats($nameIDFormat);
105
    }
106
107
108
    /**
109
     * Collect the value of the ArtifactResolutionService-property
110
     *
111
     * @return \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[]
112
     */
113
    public function getArtifactResolutionServices(): array
114
    {
115
        return $this->artifactResolutionServiceEndpoints;
116
    }
117
118
119
    /**
120
     * Set the value of the ArtifactResolutionService-property
121
     *
122
     * @param \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[] $artifactResolutionServices
123
     * @throws \SimpleSAML\Assert\AssertionFailedException
124
     */
125
    protected function setArtifactResolutionServices(array $artifactResolutionServices): void
126
    {
127
        Assert::allIsInstanceOf(
128
            $artifactResolutionServices,
129
            ArtifactResolutionService::class,
130
            'All md:ArtifactResolutionService endpoints must be an instance of ArtifactResolutionService.'
131
        );
132
        $this->artifactResolutionServiceEndpoints = $artifactResolutionServices;
133
    }
134
135
136
    /**
137
     * Collect the value of the SingleLogoutService-property
138
     *
139
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
140
     */
141
    public function getSingleLogoutServices(): array
142
    {
143
        return $this->sloServiceEndpoints;
144
    }
145
146
147
    /**
148
     * Set the value of the SingleLogoutService-property
149
     *
150
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $singleLogoutServices
151
     * @throws \SimpleSAML\Assert\AssertionFailedException
152
     */
153
    protected function setSingleLogoutServices(array $singleLogoutServices): void
154
    {
155
        Assert::allIsInstanceOf(
156
            $singleLogoutServices,
157
            SingleLogoutService::class,
158
            'All md:SingleLogoutService endpoints must be an instance of SingleLogoutService.'
159
        );
160
161
        $this->sloServiceEndpoints = $singleLogoutServices;
162
    }
163
164
165
    /**
166
     * Collect the value of the ManageNameIDService-property
167
     *
168
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
169
     */
170
    public function getManageNameIDServices(): array
171
    {
172
        return $this->manageNameIDServiceEndpoints;
173
    }
174
175
176
    /**
177
     * Set the value of the ManageNameIDService-property
178
     *
179
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $manageNameIDServices
180
     * @throws \SimpleSAML\Assert\AssertionFailedException
181
     */
182
    protected function setManageNameIDServices(array $manageNameIDServices): void
183
    {
184
        Assert::allIsInstanceOf(
185
            $manageNameIDServices,
186
            ManageNameIDService::class,
187
            'All md:ManageNameIDService endpoints must be an instance of ManageNameIDService.'
188
        );
189
190
        $this->manageNameIDServiceEndpoints = $manageNameIDServices;
191
    }
192
193
194
    /**
195
     * Collect the value of the NameIDFormat-property
196
     *
197
     * @return \SimpleSAML\SAML2\XML\md\NameIDFormat[]
198
     */
199
    public function getNameIDFormats(): array
200
    {
201
        return $this->nameIDFormats;
202
    }
203
204
205
    /**
206
     * Set the value of the NameIDFormat-property
207
     *
208
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormats
209
     */
210
    protected function setNameIDFormats(array $nameIDFormats): void
211
    {
212
        Assert::allIsInstanceOf($nameIDFormats, NameIDFormat::class, ProtocolViolationException::class);
213
        $this->nameIDFormats = $nameIDFormats;
214
    }
215
216
217
    /**
218
     * Convert this descriptor to an unsigned XML document.
219
     * This method does not sign the resulting XML document.
220
     *
221
     * @param \DOMElement|null $parent
222
     * @return \DOMElement The root element of the DOM tree
223
     */
224
    protected function toUnsignedXML(DOMElement $parent = null): DOMElement
225
    {
226
        $e = parent::toUnsignedXML($parent);
227
228
        foreach ($this->artifactResolutionServiceEndpoints as $ep) {
229
            $ep->toXML($e);
230
        }
231
232
        foreach ($this->sloServiceEndpoints as $ep) {
233
            $ep->toXML($e);
234
        }
235
236
        foreach ($this->manageNameIDServiceEndpoints as $ep) {
237
            $ep->toXML($e);
238
        }
239
240
        foreach ($this->nameIDFormats as $nidFormat) {
241
            $nidFormat->toXML($e);
242
        }
243
244
        return $e;
245
    }
246
}
247