-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
2,461 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsa_200408; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\QNameElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
/** | ||
* Class representing WS-addressing AttributedQNameType. | ||
* | ||
* You can extend the class without extending the constructor. Then you can use the methods available and the class | ||
* will generate an element with the same name as the extending class | ||
* (e.g. \SimpleSAML\WSSecurity\wsa\ProblemHeaderQName). | ||
* | ||
* @package simplesamlphp/ws-security | ||
*/ | ||
abstract class AbstractAttributedQNameType extends AbstractWsaElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
use QNameElementTrait; | ||
|
||
/** The namespace-attribute for the xs:anyElement element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* AbstractAttributedQNameType constructor. | ||
* | ||
* @param string $value The QName. | ||
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes | ||
*/ | ||
final public function __construct(string $value, array $namespacedAttributes = []) | ||
{ | ||
$this->setContent($value); | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into a class instance | ||
* | ||
* @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); | ||
|
||
return new static($xml->textContent, self::getAttributesNSFromXML($xml)); | ||
} | ||
|
||
|
||
/** | ||
* Convert this element to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we should append this element to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
$e->textContent = $this->getContent(); | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsa_200408; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\URIElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
/** | ||
* Class representing WS-addressing AttributedURIType. | ||
* | ||
* You can extend the class without extending the constructor. Then you can use the methods available and the | ||
* class will generate an element with the same name as the extending class (e.g. \SimpleSAML\WSSecurity\wsa\Address). | ||
* | ||
* @package simplesamlphp/ws-security | ||
*/ | ||
abstract class AbstractAttributedURIType extends AbstractWsaElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
use URIElementTrait; | ||
|
||
/** The namespace-attribute for the xs:anyAttribute element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* AbstractAttributedURIType constructor. | ||
* | ||
* @param string $value The localized string. | ||
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes | ||
*/ | ||
final public function __construct(string $value, array $namespacedAttributes = []) | ||
{ | ||
$this->setContent($value); | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into a class instance | ||
* | ||
* @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); | ||
|
||
return new static($xml->textContent, self::getAttributesNSFromXML($xml)); | ||
} | ||
|
||
|
||
/** | ||
* Convert this element to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we should append this element to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
$e->textContent = $this->getContent(); | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsa_200408; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\WSSecurity\Constants as C; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingElementException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\ExtendableElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
use function array_pop; | ||
use function sprintf; | ||
|
||
/** | ||
* Class representing WS-addressing EndpointReferenceType. | ||
* | ||
* You can extend the class without extending the constructor. Then you can use the methods available | ||
* and the class will generate an element with the same name as the extending class | ||
* (e.g. \SimpleSAML\WSSecurity\wsa\EndpointReference). | ||
* | ||
* @package simplesamlphp/ws-security | ||
*/ | ||
abstract class AbstractEndpointReferenceType extends AbstractWsaElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
use ExtendableElementTrait; | ||
|
||
/** The namespace-attribute for the xs:any element */ | ||
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; | ||
|
||
/** The namespace-attribute for the xs:anyAttribute element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* EndpointReferenceType constructor. | ||
* | ||
* @param \SimpleSAML\WSSecurity\XML\wsa_200408\Address $address | ||
* @param \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceProperties|null $referenceProperties | ||
* @param \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceParameters|null $referenceParameters | ||
* @param \SimpleSAML\WSSecurity\XML\wsa_200408\PortType|null $portType | ||
* @param \SimpleSAML\WSSecurity\XML\wsa_200408\ServiceName|null $serviceName | ||
* @param \SimpleSAML\XML\Chunk[] $children | ||
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes | ||
* | ||
* @throws \SimpleSAML\Assert\AssertionFailedException | ||
*/ | ||
final public function __construct( | ||
protected Address $address, | ||
protected ?ReferenceProperties $referenceProperties = null, | ||
protected ?ReferenceParameters $referenceParameters = null, | ||
protected ?PortType $portType = null, | ||
protected ?ServiceName $serviceName = null, | ||
array $children = [], | ||
array $namespacedAttributes = [], | ||
) { | ||
$this->setElements($children); | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the address property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsa_200408\Address | ||
*/ | ||
public function getAddress(): Address | ||
{ | ||
return $this->address; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the referenceProperties property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceProperties|null | ||
*/ | ||
public function getReferenceProperties(): ?ReferenceProperties | ||
{ | ||
return $this->referenceProperties; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the referenceParameters property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceParameters|null | ||
*/ | ||
public function getReferenceParameters(): ?ReferenceParameters | ||
{ | ||
return $this->referenceParameters; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the portType property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsa_200408\PortType|null | ||
*/ | ||
public function getPortType(): ?PortType | ||
{ | ||
return $this->portType; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the serviceName property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsa_200408\ServiceName|null | ||
*/ | ||
public function getServiceName(): ?ServiceName | ||
{ | ||
return $this->serviceName; | ||
} | ||
|
||
|
||
/** | ||
* Initialize an EndpointReferenceType. | ||
* | ||
* Note: this method cannot be used when extending this class, if the constructor has a different signature. | ||
* | ||
* @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 | ||
* @throws \SimpleSAML\XML\Exception\MissingAttributeException | ||
* if the supplied element is missing any of the mandatory attributes | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
$qualifiedName = static::getClassName(static::class); | ||
Assert::eq( | ||
$xml->localName, | ||
$qualifiedName, | ||
sprintf('Unexpected name for endpoint reference: %s. Expected: %s.', $xml->localName, $qualifiedName), | ||
InvalidDOMElementException::class, | ||
); | ||
|
||
$address = Address::getChildrenOfClass($xml); | ||
Assert::minCount($address, 1, MissingElementException::class); | ||
Assert::maxCount($address, 1, TooManyElementsException::class); | ||
|
||
$referenceProperties = ReferenceProperties::getChildrenOfClass($xml); | ||
Assert::maxCount($referenceProperties, 1, TooManyElementsException::class); | ||
|
||
$referenceParameters = ReferenceParameters::getChildrenOfClass($xml); | ||
Assert::maxCount($referenceParameters, 1, TooManyElementsException::class); | ||
|
||
$portType = PortType::getChildrenOfClass($xml); | ||
Assert::maxCount($portType, 1, TooManyElementsException::class); | ||
|
||
$serviceName = ServiceName::getChildrenOfClass($xml); | ||
Assert::maxCount($serviceName, 1, TooManyElementsException::class); | ||
|
||
$children = []; | ||
foreach ($xml->childNodes as $child) { | ||
if (!($child instanceof DOMElement)) { | ||
continue; | ||
} elseif ($child->namespaceURI === C::NS_ADDR_200408) { | ||
continue; | ||
} | ||
|
||
$children[] = new Chunk($child); | ||
} | ||
|
||
return new static( | ||
array_pop($address), | ||
array_pop($referenceProperties), | ||
array_pop($referenceParameters), | ||
array_pop($portType), | ||
array_pop($serviceName), | ||
$children, | ||
self::getAttributesNSFromXML($xml), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Add this endpoint reference to an XML element. | ||
* | ||
* @param \DOMElement $parent The element we should append this endpoint to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = parent::instantiateParentElement($parent); | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
$this->getAddress()->toXML($e); | ||
|
||
$this->getReferenceProperties()?->toXML($e); | ||
$this->getReferenceParameters()?->toXML($e); | ||
$this->getPortType()?->toXML($e); | ||
$this->getServiceName()?->toXML($e); | ||
|
||
foreach ($this->getElements() as $child) { | ||
if (!$child->isEmptyElement()) { | ||
$child->toXML($e); | ||
} | ||
} | ||
|
||
return $e; | ||
} | ||
} |
Oops, something went wrong.