Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inheritance - No relation between BaseID and NameID #351

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SAML2/XML/saml/AbstractBaseID.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function toXML(DOMElement $parent = null): DOMElement
return $e;
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
Expand Down
25 changes: 3 additions & 22 deletions src/SAML2/XML/saml/AbstractBaseIDType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
abstract class AbstractBaseIDType extends AbstractSamlElement implements BaseIdentifierInterface
{
use IDNameQualifiersTrait;


/**
* Initialize a saml:BaseIDAbstractType from scratch
*
Expand All @@ -33,28 +36,6 @@ protected function __construct(
}


/**
* Collect the value of the NameQualifier-property
*
* @return string|null
*/
public function getNameQualifier(): ?string
{
return $this->nameQualifier;
}


/**
* Collect the value of the SPNameQualifier-property
*
* @return string|null
*/
public function getSPNameQualifier(): ?string
{
return $this->spNameQualifier;
}


/**
* Convert this BaseID to XML.
*
Expand Down
34 changes: 34 additions & 0 deletions src/SAML2/XML/saml/IDNameQualifiersTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML2\XML\saml;

/**
* SAML IDNameQualifier attribute group.
*
* @package simplesamlphp/saml2
*/
trait IDNameQualifiersTrait
{
/**
* Collect the value of the NameQualifier-property
*
* @return string|null
*/
public function getNameQualifier(): ?string
{
return $this->nameQualifier;
}


/**
* Collect the value of the SPNameQualifier-property
*
* @return string|null
*/
public function getSPNameQualifier(): ?string
{
return $this->spNameQualifier;
}
}
25 changes: 0 additions & 25 deletions src/SAML2/XML/saml/Issuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace SimpleSAML\SAML2\XML\saml;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\XML\Exception\InvalidDOMElementException;

/**
* Class representing the saml:Issuer element.
Expand Down Expand Up @@ -64,27 +62,4 @@ public function __construct(

parent::__construct($value, $NameQualifier, $SPNameQualifier, $Format, $SPProvidedID);
}


/**
* Convert XML into an Issuer
*
* @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
{
Assert::same($xml->localName, 'Issuer', InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, Issuer::NS, InvalidDOMElementException::class);

$Format = self::getOptionalAttribute($xml, 'Format', null);
$SPProvidedID = self::getOptionalAttribute($xml, 'SPProvidedID', null);
$NameQualifier = self::getOptionalAttribute($xml, 'NameQualifier', null);
$SPNameQualifier = self::getOptionalAttribute($xml, 'SPNameQualifier', null);

return new static($xml->textContent, $NameQualifier, $SPNameQualifier, $Format, $SPProvidedID);
}
}
25 changes: 0 additions & 25 deletions src/SAML2/XML/saml/NameID.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace SimpleSAML\SAML2\XML\saml;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Exception\ArrayValidationException;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
Expand Down Expand Up @@ -47,29 +45,6 @@ public function __construct(
}


/**
* Convert XML into an NameID
*
* @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
{
Assert::same($xml->localName, 'NameID', InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, NameID::NS, InvalidDOMElementException::class);

$NameQualifier = self::getOptionalAttribute($xml, 'NameQualifier', null);
$SPNameQualifier = self::getOptionalAttribute($xml, 'SPNameQualifier', null);
$Format = self::getOptionalAttribute($xml, 'Format', null);
$SPProvidedID = self::getOptionalAttribute($xml, 'SPProvidedID', null);

return new static($xml->textContent, $NameQualifier, $SPNameQualifier, $Format, $SPProvidedID);
}


public function getBlacklistedAlgorithms(): ?array
{
$container = ContainerSingleton::getInstance();
Expand Down
44 changes: 38 additions & 6 deletions src/SAML2/XML/saml/NameIDType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* @package simplesamlphp/saml2
*/

abstract class NameIDType extends AbstractBaseIDType
abstract class NameIDType extends AbstractSamlElement implements IdentifierInterface
{
use IDNameQualifiersTrait;
use StringElementTrait;


Expand All @@ -30,16 +31,16 @@ abstract class NameIDType extends AbstractBaseIDType
*/
protected function __construct(
string $value,
?string $nameQualifier = null,
?string $spNameQualifier = null,
protected ?string $nameQualifier = null,
protected ?string $spNameQualifier = null,
protected ?string $format = null,
protected ?string $spProvidedID = null,
) {
Assert::nullOrNotWhitespaceOnly($nameQualifier);
Assert::nullOrNotWhitespaceOnly($spNameQualifier);
Assert::nullOrValidURI($format); // Covers the empty string
Assert::nullOrNotWhitespaceOnly($spProvidedID);

parent::__construct($nameQualifier, $spNameQualifier);

$this->setContent($value);
}

Expand Down Expand Up @@ -79,6 +80,29 @@ protected function validateContent(string $content): void
}


/**
* Convert XML into an NameID
*
* @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
{
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);

$NameQualifier = self::getOptionalAttribute($xml, 'NameQualifier', null);
$SPNameQualifier = self::getOptionalAttribute($xml, 'SPNameQualifier', null);
$Format = self::getOptionalAttribute($xml, 'Format', null);
$SPProvidedID = self::getOptionalAttribute($xml, 'SPProvidedID', null);

return new static($xml->textContent, $NameQualifier, $SPNameQualifier, $Format, $SPProvidedID);
}


/**
* Convert this NameIDType to XML.
*
Expand All @@ -87,7 +111,15 @@ protected function validateContent(string $content): void
*/
public function toXML(DOMElement $parent = null): DOMElement
{
$e = parent::toXML($parent);
$e = $this->instantiateParentElement($parent);

if ($this->getNameQualifier() !== null) {
$e->setAttribute('NameQualifier', $this->getNameQualifier());
}

if ($this->getSPNameQualifier() !== null) {
$e->setAttribute('SPNameQualifier', $this->getSPNameQualifier());
}

if ($this->getFormat() !== null) {
$e->setAttribute('Format', $this->getFormat());
Expand Down
Loading