Passed
Push — master ( eb6d7f...017f7a )
by Tim
02:40
created

AbstractSSODescriptor   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 226
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 226
rs 10
c 0
b 0
f 0
wmc 14

10 Methods

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