Skip to content

Commit

Permalink
Add wst classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 24, 2024
1 parent bb92cf6 commit 4d548dd
Show file tree
Hide file tree
Showing 68 changed files with 1,667 additions and 176 deletions.
2 changes: 1 addition & 1 deletion resources/schemas/ws-trust.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ elementFormDefault='qualified' >
<xs:restriction base='xs:anyURI' >
<xs:enumeration value='http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey' />
<xs:enumeration value='http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey' />
<xs:enumeration value='http://docs.oasis-open.org/wssx/wstrust/200512/Bearer' />
<xs:enumeration value='http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer' />
</xs:restriction>
</xs:simpleType>

Expand Down
114 changes: 114 additions & 0 deletions src/XML/wst/AbstractBinaryExchangeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\StringElementTrait;
use SimpleSAML\XML\XsNamespace as NS;

/**
* A BinaryExchangeType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractBinaryExchangeType extends AbstractWstElement
{
use ExtendableAttributesTrait;
use StringElementTrait;

/** @var string|\SimpleSAML\XML\XsNamespace */
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
* @param string $content
* @param string $valueType
* @param string $encodingType
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
*/
final public function __construct(
string $content,
protected string $valueType,
protected string $encodingType,
array $namespacedAttributes
) {
Assert::validURI($valueType, SchemaViolationException::class);
Assert::validURI($encodingType, SchemaViolationException::class);

$this->setContent($content);
$this->setAttributesNS($namespacedAttributes);
}


/**
* Get the valueType property.
*
* @return string
*/
public function getValueType(): string
{
return $this->valueType;
}


/**
* Get the valueType property.
*
* @return string
*/
public function getEncodingType(): string
{
return $this->encodingType;
}


/**
* 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::getAttribute($xml, 'ValueType'),
self::getAttribute($xml, 'EncodingType'),
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();

$e->setAttribute('ValueType', $this->getValueType());
$e->setAttribute('EncodingType', $this->getEncodingType());

foreach ($this->getAttributesNS() as $attr) {
$attr->toXML($e);
}

return $e;
}
}
96 changes: 96 additions & 0 deletions src/XML/wst/AbstractCancelTargetType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;

use function array_pop;

/**
* Class defining the CancelTargetType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractCancelTargetType extends AbstractWstElement
{
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;


/**
* AbstractCancelTargetType constructor
*
* @param \SimpleSAML\XML\SerializableElementInterface $child
*/
final public function __construct(
SerializableElementInterface $child
) {
$this->setElements([$child]);
}


/**
* Create an instance of this object from its XML representation.
*
* @param \DOMElement $xml
* @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);

$children = [];
foreach ($xml->childNodes as $child) {
if (!($child instanceof DOMElement)) {
continue;
} elseif ($child->namespaceURI === static::NS) {
continue;
}

$children[] = new Chunk($child);
}

Assert::minCount($children, 1, MissingElementException::class);
Assert::maxCount($children, 1, TooManyElementsException::class);

return new static(
array_pop($children),
);
}


/**
* Add this CancelTargetType to an XML element.
*
* @param \DOMElement $parent The element we should append this username token to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
{
$e = parent::instantiateParentElement($parent);

foreach ($this->getElements() as $child) {
if (!$child->isEmptyElement()) {
$child->toXML($e);
}
}

return $e;
}
}
30 changes: 30 additions & 0 deletions src/XML/wst/AbstractComputedKeyOpenEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

use SimpleSAML\XML\URIElementTrait;

/**
* A ComputedKeyOpenEnum element
*
* @package tvdijen/ws-security
*/
abstract class AbstractComputedKeyOpenEnum extends AbstractWstElement
{
use URIElementTrait;


/**
* @param \SimpleSAML\WSSecurity\XML\wst\ComputedKeyEnum|string $content
*/
public function __construct(ComputedKeyEnum|string $content)
{
if ($content instanceof ComputedKeyEnum) {
$content = $content->value;
}

$this->setContent($content);
}
}
30 changes: 30 additions & 0 deletions src/XML/wst/AbstractKeyTypeOpenEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

use SimpleSAML\XML\URIElementTrait;

/**
* A KeyTypeOpenEnum element
*
* @package tvdijen/ws-security
*/
abstract class AbstractKeyTypeOpenEnum extends AbstractWstElement
{
use URIElementTrait;


/**
* @param \SimpleSAML\WSSecurity\XML\wst\KeyTypeEnum|string $content
*/
public function __construct(KeyTypeEnum|string $content)
{
if ($content instanceof KeyTypeEnum) {
$content = $content->value;
}

$this->setContent($content);
}
}
96 changes: 96 additions & 0 deletions src/XML/wst/AbstractRenewTargetType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;

use function array_pop;

/**
* Class defining the RenewTargetType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractRenewTargetType extends AbstractWstElement
{
use ExtendableElementTrait;

/** The namespace-attribute for the xs:any element */
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;


/**
* AbstractRenewTargetType constructor
*
* @param \SimpleSAML\XML\SerializableElementInterface $child
*/
final public function __construct(
SerializableElementInterface $child
) {
$this->setElements([$child]);
}


/**
* Create an instance of this object from its XML representation.
*
* @param \DOMElement $xml
* @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);

$children = [];
foreach ($xml->childNodes as $child) {
if (!($child instanceof DOMElement)) {
continue;
} elseif ($child->namespaceURI === static::NS) {
continue;
}

$children[] = new Chunk($child);
}

Assert::minCount($children, 1, MissingElementException::class);
Assert::maxCount($children, 1, TooManyElementsException::class);

return new static(
array_pop($children),
);
}


/**
* Add this RenewTargetType to an XML element.
*
* @param \DOMElement $parent The element we should append this username token to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
{
$e = parent::instantiateParentElement($parent);

foreach ($this->getElements() as $child) {
if (!$child->isEmptyElement()) {
$child->toXML($e);
}
}

return $e;
}
}
Loading

0 comments on commit 4d548dd

Please sign in to comment.