Request::getIDPList()   A
last analyzed

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\ecp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
10
use SimpleSAML\SAML2\Type\SAMLStringValue;
11
use SimpleSAML\SAML2\XML\saml\Issuer;
12
use SimpleSAML\SAML2\XML\samlp\IDPList;
13
use SimpleSAML\SOAP11\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\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\SOAP11\Type\MustUnderstandValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\Type\MustUnderstandValue 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...
15
use SimpleSAML\XML\SchemaValidatableElementInterface;
16
use SimpleSAML\XML\SchemaValidatableElementTrait;
17
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
18
use SimpleSAML\XMLSchema\Exception\MissingAttributeException;
19
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
20
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...
21
22
use function intval;
23
use function strval;
24
25
/**
26
 * Class representing the ECP Request element.
27
 *
28
 * @package simplesamlphp/saml2
29
 */
30
final class Request extends AbstractEcpElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\ecp\AbstractEcpElement 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...
31
{
32
    use SchemaValidatableElementTrait;
33
34
35
    /**
36
     * Create a ECP Request element.
37
     *
38
     * @param \SimpleSAML\SAML2\XML\saml\Issuer $issuer
39
     * @param \SimpleSAML\SAML2\XML\samlp\IDPList|null $idpList
40
     * @param \SimpleSAML\SAML2\Type\SAMLStringValue|null $providerName
41
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue|null $isPassive
42
     */
43
    public function __construct(
44
        protected Issuer $issuer,
45
        protected ?IDPList $idpList = null,
46
        protected ?SAMLStringValue $providerName = null,
47
        protected ?BooleanValue $isPassive = null,
48
    ) {
49
    }
50
51
52
    /**
53
     * Collect the value of the isPassive-property
54
     *
55
     * @return \SimpleSAML\XMLSchema\Type\BooleanValue|null
56
     */
57
    public function getIsPassive(): ?BooleanValue
58
    {
59
        return $this->isPassive;
60
    }
61
62
63
    /**
64
     * Collect the value of the providerName-property
65
     *
66
     * @return \SimpleSAML\SAML2\Type\SAMLStringValue|null
67
     */
68
    public function getProviderName(): ?SAMLStringValue
69
    {
70
        return $this->providerName;
71
    }
72
73
74
    /**
75
     * Collect the value of the issuer-property
76
     *
77
     * @return \SimpleSAML\SAML2\XML\saml\Issuer
78
     */
79
    public function getIssuer(): Issuer
80
    {
81
        return $this->issuer;
82
    }
83
84
85
    /**
86
     * Collect the value of the idpList-property
87
     *
88
     * @return \SimpleSAML\SAML2\XML\samlp\IDPList|null
89
     */
90
    public function getIDPList(): ?IDPList
91
    {
92
        return $this->idpList;
93
    }
94
95
96
    /**
97
     * Convert XML into a Request
98
     *
99
     * @param \DOMElement $xml The XML element we should load
100
     *
101
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
102
     *   if the qualified name of the supplied element is wrong
103
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
104
     *   if the supplied element is missing any of the mandatory attributes
105
     */
106
    public static function fromXML(DOMElement $xml): static
107
    {
108
        Assert::same($xml->localName, 'Request', InvalidDOMElementException::class);
109
        Assert::same($xml->namespaceURI, Request::NS, InvalidDOMElementException::class);
110
111
        // Assert required attributes
112
        Assert::true(
113
            $xml->hasAttributeNS(C::NS_SOAP_ENV, 'actor'),
114
            'Missing env:actor attribute in <ecp:Request>.',
115
            MissingAttributeException::class,
116
        );
117
        Assert::true(
118
            $xml->hasAttributeNS(C::NS_SOAP_ENV, 'mustUnderstand'),
119
            'Missing env:mustUnderstand attribute in <ecp:Request>.',
120
            MissingAttributeException::class,
121
        );
122
123
        MustUnderstandValue::fromString($xml->getAttributeNS(C::NS_SOAP_ENV, 'mustUnderstand'));
124
125
        Assert::same(
126
            $xml->getAttributeNS(C::NS_SOAP_ENV, 'actor'),
127
            C::SOAP_ACTOR_NEXT,
128
            'Invalid value of env:actor attribute in <ecp:Request>.',
129
            ProtocolViolationException::class,
130
        );
131
132
        $issuer = Issuer::getChildrenOfClass($xml);
133
        Assert::count(
134
            $issuer,
135
            1,
136
            'More than one <saml:Issuer> in <ecp:Request>.',
137
            TooManyElementsException::class,
138
        );
139
140
        $idpList = IDPList::getChildrenOfClass($xml);
141
142
        return new static(
143
            array_pop($issuer),
144
            array_pop($idpList),
145
            self::getOptionalAttribute($xml, 'ProviderName', SAMLStringValue::class, null),
146
            self::getOptionalAttribute($xml, 'IsPassive', BooleanValue::class, null),
147
        );
148
    }
149
150
151
    /**
152
     * Convert this ECP SubjectConfirmation to XML.
153
     *
154
     * @param \DOMElement|null $parent The element we should append this element to.
155
     */
156
    public function toXML(?DOMElement $parent = null): DOMElement
157
    {
158
        $e = $this->instantiateParentElement($parent);
159
        $e->setAttributeNS(C::NS_SOAP_ENV, 'SOAP-ENV:mustUnderstand', '1');
160
        $e->setAttributeNS(C::NS_SOAP_ENV, 'SOAP-ENV:actor', C::SOAP_ACTOR_NEXT);
161
162
        if ($this->getProviderName() !== null) {
163
            $e->setAttribute('ProviderName', $this->getProviderName()->getValue());
164
        }
165
166
        if ($this->getIsPassive() !== null) {
167
            $e->setAttribute('IsPassive', strval(intval($this->getIsPassive()->toBoolean())));
168
        }
169
170
        $this->getIssuer()->toXML($e);
171
        $this->getIDPList()?->toXML($e);
172
173
        return $e;
174
    }
175
}
176