Passed
Pull Request — master (#374)
by Tim
02:36
created

getAssertionIDRequestService()   A

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\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Type\AnyURIListValue;
10
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
11
use SimpleSAML\SAML2\Type\SAMLDateTimeValue;
12
use SimpleSAML\SAML2\XML\saml\Attribute;
13
use SimpleSAML\XML\Constants as C;
14
use SimpleSAML\XML\SchemaValidatableElementInterface;
15
use SimpleSAML\XML\SchemaValidatableElementTrait;
16
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
17
use SimpleSAML\XMLSchema\Exception\MissingElementException;
18
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
19
use SimpleSAML\XMLSchema\Type\DurationValue;
20
use SimpleSAML\XMLSchema\Type\IDValue;
21
use SimpleSAML\XMLSecurity\XML\ds\Signature;
22
23
/**
24
 * Class representing SAML 2 metadata AttributeAuthorityDescriptor.
25
 *
26
 * @package simplesamlphp/saml2
27
 */
28
final class AttributeAuthorityDescriptor extends AbstractRoleDescriptorType implements
29
    SchemaValidatableElementInterface
30
{
31
    use SchemaValidatableElementTrait;
32
33
34
    /**
35
     * AttributeAuthorityDescriptor constructor.
36
     *
37
     * @param \SimpleSAML\SAML2\XML\md\AttributeService[] $attributeService
38
     * @param \SimpleSAML\SAML2\Type\AnyURIListValue $protocolSupportEnumeration
39
     * @param \SimpleSAML\SAML2\XML\md\AssertionIDRequestService[] $assertionIDRequestService
40
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormat
41
     * @param \SimpleSAML\SAML2\XML\md\AttributeProfile[] $attributeProfile
42
     * @param \SimpleSAML\SAML2\XML\saml\Attribute[] $attribute
43
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $ID
44
     * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null $validUntil
45
     * @param \SimpleSAML\XMLSchema\Type\DurationValue|null $cacheDuration
46
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions
47
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $errorURL
48
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
49
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptor
50
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contact
51
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\list 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...
52
     */
53
    public function __construct(
54
        protected array $attributeService,
55
        AnyURIListValue $protocolSupportEnumeration,
56
        protected array $assertionIDRequestService = [],
57
        protected array $nameIDFormat = [],
58
        protected array $attributeProfile = [],
59
        protected array $attribute = [],
60
        ?IDValue $ID = null,
61
        ?SAMLDateTimeValue $validUntil = null,
62
        ?DurationValue $cacheDuration = null,
63
        ?Extensions $extensions = null,
64
        ?SAMLAnyURIValue $errorURL = null,
65
        ?Organization $organization = null,
66
        array $keyDescriptor = [],
67
        array $contact = [],
68
        array $namespacedAttributes = [],
69
    ) {
70
        Assert::maxCount($attributeService, C::UNBOUNDED_LIMIT);
71
        Assert::minCount(
72
            $attributeService,
73
            1,
74
            'AttributeAuthorityDescriptor must contain at least one AttributeService.',
75
            MissingElementException::class,
76
        );
77
        Assert::allIsInstanceOf(
78
            $attributeService,
79
            AttributeService::class,
80
            'AttributeService is not an instance of EndpointType.',
81
            InvalidDOMElementException::class,
82
        );
83
        Assert::maxCount($nameIDFormat, C::UNBOUNDED_LIMIT);
84
        Assert::allIsInstanceOf($nameIDFormat, NameIDFormat::class);
85
        Assert::maxCount($assertionIDRequestService, C::UNBOUNDED_LIMIT);
86
        Assert::allIsInstanceOf($assertionIDRequestService, AssertionIDRequestService::class);
87
        Assert::maxCount($attributeProfile, C::UNBOUNDED_LIMIT);
88
        Assert::allIsInstanceOf($attributeProfile, AttributeProfile::class);
89
        Assert::maxCount($attribute, C::UNBOUNDED_LIMIT);
90
        Assert::allIsInstanceOf($attribute, Attribute::class);
91
92
        parent::__construct(
93
            $protocolSupportEnumeration,
94
            $ID,
95
            $validUntil,
96
            $cacheDuration,
97
            $extensions,
98
            $errorURL,
99
            $keyDescriptor,
100
            $organization,
101
            $contact,
102
            $namespacedAttributes,
103
        );
104
    }
105
106
107
    /**
108
     * Collect the value of the AttributeService-property
109
     *
110
     * @return \SimpleSAML\SAML2\XML\md\AttributeService[]
111
     */
112
    public function getAttributeService(): array
113
    {
114
        return $this->attributeService;
115
    }
116
117
118
    /**
119
     * Collect the value of the NameIDFormat-property
120
     *
121
     * @return \SimpleSAML\SAML2\XML\md\NameIDFormat[]
122
     */
123
    public function getNameIDFormat(): array
124
    {
125
        return $this->nameIDFormat;
126
    }
127
128
129
    /**
130
     * Collect the value of the AssertionIDRequestService-property
131
     *
132
     * @return \SimpleSAML\SAML2\XML\md\AssertionIDRequestService[]
133
     */
134
    public function getAssertionIDRequestService(): array
135
    {
136
        return $this->assertionIDRequestService;
137
    }
138
139
140
    /**
141
     * Collect the value of the AttributeProfile-property
142
     *
143
     * @return \SimpleSAML\SAML2\XML\md\AttributeProfile[]
144
     */
145
    public function getAttributeProfile(): array
146
    {
147
        return $this->attributeProfile;
148
    }
149
150
151
    /**
152
     * Collect the value of the Attribute-property
153
     *
154
     * @return \SimpleSAML\SAML2\XML\saml\Attribute[]
155
     */
156
    public function getAttributes(): array
157
    {
158
        return $this->attribute;
159
    }
160
161
162
    /**
163
     * Initialize an IDPSSODescriptor.
164
     *
165
     * @param \DOMElement $xml The XML element we should load.
166
     * @return static
167
     *
168
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
169
     *   if the qualified name of the supplied element is wrong
170
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
171
     *   if the supplied element is missing one of the mandatory attributes
172
     * @throws \SimpleSAML\XMLSchema\Exception\MissingElementException
173
     *   if one of the mandatory child-elements is missing
174
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
175
     *   if too many child-elements of a type are specified
176
     */
177
    public static function fromXML(DOMElement $xml): static
178
    {
179
        Assert::same($xml->localName, 'AttributeAuthorityDescriptor', InvalidDOMElementException::class);
180
        Assert::same($xml->namespaceURI, AttributeAuthorityDescriptor::NS, InvalidDOMElementException::class);
181
182
        $attrServices = AttributeService::getChildrenOfClass($xml);
183
        Assert::notEmpty(
184
            $attrServices,
185
            'Must have at least one AttributeService in AttributeAuthorityDescriptor.',
186
            MissingElementException::class,
187
        );
188
189
        $assertIDReqServices = AssertionIDRequestService::getChildrenOfClass($xml);
190
        $nameIDFormats = NameIDFormat::getChildrenOfClass($xml);
191
        $attrProfiles = AttributeProfile::getChildrenOfClass($xml);
192
        $attributes = Attribute::getChildrenOfClass($xml);
193
194
        $orgs = Organization::getChildrenOfClass($xml);
195
        Assert::maxCount(
196
            $orgs,
197
            1,
198
            'More than one Organization found in this descriptor',
199
            TooManyElementsException::class,
200
        );
201
202
        $extensions = Extensions::getChildrenOfClass($xml);
203
        Assert::maxCount(
204
            $extensions,
205
            1,
206
            'Only one md:Extensions element is allowed.',
207
            TooManyElementsException::class,
208
        );
209
210
        $signature = Signature::getChildrenOfClass($xml);
211
        Assert::maxCount(
212
            $signature,
213
            1,
214
            'Only one ds:Signature element is allowed.',
215
            TooManyElementsException::class,
216
        );
217
218
        $authority = new static(
219
            $attrServices,
220
            self::getAttribute($xml, 'protocolSupportEnumeration', AnyURIListValue::class),
221
            $assertIDReqServices,
222
            $nameIDFormats,
223
            $attrProfiles,
224
            $attributes,
225
            self::getOptionalAttribute($xml, 'ID', IDValue::class, null),
226
            self::getOptionalAttribute($xml, 'validUntil', SAMLDateTimeValue::class, null),
227
            self::getOptionalAttribute($xml, 'cacheDuration', DurationValue::class, null),
228
            !empty($extensions) ? $extensions[0] : null,
229
            self::getOptionalAttribute($xml, 'errorURL', SAMLAnyURIValue::class, null),
230
            !empty($orgs) ? $orgs[0] : null,
231
            KeyDescriptor::getChildrenOfClass($xml),
232
            ContactPerson::getChildrenOfClass($xml),
233
            self::getAttributesNSFromXML($xml),
234
        );
235
236
        if (!empty($signature)) {
237
            $authority->setSignature($signature[0]);
238
            $authority->setXML($xml);
239
        }
240
        return $authority;
241
    }
242
243
244
    /**
245
     * Convert this assertion to an unsigned XML document.
246
     * This method does not sign the resulting XML document.
247
     *
248
     * @return \DOMElement The root element of the DOM tree
249
     */
250
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
251
    {
252
        $e = parent::toUnsignedXML($parent);
253
254
        foreach ($this->getAttributeService() as $ep) {
255
            $ep->toXML($e);
256
        }
257
258
        foreach ($this->getAssertionIDRequestService() as $ep) {
259
            $ep->toXML($e);
260
        }
261
262
        foreach ($this->getNameIDFormat() as $nidFormat) {
263
            $nidFormat->toXML($e);
264
        }
265
266
        foreach ($this->getAttributeProfile() as $ap) {
267
            $ap->toXML($e);
268
        }
269
270
        foreach ($this->getAttributes() as $a) {
271
            $a->toXML($e);
272
        }
273
274
        return $e;
275
    }
276
}
277