Skip to content

Commit

Permalink
Fix inheritance - No relation between BaseID and NameID
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 25, 2024
1 parent 64050b9 commit bc31e1a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
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;
}
}
21 changes: 15 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 @@ -87,7 +88,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

0 comments on commit bc31e1a

Please sign in to comment.