Skip to content

Commit 49e4264

Browse files
committed
Fix inheritance - No relation between BaseID and NameID
1 parent a6c46e8 commit 49e4264

4 files changed

Lines changed: 130 additions & 86 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
},
4444
"config": {
4545
"allow-plugins": {
46-
"composer/package-versions-deprecated": true
46+
"composer/package-versions-deprecated": true,
47+
"dealerdirect/phpcodesniffer-composer-installer": true
4748
}
4849
}
4950
}

src/SAML2/XML/saml/BaseIDType.php

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,8 @@
1717

1818
abstract class BaseIDType
1919
{
20-
/**
21-
* The security or administrative domain that qualifies the identifier.
22-
* This attribute provides a means to federate identifiers from disparate user stores without collision.
23-
*
24-
* @see saml-core-2.0-os
25-
*
26-
* @var string|null
27-
*/
28-
protected $NameQualifier = null;
20+
use IDNameQualifiersTrait;
2921

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

4023
/**
4124
* The name for this BaseID.
@@ -68,52 +51,6 @@ public function __construct(DOMElement $xml = null)
6851
}
6952

7053

71-
/**
72-
* Collect the value of the NameQualifier-property
73-
*
74-
* @return string|null
75-
*/
76-
public function getNameQualifier() : ?string
77-
{
78-
return $this->NameQualifier;
79-
}
80-
81-
82-
/**
83-
* Set the value of the NameQualifier-property
84-
*
85-
* @param string|null $nameQualifier
86-
* @return void
87-
*/
88-
public function setNameQualifier(string $nameQualifier = null) : void
89-
{
90-
$this->NameQualifier = $nameQualifier;
91-
}
92-
93-
94-
/**
95-
* Collect the value of the SPNameQualifier-property
96-
*
97-
* @return string|null
98-
*/
99-
public function getSPNameQualifier() : ?string
100-
{
101-
return $this->SPNameQualifier;
102-
}
103-
104-
105-
/**
106-
* Set the value of the SPNameQualifier-property
107-
*
108-
* @param string|null $spNameQualifier
109-
* @return void
110-
*/
111-
public function setSPNameQualifier(string $spNameQualifier = null) : void
112-
{
113-
$this->SPNameQualifier = $spNameQualifier;
114-
}
115-
116-
11754
/**
11855
* Convert this BaseID to XML.
11956
*
@@ -132,28 +69,13 @@ public function toXML(DOMElement $parent = null) : DOMElement
13269
$parent->appendChild($element);
13370

13471
if ($this->NameQualifier !== null) {
135-
$element->setAttribute('NameQualifier', $this->NameQualifier);
72+
$element->setAttribute('NameQualifier', $this->getNameQualifier());
13673
}
13774

13875
if ($this->SPNameQualifier !== null) {
139-
$element->setAttribute('SPNameQualifier', $this->SPNameQualifier);
76+
$element->setAttribute('SPNameQualifier', $this->getSPNameQualifier());
14077
}
14178

14279
return $element;
14380
}
144-
145-
146-
/**
147-
* Get a string representation of this BaseIDType object.
148-
*
149-
* @return string The resulting XML, as a string.
150-
*/
151-
public function __toString()
152-
{
153-
$doc = DOMDocumentFactory::create();
154-
$root = $doc->createElementNS(Constants::NS_SAML, 'root');
155-
$ele = $this->toXML($root);
156-
157-
return $doc->saveXML($ele);
158-
}
15981
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SAML2\XML\saml;
6+
7+
/**
8+
* SAML IDNameQualifier attribute group.
9+
*
10+
* @package simplesamlphp/saml2
11+
*/
12+
trait IDNameQualifiersTrait
13+
{
14+
/**
15+
* The security or administrative domain that qualifies the identifier.
16+
* This attribute provides a means to federate identifiers from disparate user stores without collision.
17+
*
18+
* @see saml-core-2.0-os
19+
*
20+
* @var string|null
21+
*/
22+
protected $NameQualifier = null;
23+
24+
25+
/**
26+
* Further qualifies an identifier with the name of a service provider or affiliation of providers.
27+
* This attribute provides an additional means to federate identifiers on the basis of the relying party or parties.
28+
*
29+
* @see saml-core-2.0-os
30+
*
31+
* @var string|null
32+
*/
33+
protected $SPNameQualifier = null;
34+
35+
36+
/**
37+
* Collect the value of the NameQualifier-property
38+
*
39+
* @return string|null
40+
*/
41+
public function getNameQualifier(): ?string
42+
{
43+
return $this->NameQualifier;
44+
}
45+
46+
47+
/**
48+
* Set the value of the NameQualifier-property
49+
*
50+
* @param string|null $nameQualifier
51+
* @return void
52+
*/
53+
public function setNameQualifier(string $nameQualifier = null) : void
54+
{
55+
$this->NameQualifier = $nameQualifier;
56+
}
57+
58+
59+
/**
60+
* Collect the value of the SPNameQualifier-property
61+
*
62+
* @return string|null
63+
*/
64+
public function getSPNameQualifier(): ?string
65+
{
66+
return $this->SPNameQualifier;
67+
}
68+
69+
70+
/**
71+
* Set the value of the SPNameQualifier-property
72+
*
73+
* @param string|null $spNameQualifier
74+
* @return void
75+
*/
76+
public function setSPNameQualifier(string $spNameQualifier = null) : void
77+
{
78+
$this->SPNameQualifier = $spNameQualifier;
79+
}
80+
}

src/SAML2/XML/saml/NameIDType.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
namespace SAML2\XML\saml;
1212

1313
use DOMElement;
14+
use SAML2\Constants;
15+
use SAML2\DOMDocumentFactory;
1416

15-
abstract class NameIDType extends BaseIDType
17+
abstract class NameIDType
1618
{
19+
use IDNameQualifiersTrait;
20+
21+
1722
/**
1823
* A URI reference representing the classification of string-based identifier information. See Section 8.3 for the
1924
* 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
5964
*/
6065
public function __construct(DOMElement $xml = null)
6166
{
62-
parent::__construct($xml);
63-
6467
if ($xml === null) {
6568
return;
6669
}
6770

71+
if ($xml->hasAttribute('NameQualifier')) {
72+
$this->NameQualifier = $xml->getAttribute('NameQualifier');
73+
}
74+
75+
if ($xml->hasAttribute('SPNameQualifier')) {
76+
$this->SPNameQualifier = $xml->getAttribute('SPNameQualifier');
77+
}
78+
6879
if ($xml->hasAttribute('Format')) {
6980
$this->Format = $xml->getAttribute('Format');
7081
}
@@ -154,7 +165,22 @@ public function setSPProvidedID(string $spProvidedID = null) : void
154165
*/
155166
public function toXML(DOMElement $parent = null) : DOMElement
156167
{
157-
$element = parent::toXML($parent);
168+
if ($parent === null) {
169+
$parent = DOMDocumentFactory::create();
170+
$doc = $parent;
171+
} else {
172+
$doc = $parent->ownerDocument;
173+
}
174+
$element = $doc->createElementNS(Constants::NS_SAML, $this->nodeName);
175+
$parent->appendChild($element);
176+
177+
if ($this->NameQualifier !== null) {
178+
$element->setAttribute('NameQualifier', $this->getNameQualifier());
179+
}
180+
181+
if ($this->SPNameQualifier !== null) {
182+
$element->setAttribute('SPNameQualifier', $this->getSPNameQualifier());
183+
}
158184

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

170196
return $element;
171197
}
198+
199+
200+
/**
201+
* Get a string representation of this BaseIDType object.
202+
*
203+
* @return string The resulting XML, as a string.
204+
*/
205+
public function __toString()
206+
{
207+
$doc = DOMDocumentFactory::create();
208+
$root = $doc->createElementNS(Constants::NS_SAML, 'root');
209+
$ele = $this->toXML($root);
210+
211+
return $doc->saveXML($ele);
212+
}
172213
}

0 commit comments

Comments
 (0)