diff --git a/src/SAML2/XML/saml/AbstractEvidenceType.php b/src/SAML2/XML/saml/AbstractEvidenceType.php deleted file mode 100644 index 2e4f9ff31..000000000 --- a/src/SAML2/XML/saml/AbstractEvidenceType.php +++ /dev/null @@ -1,151 +0,0 @@ -assertionIDRef) - && empty($this->assertionURIRef) - && empty($this->assertion) - && empty($this->encryptedAssertion) - ); - } - - - /** - * @return \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] - */ - public function getAssertionIDRef(): array - { - return $this->assertionIDRef; - } - - - /** - * @return \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] - */ - public function getAssertionURIRef(): array - { - return $this->assertionURIRef; - } - - - /** - * @return \SimpleSAML\SAML2\XML\saml\Assertion[] - */ - public function getAssertion(): array - { - return $this->assertion; - } - - - /** - * @return \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] - */ - public function getEncryptedAssertion(): array - { - return $this->encryptedAssertion; - } - - - /** - * Convert XML into an AbstractEvidenceType - * - * @param \DOMElement $xml The XML element we should load - * @return static - * - * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException - * If the qualified name of the supplied element is wrong - */ - public static function fromXML(DOMElement $xml): static - { - $qualifiedName = static::getClassName(static::class); - Assert::eq( - $xml->localName, - $qualifiedName, - 'Unexpected name for endpoint: ' . $xml->localName . '. Expected: ' . $qualifiedName . '.', - InvalidDOMElementException::class, - ); - - $assertionIDRef = AssertionIDRef::getChildrenOfClass($xml); - $assertionURIRef = AssertionURIRef::getChildrenOfClass($xml); - $assertion = Assertion::getChildrenOfClass($xml); - $encryptedAssertion = EncryptedAssertion::getChildrenOfClass($xml); - - return new static( - $assertionIDRef, - $assertionURIRef, - $assertion, - $encryptedAssertion, - ); - } - - - /** - * Convert this AbstractEvidenceType to XML. - * - * @param \DOMElement $parent The element we are converting to XML. - * @return \DOMElement The XML element after adding the data corresponding to this Condition. - */ - public function toXML(DOMElement $parent = null): DOMElement - { - $e = $this->instantiateParentElement($parent); - - foreach ($this->getAssertionIDRef() as $assertionIDRef) { - $assertionIDRef->toXML($e); - } - - foreach ($this->getAssertionURIRef() as $assertionURIRef) { - $assertionURIRef->toXML($e); - } - - foreach ($this->getAssertion() as $assertion) { - $assertion->toXML($e); - } - - foreach ($this->getEncryptedAssertion() as $encryptedAssertion) { - $encryptedAssertion->toXML($e); - } - - return $e; - } -} diff --git a/src/SAML2/XML/saml/Evidence.php b/src/SAML2/XML/saml/Evidence.php index 5c5f0be7e..8ef5954aa 100644 --- a/src/SAML2/XML/saml/Evidence.php +++ b/src/SAML2/XML/saml/Evidence.php @@ -4,11 +4,148 @@ namespace SimpleSAML\SAML2\XML\saml; +use DOMElement; +use SimpleSAML\Assert\Assert; +use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Exception\SchemaViolationException; + /** * Class representing a saml:Evidence element. * * @package simplesaml/saml2 */ -final class Evidence extends AbstractEvidenceType +final class Evidence extends AbstractSamlElement { + /** + * @param \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] $assertionIDRef + * @param \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] $assertionURIRef + * @param \SimpleSAML\SAML2\XML\saml\Assertion[] $assertion + * @param \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] $encryptedAssertion + */ + public function __construct( + protected array $assertionIDRef = [], + protected array $assertionURIRef = [], + protected array $assertion = [], + protected array $encryptedAssertion = [], + ) { + Assert::allIsInstanceOf($assertionIDRef, AssertionIDRef::class, SchemaViolationException::class); + Assert::allIsInstanceOf($assertionURIRef, AssertionURIRef::class, SchemaViolationException::class); + Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class); + Assert::allIsInstanceOf($encryptedAssertion, EncryptedAssertion::class, SchemaViolationException::class); + } + + + /** + * Test if an object, at the state it's in, would produce an empty XML-element + * + * @return bool + */ + public function isEmptyElement(): bool + { + return ( + empty($this->assertionIDRef) + && empty($this->assertionURIRef) + && empty($this->assertion) + && empty($this->encryptedAssertion) + ); + } + + + /** + * @return \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] + */ + public function getAssertionIDRef(): array + { + return $this->assertionIDRef; + } + + + /** + * @return \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] + */ + public function getAssertionURIRef(): array + { + return $this->assertionURIRef; + } + + + /** + * @return \SimpleSAML\SAML2\XML\saml\Assertion[] + */ + public function getAssertion(): array + { + return $this->assertion; + } + + + /** + * @return \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] + */ + public function getEncryptedAssertion(): array + { + return $this->encryptedAssertion; + } + + + /** + * Convert XML into an Evidence + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + $qualifiedName = static::getClassName(static::class); + Assert::eq( + $xml->localName, + $qualifiedName, + 'Unexpected name for endpoint: ' . $xml->localName . '. Expected: ' . $qualifiedName . '.', + InvalidDOMElementException::class, + ); + + $assertionIDRef = AssertionIDRef::getChildrenOfClass($xml); + $assertionURIRef = AssertionURIRef::getChildrenOfClass($xml); + $assertion = Assertion::getChildrenOfClass($xml); + $encryptedAssertion = EncryptedAssertion::getChildrenOfClass($xml); + + return new static( + $assertionIDRef, + $assertionURIRef, + $assertion, + $encryptedAssertion, + ); + } + + + /** + * Convert this Evidence to XML. + * + * @param \DOMElement $parent The element we are converting to XML. + * @return \DOMElement The XML element after adding the data corresponding to this Condition. + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + + foreach ($this->getAssertionIDRef() as $assertionIDRef) { + $assertionIDRef->toXML($e); + } + + foreach ($this->getAssertionURIRef() as $assertionURIRef) { + $assertionURIRef->toXML($e); + } + + foreach ($this->getAssertion() as $assertion) { + $assertion->toXML($e); + } + + foreach ($this->getEncryptedAssertion() as $encryptedAssertion) { + $encryptedAssertion->toXML($e); + } + + return $e; + } } diff --git a/tests/SAML2/XML/saml/EvidenceTest.php b/tests/SAML2/XML/saml/EvidenceTest.php index 4a0c6c8b7..ac666e7be 100644 --- a/tests/SAML2/XML/saml/EvidenceTest.php +++ b/tests/SAML2/XML/saml/EvidenceTest.php @@ -22,7 +22,6 @@ * Class \SimpleSAML\SAML2\XML\saml\EvidenceTest * * @covers \SimpleSAML\SAML2\XML\saml\Evidence - * @covers \SimpleSAML\SAML2\XML\saml\AbstractEvidenceType * @covers \SimpleSAML\SAML2\XML\saml\AbstractSamlElement * * @package simplesamlphp/saml2