AbstractSSODescriptor   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 147
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 46 1
A getNameIDFormat() 0 3 1
A getArtifactResolutionService() 0 3 1
A toUnsignedXML() 0 21 5
A getManageNameIDService() 0 3 1
A getSingleLogoutService() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DateTimeImmutable;
8
use DOMElement;
9
use SimpleSAML\Assert\Assert;
10
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
11
use SimpleSAML\XML\Constants as C;
12
13
/**
14
 * Class representing SAML 2 SSODescriptorType.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
abstract class AbstractSSODescriptor extends AbstractRoleDescriptorType
19
{
20
    /**
21
     * Initialize a RoleDescriptor.
22
     *
23
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
24
     * @param string|null $ID The ID for this document. Defaults to null.
25
     * @param \DateTimeImmutable|null $validUntil Unix time of validity for this document. Defaults to null.
26
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
27
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An array of extensions. Defaults to an empty array.
28
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
29
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements.
30
     *   Defaults to an empty array.
31
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
32
     *   The organization running this entity. Defaults to null.
33
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity.
34
     *   Defaults to an empty array.
35
     * @param \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[] $artifactResolutionService An array of
36
     *   ArtifactResolutionEndpoint. Defaults to an empty array.
37
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $singleLogoutService An array of SingleLogoutEndpoint.
38
     *   Defaults to an empty array.
39
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $manageNameIDService An array of ManageNameIDService.
40
     *   Defaults to an empty array.
41
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormat An array of supported NameID formats.
42
     *   Defaults to an empty array.
43
     */
44
    public function __construct(
45
        array $protocolSupportEnumeration,
46
        ?string $ID = null,
47
        ?DateTimeImmutable $validUntil = null,
48
        ?string $cacheDuration = null,
49
        ?Extensions $extensions = null,
50
        ?string $errorURL = null,
51
        array $keyDescriptors = [],
52
        ?Organization $organization = null,
53
        array $contacts = [],
54
        protected array $artifactResolutionService = [],
55
        protected array $singleLogoutService = [],
56
        protected array $manageNameIDService = [],
57
        protected array $nameIDFormat = [],
58
    ) {
59
        Assert::maxCount($artifactResolutionService, C::UNBOUNDED_LIMIT);
60
        Assert::allIsInstanceOf(
61
            $artifactResolutionService,
62
            ArtifactResolutionService::class,
63
            'All md:ArtifactResolutionService endpoints must be an instance of ArtifactResolutionService.',
64
        );
65
        Assert::maxCount($singleLogoutService, C::UNBOUNDED_LIMIT);
66
        Assert::allIsInstanceOf(
67
            $singleLogoutService,
68
            SingleLogoutService::class,
69
            'All md:SingleLogoutService endpoints must be an instance of SingleLogoutService.',
70
        );
71
        Assert::maxCount($manageNameIDService, C::UNBOUNDED_LIMIT);
72
        Assert::allIsInstanceOf(
73
            $manageNameIDService,
74
            ManageNameIDService::class,
75
            'All md:ManageNameIDService endpoints must be an instance of ManageNameIDService.',
76
        );
77
        Assert::maxCount($nameIDFormat, C::UNBOUNDED_LIMIT);
78
        Assert::allIsInstanceOf($nameIDFormat, NameIDFormat::class, ProtocolViolationException::class);
79
80
        parent::__construct(
81
            $protocolSupportEnumeration,
82
            $ID,
83
            $validUntil,
84
            $cacheDuration,
85
            $extensions,
86
            $errorURL,
87
            $keyDescriptors,
88
            $organization,
89
            $contacts,
90
        );
91
    }
92
93
94
    /**
95
     * Collect the value of the ArtifactResolutionService-property
96
     *
97
     * @return \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[]
98
     */
99
    public function getArtifactResolutionService(): array
100
    {
101
        return $this->artifactResolutionService;
102
    }
103
104
105
    /**
106
     * Collect the value of the SingleLogoutService-property
107
     *
108
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
109
     */
110
    public function getSingleLogoutService(): array
111
    {
112
        return $this->singleLogoutService;
113
    }
114
115
116
    /**
117
     * Collect the value of the ManageNameIDService-property
118
     *
119
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
120
     */
121
    public function getManageNameIDService(): array
122
    {
123
        return $this->manageNameIDService;
124
    }
125
126
127
    /**
128
     * Collect the value of the NameIDFormat-property
129
     *
130
     * @return \SimpleSAML\SAML2\XML\md\NameIDFormat[]
131
     */
132
    public function getNameIDFormat(): array
133
    {
134
        return $this->nameIDFormat;
135
    }
136
137
138
    /**
139
     * Add this SSODescriptorType to an EntityDescriptor.
140
     *
141
     * @param  \DOMElement|null $parent The EntityDescriptor we should append this SSODescriptorType to.
142
     * @return \DOMElement The generated SSODescriptor DOMElement.
143
     */
144
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
145
    {
146
        $e = parent::toUnsignedXML($parent);
147
148
        foreach ($this->getArtifactResolutionService() as $ep) {
149
            $ep->toXML($e);
150
        }
151
152
        foreach ($this->getSingleLogoutService() as $ep) {
153
            $ep->toXML($e);
154
        }
155
156
        foreach ($this->getManageNameIDService() as $ep) {
157
            $ep->toXML($e);
158
        }
159
160
        foreach ($this->getNameIDFormat() as $nidFormat) {
161
            $nidFormat->toXML($e);
162
        }
163
164
        return $e;
165
    }
166
}
167