Skip to content

Commit

Permalink
Fix inheritance and set xsi:type
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Sep 1, 2024
1 parent 8e0cd8f commit 1aa64f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/XML/fed/AbstractSecurityTokenServiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ final public function __construct(
);

parent::__construct(
static::XSI_TYPE_PREFIX . ':' . static::XSI_TYPE_NAME,
$protocolSupportEnumeration,
$ID,
$validUntil,
Expand Down
14 changes: 5 additions & 9 deletions src/XML/fed/AbstractWebServiceDescriptorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use DateTimeImmutable;
use DOMElement;
use SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType;
use SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor;
use SimpleSAML\SAML2\XML\md\Extensions;
use SimpleSAML\SAML2\XML\md\Organization;

Expand All @@ -15,18 +15,12 @@
*
* @package simplesamlphp/ws-security
*/
abstract class AbstractWebServiceDescriptorType extends AbstractRoleDescriptorType
abstract class AbstractWebServiceDescriptorType extends AbstractRoleDescriptor
{
/** @var string */
public const NS = AbstractFedElement::NS;

/** @var string */
public const NS_PREFIX = AbstractFedElement::NS_PREFIX;


/**
* WebServiceDescriptorType constructor.
*
* @param string $type The xsi-type of the element
* @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.
Expand All @@ -51,6 +45,7 @@ abstract class AbstractWebServiceDescriptorType extends AbstractRoleDescriptorTy
* @param string|null $serviceDescription
*/
protected function __construct(
string $type,
array $protocolSupportEnumeration,
?string $ID = null,
?DateTimeImmutable $validUntil = null,
Expand All @@ -72,6 +67,7 @@ protected function __construct(
protected ?string $serviceDescription = null,
) {
parent::__construct(
$type,
$protocolSupportEnumeration,
$ID,
$validUntil,
Expand Down
24 changes: 14 additions & 10 deletions src/XML/fed/SecurityTokenServiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\XML\md\{ContactPerson, Extensions, KeyDescriptor, Organization};
use SimpleSAML\WSSecurity\Constants as C;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XMLSecurity\XML\ds\Signature;
Expand All @@ -23,15 +23,9 @@
*/
final class SecurityTokenServiceType extends AbstractSecurityTokenServiceType
{
/** @var string */
public const NS = C::NS_MD;

/** @var string */
public const NS_PREFIX = 'md';

/** @var string */
public const LOCALNAME = 'RoleDescriptor';

public const XSI_TYPE_PREFIX = 'fed';
public const XSI_TYPE_NAME = 'SecurityTokenServiceType';
public const XSI_TYPE_NAMESPACE = C::NS_FED;

/**
* Convert XML into a SecurityTokenServiceType RoleDescriptor
Expand All @@ -49,6 +43,15 @@ public static function fromXML(DOMElement $xml): static
Assert::same($xml->localName, 'RoleDescriptor', InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);

Assert::true(
$xml->hasAttributeNS(C::NS_XSI, 'type'),
'Missing required xsi:type in <saml:RoleDescriptor> element.',
SchemaViolationException::class,
);

$type = $xml->getAttributeNS(C::NS_XSI, 'type');
Assert::validQName($type, SchemaViolationException::class);

$protocols = self::getAttribute($xml, 'protocolSupportEnumeration');
$validUntil = self::getOptionalAttribute($xml, 'validUntil', null);
SAMLAssert::nullOrValidDateTime($validUntil);
Expand Down Expand Up @@ -134,6 +137,7 @@ public static function fromXML(DOMElement $xml): static
);

$securityTokenServiceType = new static(
$type,
preg_split('/[\s]+/', trim($protocols)),
self::getOptionalAttribute($xml, 'ID', null),
$validUntil !== null ? new DateTimeImmutable($validUntil) : null,
Expand Down

0 comments on commit 1aa64f0

Please sign in to comment.