Skip to content

Commit

Permalink
Fix saml:Evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 31, 2023
1 parent 7d0c9c2 commit b9e7f75
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 153 deletions.
151 changes: 0 additions & 151 deletions src/SAML2/XML/saml/AbstractEvidenceType.php

This file was deleted.

139 changes: 138 additions & 1 deletion src/SAML2/XML/saml/Evidence.php
Expand Up @@ -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;
}
}
1 change: 0 additions & 1 deletion tests/SAML2/XML/saml/EvidenceTest.php
Expand Up @@ -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
Expand Down

0 comments on commit b9e7f75

Please sign in to comment.