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

SPSSODescriptor::wantAssertionsSigned()   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 SAML2\XML\md;
6
7
use DOMElement;
8
use SAML2\Utils;
9
10
/**
11
 * Class representing SAML 2 SPSSODescriptor.
12
 *
13
 * @package SimpleSAMLphp
14
 */
15
class SPSSODescriptor extends AbstractSSODescriptor
16
{
17
    /**
18
     * Whether this SP signs authentication requests.
19
     *
20
     * @var bool|null
21
     */
22
    private $AuthnRequestsSigned = null;
23
24
    /**
25
     * Whether this SP wants the Assertion elements to be signed.
26
     *
27
     * @var bool|null
28
     */
29
    private $WantAssertionsSigned = null;
30
31
    /**
32
     * List of AssertionConsumerService endpoints for this SP.
33
     *
34
     * Array with IndexedEndpointType objects.
35
     *
36
     * @var \SAML2\XML\md\IndexedEndpointType[]
37
     */
38
    private $AssertionConsumerService = [];
39
40
    /**
41
     * List of AttributeConsumingService descriptors for this SP.
42
     *
43
     * Array with \SAML2\XML\md\AttributeConsumingService objects.
44
     *
45
     * @var \SAML2\XML\md\AttributeConsumingService[]
46
     */
47
    private $AttributeConsumingService = [];
48
49
50
    /**
51
     * Initialize a SPSSODescriptor.
52
     *
53
     * @param \DOMElement|null $xml The XML element we should load.
54
     */
55
    public function __construct(DOMElement $xml = null)
56
    {
57
        parent::__construct('md:SPSSODescriptor', $xml);
0 ignored issues
show
Bug introduced by
'md:SPSSODescriptor' of type string is incompatible with the type array expected by parameter $protocolSupportEnumeration of SAML2\XML\md\AbstractSSODescriptor::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        parent::__construct(/** @scrutinizer ignore-type */ 'md:SPSSODescriptor', $xml);
Loading history...
Bug introduced by
It seems like $xml can also be of type DOMElement; however, parameter $ID of SAML2\XML\md\AbstractSSODescriptor::__construct() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        parent::__construct('md:SPSSODescriptor', /** @scrutinizer ignore-type */ $xml);
Loading history...
58
59
        if ($xml === null) {
60
            return;
61
        }
62
63
        $this->AuthnRequestsSigned = Utils::parseBoolean($xml, 'AuthnRequestsSigned', null);
64
        $this->WantAssertionsSigned = Utils::parseBoolean($xml, 'WantAssertionsSigned', null);
65
66
        /** @var \DOMElement $ep */
67
        foreach (Utils::xpQuery($xml, './saml_metadata:AssertionConsumerService') as $ep) {
68
            $this->AssertionConsumerService[] = new IndexedEndpointType($ep);
69
        }
70
71
        /** @var \DOMElement $acs */
72
        foreach (Utils::xpQuery($xml, './saml_metadata:AttributeConsumingService') as $acs) {
73
            $this->AttributeConsumingService[] = AttributeConsumingService::fromXML($acs);
74
        }
75
    }
76
77
78
    /**
79
     * Collect the value of the AuthnRequestsSigned-property
80
     *
81
     * @return bool|null
82
     */
83
    public function getAuthnRequestsSigned(): ?bool
84
    {
85
        return $this->AuthnRequestsSigned;
86
    }
87
88
89
    /**
90
     * Set the value of the AuthnRequestsSigned-property
91
     *
92
     * @param bool|null $flag
93
     * @return void
94
     */
95
    public function setAuthnRequestsSigned(bool $flag = null): void
96
    {
97
        $this->AuthnRequestsSigned = $flag;
98
    }
99
100
101
    /**
102
     * Collect the value of the WantAssertionsSigned-property
103
     *
104
     * @return bool|null
105
     */
106
    public function wantAssertionsSigned(): ?bool
107
    {
108
        return $this->WantAssertionsSigned;
109
    }
110
111
112
    /**
113
     * Set the value of the WantAssertionsSigned-property
114
     *
115
     * @param bool|null $flag
116
     * @return void
117
     */
118
    public function setWantAssertionsSigned(bool $flag = null): void
119
    {
120
        $this->WantAssertionsSigned = $flag;
121
    }
122
123
124
    /**
125
     * Collect the value of the AssertionConsumerService-property
126
     *
127
     * @return array
128
     */
129
    public function getAssertionConsumerService(): array
130
    {
131
        return $this->AssertionConsumerService;
132
    }
133
134
135
    /**
136
     * Set the value of the AssertionConsumerService-property
137
     *
138
     * @param array $acs
139
     * @return void
140
     */
141
    public function setAssertionConsumerService(array $acs): void
142
    {
143
        $this->AssertionConsumerService = $acs;
144
    }
145
146
147
    /**
148
     * Add the value to the AssertionConsumerService-property
149
     *
150
     * @param \SAML2\XML\md\IndexedEndpointType $acs
151
     * @return void
152
     */
153
    public function addAssertionConsumerService(IndexedEndpointType $acs): void
154
    {
155
        $this->AssertionConsumerService[] = $acs;
156
    }
157
158
159
    /**
160
     * Collect the value of the AttributeConsumingService-property
161
     *
162
     * @return array
163
     */
164
    public function getAttributeConsumingService(): array
165
    {
166
        return $this->AttributeConsumingService;
167
    }
168
169
170
    /**
171
     * Add the value to the AttributeConsumingService-property
172
     *
173
     * @param \SAML2\XML\md\AttributeConsumingService $acs
174
     * @return void
175
     */
176
    public function addAttributeConsumingService(AttributeConsumingService $acs): void
177
    {
178
        $this->AttributeConsumingService[] = $acs;
179
    }
180
181
182
    /**
183
     * Set the value of the AttributeConsumingService-property
184
     *
185
     * @param array $acs
186
     * @return void
187
     */
188
    public function setAttributeConsumingService(array $acs): void
189
    {
190
        $this->AttributeConsumingService = $acs;
191
    }
192
193
194
    /**
195
     * Convert XML into a SPSSODescriptor
196
     *
197
     * @param \DOMElement $xml The XML element we should load
198
     * @return self
199
     */
200
    public static function fromXML(DOMElement $xml): object
201
    {
202
        // @TODO: Actually fill this method with something useful;  this is a dummy!!
203
        return new self(new DOMElement('root'));
204
    }
205
206
207
    /**
208
     * Add this SPSSODescriptor to an EntityDescriptor.
209
     *
210
     * @param \DOMElement|null $parent The EntityDescriptor we should append this SPSSODescriptor to.
211
     * @return \DOMElement
212
     */
213
    public function toXML(?DOMElement $parent = null): DOMElement
214
    {
215
        // @TODO: handle null argument
216
217
        $e = parent::toXML($parent);
218
219
        if (is_bool($this->AuthnRequestsSigned)) {
220
            $e->setAttribute('AuthnRequestsSigned', $this->AuthnRequestsSigned ? 'true' : 'false');
221
        }
222
223
        if (is_bool($this->WantAssertionsSigned)) {
224
            $e->setAttribute('WantAssertionsSigned', $this->WantAssertionsSigned ? 'true' : 'false');
225
        }
226
227
        foreach ($this->AssertionConsumerService as $ep) {
228
            $ep->toXML($e, 'md:AssertionConsumerService');
229
        }
230
231
        foreach ($this->AttributeConsumingService as $acs) {
232
            $acs->toXML($e);
233
        }
234
235
        return $e;
236
    }
237
}
238