simplesamlphp /
saml2
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace SimpleSAML\SAML2\XML\saml; |
||
| 6 | |||
| 7 | use DOMElement; |
||
| 8 | use SimpleSAML\SAML2\Assert\Assert; |
||
| 9 | use SimpleSAML\SAML2\Constants as C; |
||
| 10 | use SimpleSAML\XML\ExtendableElementTrait; |
||
| 11 | use SimpleSAML\XML\SchemaValidatableElementInterface; |
||
| 12 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||
| 13 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||
| 14 | use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
||
| 15 | use SimpleSAML\XMLSchema\XML\Constants\NS; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Class representing a saml:Advice element. |
||
| 19 | * |
||
| 20 | * @package simplesaml/saml2 |
||
| 21 | */ |
||
| 22 | final class Advice extends AbstractSamlElement implements SchemaValidatableElementInterface |
||
| 23 | { |
||
| 24 | use ExtendableElementTrait; |
||
| 25 | use SchemaValidatableElementTrait; |
||
| 26 | |||
| 27 | |||
| 28 | /** The namespace-attribute for the xs:any element */ |
||
| 29 | public const string XS_ANY_ELT_NAMESPACE = NS::OTHER; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * @param \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] $assertionIDRef |
||
| 34 | * @param \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] $assertionURIRef |
||
| 35 | * @param \SimpleSAML\SAML2\XML\saml\Assertion[] $assertion |
||
| 36 | * @param \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] $encryptedAssertion |
||
| 37 | * @param \SimpleSAML\XML\SerializableElementInterface[] $elements |
||
| 38 | */ |
||
| 39 | public function __construct( |
||
| 40 | protected array $assertionIDRef = [], |
||
| 41 | protected array $assertionURIRef = [], |
||
| 42 | protected array $assertion = [], |
||
| 43 | protected array $encryptedAssertion = [], |
||
| 44 | array $elements = [], |
||
| 45 | ) { |
||
| 46 | Assert::maxCount($assertionIDRef, C::UNBOUNDED_LIMIT); |
||
| 47 | Assert::maxCount($assertionURIRef, C::UNBOUNDED_LIMIT); |
||
| 48 | Assert::maxCount($assertion, C::UNBOUNDED_LIMIT); |
||
| 49 | Assert::maxCount($encryptedAssertion, C::UNBOUNDED_LIMIT); |
||
| 50 | Assert::allIsInstanceOf($assertionIDRef, AssertionIDRef::class, SchemaViolationException::class); |
||
| 51 | Assert::allIsInstanceOf($assertionURIRef, AssertionURIRef::class, SchemaViolationException::class); |
||
| 52 | Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class); |
||
| 53 | Assert::allIsInstanceOf($encryptedAssertion, EncryptedAssertion::class, SchemaViolationException::class); |
||
| 54 | |||
| 55 | $this->setElements($elements); |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * Test if an object, at the state it's in, would produce an empty XML-element |
||
| 61 | */ |
||
| 62 | public function isEmptyElement(): bool |
||
| 63 | { |
||
| 64 | return empty($this->assertionIDRef) |
||
| 65 | && empty($this->assertionURIRef) |
||
| 66 | && empty($this->assertion) |
||
| 67 | && empty($this->encryptedAssertion) |
||
| 68 | && empty($this->getElements()); |
||
| 69 | } |
||
| 70 | |||
| 71 | |||
| 72 | /** |
||
| 73 | * @return \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] |
||
| 74 | */ |
||
| 75 | public function getAssertionIDRef(): array |
||
| 76 | { |
||
| 77 | return $this->assertionIDRef; |
||
| 78 | } |
||
| 79 | |||
| 80 | |||
| 81 | /** |
||
| 82 | * @return \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] |
||
| 83 | */ |
||
| 84 | public function getAssertionURIRef(): array |
||
| 85 | { |
||
| 86 | return $this->assertionURIRef; |
||
| 87 | } |
||
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * @return \SimpleSAML\SAML2\XML\saml\Assertion[] |
||
| 92 | */ |
||
| 93 | public function getAssertion(): array |
||
| 94 | { |
||
| 95 | return $this->assertion; |
||
| 96 | } |
||
| 97 | |||
| 98 | |||
| 99 | /** |
||
| 100 | * @return \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] |
||
| 101 | */ |
||
| 102 | public function getEncryptedAssertion(): array |
||
| 103 | { |
||
| 104 | return $this->encryptedAssertion; |
||
| 105 | } |
||
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * Convert XML into an Advice |
||
| 110 | * |
||
| 111 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 112 | * If the qualified name of the supplied element is wrong |
||
| 113 | */ |
||
| 114 | public static function fromXML(DOMElement $xml): static |
||
| 115 | { |
||
| 116 | $qualifiedName = static::getClassName(static::class); |
||
| 117 | Assert::eq( |
||
| 118 | $xml->localName, |
||
| 119 | $qualifiedName, |
||
| 120 | 'Unexpected name for endpoint: ' . $xml->localName . '. Expected: ' . $qualifiedName . '.', |
||
| 121 | InvalidDOMElementException::class, |
||
| 122 | ); |
||
| 123 | |||
| 124 | $assertionIDRef = AssertionIDRef::getChildrenOfClass($xml); |
||
| 125 | $assertionURIRef = AssertionURIRef::getChildrenOfClass($xml); |
||
| 126 | $assertion = Assertion::getChildrenOfClass($xml); |
||
| 127 | $encryptedAssertion = EncryptedAssertion::getChildrenOfClass($xml); |
||
| 128 | |||
| 129 | return new static( |
||
| 130 | $assertionIDRef, |
||
| 131 | $assertionURIRef, |
||
| 132 | $assertion, |
||
| 133 | $encryptedAssertion, |
||
| 134 | self::getChildElementsFromXML($xml), |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | |||
| 138 | |||
| 139 | /** |
||
| 140 | * Convert this Advince to XML. |
||
| 141 | */ |
||
| 142 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 143 | { |
||
| 144 | $e = $this->instantiateParentElement($parent); |
||
| 145 | |||
| 146 | foreach ($this->getAssertionIDRef() as $assertionIDRef) { |
||
| 147 | $assertionIDRef->toXML($e); |
||
| 148 | } |
||
| 149 | |||
| 150 | foreach ($this->getAssertionURIRef() as $assertionURIRef) { |
||
| 151 | $assertionURIRef->toXML($e); |
||
| 152 | } |
||
| 153 | |||
| 154 | foreach ($this->getAssertion() as $assertion) { |
||
| 155 | $assertion->toXML($e); |
||
| 156 | } |
||
| 157 | |||
| 158 | foreach ($this->getEncryptedAssertion() as $encryptedAssertion) { |
||
| 159 | $encryptedAssertion->toXML($e); |
||
| 160 | } |
||
| 161 | |||
| 162 | foreach ($this->getElements() as $element) { |
||
| 163 | $element->toXML($e); |
||
| 164 | } |
||
| 165 | |||
| 166 | return $e; |
||
| 167 | } |
||
| 168 | } |
||
| 169 |