Completed
Branch rewrite-api-md (eb38e5)
by Tim
03:57
created

getArtifactResolutionServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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