IDPSSODescriptor   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 266
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 101
dl 0
loc 266
rs 10
c 0
b 0
f 0
wmc 18

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributeProfile() 0 3 1
A getSupportedAttribute() 0 3 1
A getSingleSignOnService() 0 3 1
A __construct() 0 63 1
A getNameIDMappingService() 0 3 1
A wantAuthnRequestsSigned() 0 3 1
A getAssertionIDRequestService() 0 3 1
A fromXML() 0 56 4
B toUnsignedXML() 0 32 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Type\SAMLAnyURIListValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Type\SAMLAnyURIListValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
11
use SimpleSAML\SAML2\Type\SAMLDateTimeValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Type\SAMLDateTimeValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use SimpleSAML\SAML2\XML\saml\Attribute;
13
use SimpleSAML\XML\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\Constants was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use SimpleSAML\XML\SchemaValidatableElementInterface;
15
use SimpleSAML\XML\SchemaValidatableElementTrait;
16
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
17
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
18
use SimpleSAML\XMLSchema\Type\BooleanValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\BooleanValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use SimpleSAML\XMLSchema\Type\DurationValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\DurationValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use SimpleSAML\XMLSchema\Type\IDValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\IDValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use SimpleSAML\XMLSecurity\XML\ds\Signature;
22
23
use function var_export;
24
25
/**
26
 * Class representing SAML 2 IDPSSODescriptor.
27
 *
28
 * @package simplesamlphp/saml2
29
 */
30
final class IDPSSODescriptor extends AbstractSSODescriptor implements SchemaValidatableElementInterface
31
{
32
    use SchemaValidatableElementTrait;
33
34
35
    /**
36
     * IDPSSODescriptor constructor.
37
     *
38
     * @param \SimpleSAML\SAML2\XML\md\SingleSignOnService[] $singleSignOnService
39
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIListValue $protocolSupportEnumeration
40
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue|null $wantAuthnRequestsSigned
41
     * @param \SimpleSAML\SAML2\XML\md\NameIDMappingService[] $nameIDMappingService
42
     * @param \SimpleSAML\SAML2\XML\md\AssertionIDRequestService[] $assertionIDRequestService
43
     * @param \SimpleSAML\SAML2\XML\md\AttributeProfile[] $attributeProfile
44
     * @param \SimpleSAML\SAML2\XML\saml\Attribute[] $attribute
45
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $ID
46
     * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null $validUntil
47
     * @param \SimpleSAML\XMLSchema\Type\DurationValue|null $cacheDuration
48
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions
49
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $errorURL
50
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptor
51
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
52
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contact
53
     * @param \SimpleSAML\SAML2\XML\md\ArtifactResolutionService[] $artifactResolutionService
54
     * @param \SimpleSAML\SAML2\XML\md\SingleLogoutService[] $singleLogoutService
55
     * @param \SimpleSAML\SAML2\XML\md\ManageNameIDService[] $manageNameIDService
56
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormat
57
     */
58
    public function __construct(
59
        protected array $singleSignOnService,
60
        SAMLAnyURIListValue $protocolSupportEnumeration,
61
        protected ?BooleanValue $wantAuthnRequestsSigned = null,
62
        protected array $nameIDMappingService = [],
63
        protected array $assertionIDRequestService = [],
64
        protected array $attributeProfile = [],
65
        protected array $attribute = [],
66
        ?IDValue $ID = null,
67
        ?SAMLDateTimeValue $validUntil = null,
68
        ?DurationValue $cacheDuration = null,
69
        ?Extensions $extensions = null,
70
        ?SAMLAnyURIValue $errorURL = null,
71
        array $keyDescriptor = [],
72
        ?Organization $organization = null,
73
        array $contact = [],
74
        array $artifactResolutionService = [],
75
        array $singleLogoutService = [],
76
        array $manageNameIDService = [],
77
        array $nameIDFormat = [],
78
    ) {
79
        Assert::maxCount($singleSignOnService, C::UNBOUNDED_LIMIT);
80
        Assert::minCount($singleSignOnService, 1, 'At least one SingleSignOnService must be specified.');
81
        Assert::allIsInstanceOf(
82
            $singleSignOnService,
83
            SingleSignOnService::class,
84
            'All md:SingleSignOnService endpoints must be an instance of SingleSignOnService.',
85
        );
86
        Assert::maxCount($nameIDMappingService, C::UNBOUNDED_LIMIT);
87
        Assert::allIsInstanceOf(
88
            $nameIDMappingService,
89
            NameIDMappingService::class,
90
            'All md:NameIDMappingService endpoints must be an instance of NameIDMappingService.',
91
        );
92
        Assert::maxCount($assertionIDRequestService, C::UNBOUNDED_LIMIT);
93
        Assert::allIsInstanceOf(
94
            $assertionIDRequestService,
95
            AssertionIDRequestService::class,
96
            'All md:AssertionIDRequestService endpoints must be an instance of AssertionIDRequestService.',
97
        );
98
        Assert::maxCount($attributeProfile, C::UNBOUNDED_LIMIT);
99
        Assert::allIsInstanceOf($attributeProfile, AttributeProfile::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\AttributeProfile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
100
        Assert::maxCount($attribute, C::UNBOUNDED_LIMIT);
101
        Assert::allIsInstanceOf(
102
            $attribute,
103
            Attribute::class,
104
            'All md:Attribute elements must be an instance of Attribute.',
105
        );
106
107
        parent::__construct(
108
            $protocolSupportEnumeration,
109
            $ID,
110
            $validUntil,
111
            $cacheDuration,
112
            $extensions,
113
            $errorURL,
114
            $keyDescriptor,
115
            $organization,
116
            $contact,
117
            $artifactResolutionService,
118
            $singleLogoutService,
119
            $manageNameIDService,
120
            $nameIDFormat,
121
        );
122
    }
123
124
125
    /**
126
     * Collect the value of the WantAuthnRequestsSigned-property
127
     *
128
     * @return \SimpleSAML\XMLSchema\Type\BooleanValue|null
129
     */
130
    public function wantAuthnRequestsSigned(): ?BooleanValue
131
    {
132
        return $this->wantAuthnRequestsSigned;
133
    }
134
135
136
    /**
137
     * Get the SingleSignOnService endpoints
138
     *
139
     * @return \SimpleSAML\SAML2\XML\md\SingleSignOnService[]
140
     */
141
    public function getSingleSignOnService(): array
142
    {
143
        return $this->singleSignOnService;
144
    }
145
146
147
    /**
148
     * Get the NameIDMappingService endpoints
149
     *
150
     * @return \SimpleSAML\SAML2\XML\md\NameIDMappingService[]
151
     */
152
    public function getNameIDMappingService(): array
153
    {
154
        return $this->nameIDMappingService;
155
    }
156
157
158
    /**
159
     * Collect the AssertionIDRequestService endpoints
160
     *
161
     * @return \SimpleSAML\SAML2\XML\md\AssertionIDRequestService[]
162
     */
163
    public function getAssertionIDRequestService(): array
164
    {
165
        return $this->assertionIDRequestService;
166
    }
167
168
169
    /**
170
     * Get the attribute profiles supported
171
     *
172
     * @return \SimpleSAML\SAML2\XML\md\AttributeProfile[]
173
     */
174
    public function getAttributeProfile(): array
175
    {
176
        return $this->attributeProfile;
177
    }
178
179
180
    /**
181
     * Get the attributes supported by this IdP
182
     *
183
     * @return \SimpleSAML\SAML2\XML\saml\Attribute[]
184
     */
185
    public function getSupportedAttribute(): array
186
    {
187
        return $this->attribute;
188
    }
189
190
191
    /**
192
     * Initialize an IDPSSODescriptor.
193
     *
194
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
195
     *   if the qualified name of the supplied element is wrong
196
     * @throws \SimpleSAML\XMLSchema\Exception\MissingElementException
197
     *   if one of the mandatory child-elements is missing
198
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
199
     *   if too many child-elements of a type are specified
200
     */
201
    public static function fromXML(DOMElement $xml): static
202
    {
203
        Assert::same($xml->localName, 'IDPSSODescriptor', InvalidDOMElementException::class);
204
        Assert::same($xml->namespaceURI, IDPSSODescriptor::NS, InvalidDOMElementException::class);
205
206
        $orgs = Organization::getChildrenOfClass($xml);
207
        Assert::maxCount(
208
            $orgs,
209
            1,
210
            'More than one Organization found in this descriptor',
211
            TooManyElementsException::class,
212
        );
213
214
        $extensions = Extensions::getChildrenOfClass($xml);
215
        Assert::maxCount(
216
            $extensions,
217
            1,
218
            'Only one md:Extensions element is allowed.',
219
            TooManyElementsException::class,
220
        );
221
222
        $signature = Signature::getChildrenOfClass($xml);
223
        Assert::maxCount(
224
            $signature,
225
            1,
226
            'Only one ds:Signature element is allowed.',
227
            TooManyElementsException::class,
228
        );
229
230
        $idpssod = new static(
231
            SingleSignOnService::getChildrenOfClass($xml),
232
            self::getAttribute($xml, 'protocolSupportEnumeration', SAMLAnyURIListValue::class),
233
            self::getOptionalAttribute($xml, 'WantAuthnRequestsSigned', BooleanValue::class, null),
234
            NameIDMappingService::getChildrenOfClass($xml),
235
            AssertionIDRequestService::getChildrenOfClass($xml),
236
            AttributeProfile::getChildrenOfClass($xml),
237
            Attribute::getChildrenOfClass($xml),
238
            self::getOptionalAttribute($xml, 'ID', IDValue::class, null),
239
            self::getOptionalAttribute($xml, 'validUntil', SAMLDateTimeValue::class, null),
240
            self::getOptionalAttribute($xml, 'cacheDuration', DurationValue::class, null),
241
            !empty($extensions) ? $extensions[0] : null,
242
            self::getOptionalAttribute($xml, 'errorURL', SAMLAnyURIValue::class, null),
243
            KeyDescriptor::getChildrenOfClass($xml),
244
            !empty($orgs) ? $orgs[0] : null,
245
            ContactPerson::getChildrenOfClass($xml),
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\ContactPerson was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
246
            ArtifactResolutionService::getChildrenOfClass($xml),
247
            SingleLogoutService::getChildrenOfClass($xml),
248
            ManageNameIDService::getChildrenOfClass($xml),
249
            NameIDFormat::getChildrenOfClass($xml),
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\NameIDFormat was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
250
        );
251
252
        if (!empty($signature)) {
253
            $idpssod->setSignature($signature[0]);
254
            $idpssod->setXML($xml);
255
        }
256
        return $idpssod;
257
    }
258
259
260
    /**
261
     * Convert this assertion to an unsigned XML document.
262
     * This method does not sign the resulting XML document.
263
     */
264
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
265
    {
266
        $e = parent::toUnsignedXML($parent);
267
268
        if ($this->wantAuthnRequestsSigned() !== null) {
269
            $e->setAttribute(
270
                'WantAuthnRequestsSigned',
271
                var_export($this->wantAuthnRequestsSigned()->toBoolean(), true),
272
            );
273
        }
274
275
        foreach ($this->getSingleSignOnService() as $ep) {
276
            $ep->toXML($e);
277
        }
278
279
        foreach ($this->getNameIDMappingService() as $ep) {
280
            $ep->toXML($e);
281
        }
282
283
        foreach ($this->getAssertionIDRequestService() as $ep) {
284
            $ep->toXML($e);
285
        }
286
287
        foreach ($this->getAttributeProfile() as $ap) {
288
            $ap->toXML($e);
289
        }
290
291
        foreach ($this->getSupportedAttribute() as $a) {
292
            $a->toXML($e);
293
        }
294
295
        return $e;
296
    }
297
}
298