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 a6c46e8 commit 49e4264
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 86 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
84 changes: 3 additions & 81 deletions src/SAML2/XML/saml/BaseIDType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,8 @@

abstract class BaseIDType
{
/**
* The security or administrative domain that qualifies the identifier.
* This attribute provides a means to federate identifiers from disparate user stores without collision.
*
* @see saml-core-2.0-os
*
* @var string|null
*/
protected $NameQualifier = null;
use IDNameQualifiersTrait;

/**
* Further qualifies an identifier with the name of a service provider or affiliation of providers.
* This attribute provides an additional means to federate identifiers on the basis of the relying party or parties.
*
* @see saml-core-2.0-os
*
* @var string|null
*/
protected $SPNameQualifier = null;

/**
* The name for this BaseID.
Expand Down Expand Up @@ -68,52 +51,6 @@ public function __construct(DOMElement $xml = null)
}


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


/**
* Set the value of the NameQualifier-property
*
* @param string|null $nameQualifier
* @return void
*/
public function setNameQualifier(string $nameQualifier = null) : void
{
$this->NameQualifier = $nameQualifier;
}


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


/**
* Set the value of the SPNameQualifier-property
*
* @param string|null $spNameQualifier
* @return void
*/
public function setSPNameQualifier(string $spNameQualifier = null) : void
{
$this->SPNameQualifier = $spNameQualifier;
}


/**
* Convert this BaseID to XML.
*
Expand All @@ -132,28 +69,13 @@ public function toXML(DOMElement $parent = null) : DOMElement
$parent->appendChild($element);

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

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

return $element;
}


/**
* Get a string representation of this BaseIDType object.
*
* @return string The resulting XML, as a string.
*/
public function __toString()
{
$doc = DOMDocumentFactory::create();
$root = $doc->createElementNS(Constants::NS_SAML, 'root');
$ele = $this->toXML($root);

return $doc->saveXML($ele);
}
}
80 changes: 80 additions & 0 deletions src/SAML2/XML/saml/IDNameQualifiersTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace SAML2\XML\saml;

/**
* SAML IDNameQualifier attribute group.
*
* @package simplesamlphp/saml2
*/
trait IDNameQualifiersTrait
{
/**
* The security or administrative domain that qualifies the identifier.
* This attribute provides a means to federate identifiers from disparate user stores without collision.
*
* @see saml-core-2.0-os
*
* @var string|null
*/
protected $NameQualifier = null;


/**
* Further qualifies an identifier with the name of a service provider or affiliation of providers.
* This attribute provides an additional means to federate identifiers on the basis of the relying party or parties.
*
* @see saml-core-2.0-os
*
* @var string|null
*/
protected $SPNameQualifier = null;


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


/**
* Set the value of the NameQualifier-property
*
* @param string|null $nameQualifier
* @return void
*/
public function setNameQualifier(string $nameQualifier = null) : void
{
$this->NameQualifier = $nameQualifier;
}


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


/**
* Set the value of the SPNameQualifier-property
*
* @param string|null $spNameQualifier
* @return void
*/
public function setSPNameQualifier(string $spNameQualifier = null) : void
{
$this->SPNameQualifier = $spNameQualifier;
}
}
49 changes: 45 additions & 4 deletions src/SAML2/XML/saml/NameIDType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
namespace SAML2\XML\saml;

use DOMElement;
use SAML2\Constants;
use SAML2\DOMDocumentFactory;

abstract class NameIDType extends BaseIDType
abstract class NameIDType
{
use IDNameQualifiersTrait;


/**
* A URI reference representing the classification of string-based identifier information. See Section 8.3 for the
* SAML-defined URI references that MAY be used as the value of the Format attribute and their associated
Expand Down Expand Up @@ -59,12 +64,18 @@ abstract class NameIDType extends BaseIDType
*/
public function __construct(DOMElement $xml = null)
{
parent::__construct($xml);

if ($xml === null) {
return;
}

if ($xml->hasAttribute('NameQualifier')) {
$this->NameQualifier = $xml->getAttribute('NameQualifier');
}

if ($xml->hasAttribute('SPNameQualifier')) {
$this->SPNameQualifier = $xml->getAttribute('SPNameQualifier');
}

if ($xml->hasAttribute('Format')) {
$this->Format = $xml->getAttribute('Format');
}
Expand Down Expand Up @@ -154,7 +165,22 @@ public function setSPProvidedID(string $spProvidedID = null) : void
*/
public function toXML(DOMElement $parent = null) : DOMElement
{
$element = parent::toXML($parent);
if ($parent === null) {
$parent = DOMDocumentFactory::create();
$doc = $parent;
} else {
$doc = $parent->ownerDocument;
}
$element = $doc->createElementNS(Constants::NS_SAML, $this->nodeName);
$parent->appendChild($element);

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

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

if ($this->Format !== null) {
$element->setAttribute('Format', $this->Format);
Expand All @@ -169,4 +195,19 @@ public function toXML(DOMElement $parent = null) : DOMElement

return $element;
}


/**
* Get a string representation of this BaseIDType object.
*
* @return string The resulting XML, as a string.
*/
public function __toString()
{
$doc = DOMDocumentFactory::create();
$root = $doc->createElementNS(Constants::NS_SAML, 'root');
$ele = $this->toXML($root);

return $doc->saveXML($ele);
}
}

0 comments on commit 49e4264

Please sign in to comment.