diff --git a/composer.json b/composer.json index 05d36d351..872baa73e 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,8 @@ }, "config": { "allow-plugins": { - "composer/package-versions-deprecated": true + "composer/package-versions-deprecated": true, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/src/SAML2/XML/saml/BaseIDType.php b/src/SAML2/XML/saml/BaseIDType.php index a04ea5a5f..d5be51a53 100644 --- a/src/SAML2/XML/saml/BaseIDType.php +++ b/src/SAML2/XML/saml/BaseIDType.php @@ -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. @@ -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. * @@ -141,19 +78,4 @@ 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); - } } diff --git a/src/SAML2/XML/saml/IDNameQualifiersTrait.php b/src/SAML2/XML/saml/IDNameQualifiersTrait.php new file mode 100644 index 000000000..d3ac25e67 --- /dev/null +++ b/src/SAML2/XML/saml/IDNameQualifiersTrait.php @@ -0,0 +1,80 @@ +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; + } +} diff --git a/src/SAML2/XML/saml/NameIDType.php b/src/SAML2/XML/saml/NameIDType.php index 25088f776..25fe27955 100644 --- a/src/SAML2/XML/saml/NameIDType.php +++ b/src/SAML2/XML/saml/NameIDType.php @@ -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 @@ -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'); } @@ -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->NameQualifier); + } + + if ($this->SPNameQualifier !== null) { + $element->setAttribute('SPNameQualifier', $this->SPNameQualifier); + } if ($this->Format !== null) { $element->setAttribute('Format', $this->Format); @@ -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); + } }