Skip to content

Commit

Permalink
Backport UnknownRoleDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 18, 2023
1 parent 0b14a42 commit 3cb9737
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 49 deletions.
81 changes: 65 additions & 16 deletions src/SAML2/XML/md/UnknownRoleDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,94 @@

namespace SimpleSAML\SAML2\XML\md;

use DateTimeImmutable;
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Utils\XPath;
use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XMLSecurity\XML\ds\Signature;

use function array_pop;
use function preg_split;

/**
* Class representing unknown RoleDescriptors.
*
* @package SimpleSAMLphp
* @package simplesamlphp/saml2
*/
class UnknownRoleDescriptor extends RoleDescriptor
final class UnknownRoleDescriptor extends AbstractRoleDescriptor
{
/**
* This RoleDescriptor as XML
* Initialize an unknown RoleDescriptor.
*
* @var \SimpleSAML\XML\Chunk
* @param \SimpleSAML\XML\Chunk $chunk The whole RoleDescriptor element as a chunk object.
* @param string $type
* @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
* @param string|null $ID The ID for this document. Defaults to null.
* @param \DateTimeImmutable|null $validUntil Unix time of validity for this document. Defaults to null.
* @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
* @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An Extensions object. Defaults to null.
* @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
* @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements.
* Defaults to an empty array.
* @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
* The organization running this entity. Defaults to null.
* @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts
* An array of contacts for this entity. Defaults to an empty array.
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
*/
private Chunk $xml;
protected function __construct(
protected Chunk $chunk,
string $type,
array $protocolSupportEnumeration,
?string $ID = null,
?DateTimeImmutable $validUntil = null,
?string $cacheDuration = null,
?Extensions $extensions = null,
?string $errorURL = null,
array $keyDescriptors = [],
?Organization $organization = null,
array $contacts = [],
array $namespacedAttributes = []
) {
parent::__construct(
$type,
$protocolSupportEnumeration,
$ID,
$validUntil,
$cacheDuration,
$extensions,
$errorURL,
$keyDescriptors,
$organization,
$contacts,
$namespacedAttributes,
);
}


/**
* Initialize an unknown RoleDescriptor.
* Get the raw version of this RoleDescriptor as a Chunk.
*
* @param \DOMElement $xml The XML element we should load.
* @return \SimpleSAML\XML\Chunk
*/
public function __construct(DOMElement $xml)
public function getRawRoleDescriptor(): Chunk
{
parent::__construct('md:RoleDescriptor', $xml);

$this->xml = new Chunk($xml);
return $this->chunk;
}


/**
* Add this RoleDescriptor to an EntityDescriptor.
* Convert this RoleDescriptor to XML.
*
* @param \DOMElement $parent The EntityDescriptor we should append this RoleDescriptor to.
* @return \DOMElement
* @param \DOMElement|null $parent The element we are converting to XML.
* @return \DOMElement The XML element after adding the data corresponding to this unknown RoleDescriptor.
*/
public function toXML(DOMElement $parent): DOMElement
public function toXML(DOMElement $parent = null): DOMElement
{
return $this->xml->toXML($parent);
return $this->getRawRoleDescriptor()->toXML($parent);
}
}
33 changes: 0 additions & 33 deletions tests/resources/xml/md_UnknownRoleDescriptor.xml

This file was deleted.

0 comments on commit 3cb9737

Please sign in to comment.