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 27, 2024
1 parent c7047b0 commit c4a1e67
Show file tree
Hide file tree
Showing 20 changed files with 802 additions and 60 deletions.
116 changes: 116 additions & 0 deletions src/XML/wst/AbstractBinarySecretType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

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

use function array_map;
use function explode;
use function implode;

/**
* A BinarySecertType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractBinarySecretType extends AbstractWstElement
{
use Base64ElementTrait;
use ExtendableAttributesTrait;

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

/** @var string[]|null */
protected ?array $Type;


/**
* @param string $content
* @param (\SimpleSAML\WSSecurity\XML\wst\BinarySecretTypeEnum|string)[]|null $Type
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
*/
final public function __construct(
string $content,
?array $Type = null,
array $namespacedAttributes = []
) {
if ($Type !== null) {
$Type = array_map(
function (BinarySecretTypeEnum|string $v): string {
return ($v instanceof BinarySecretTypeEnum) ? $v->value : $v;
},
$Type,
);
Assert::allValidURI($Type, SchemaViolationException::class);
$this->Type = $Type;
}

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


/**
* Get the Type property.
*
* @return string[]|null
*/
public function getType(): ?array
{
return $this->Type;
}


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

if ($this->getType() !== null) {
$e->setAttribute('Type', implode(' ', $this->getType()));
}

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

return $e;
}
}
60 changes: 0 additions & 60 deletions src/XML/wst/AbstractBinarySecretTypeOpenEnumType.php

This file was deleted.

82 changes: 82 additions & 0 deletions src/XML/wst/AbstractRequestSecurityTokenCollectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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\MissingElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;

/**
* A RequestSecurityTokenCollectionType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractRequestSecurityTokenCollectionType extends AbstractWstElement
{
/**
* @param \SimpleSAML\WSSecurity\XML\wst\RequestSecurityToken[] $requestSecurityToken
*/
final public function __construct(
protected array $requestSecurityToken
) {
Assert::minCount($requestSecurityToken, 2, MissingElementException::class);
Assert::allIsInstanceOf(
$requestSecurityToken,
RequestSecurityToken::class,
SchemaViolationException::class,
);
}


/**
* Get the requestSecurityToken property.
*
* @return \SimpleSAML\WSSecurity\XML\wst\RequestSecurityToken[]
*/
public function getRequestSecurityToken(): array
{
return $this->requestSecurityToken;
}


/**
* 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(
RequestSecurityToken::getChildrenOfClass($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);

foreach ($this->getRequestSecurityToken() as $r) {
$r->toXML($e);
}

return $e;
}
}
99 changes: 99 additions & 0 deletions src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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\MissingElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;

/**
* A RequestSecurityTokenResponseCollectionType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractRequestSecurityTokenResponseCollectionType extends AbstractWstElement
{
use ExtendableAttributesTrait;

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


/**
* @param \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponse[] $requestSecurityTokenResponse
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
*/
final public function __construct(
protected array $requestSecurityTokenResponse,
array $namespacedAttributes
) {
Assert::minCount($requestSecurityTokenResponse, 1, MissingElementException::class);
Assert::allIsInstanceOf(
$requestSecurityTokenResponse,
RequestSecurityTokenResponse::class,
SchemaViolationException::class,
);

$this->setAttributesNS($namespacedAttributes);
}


/**
* Get the requestSecurityTokenResponse property.
*
* @return \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponse[]
*/
public function getRequestSecurityTokenResponse(): array
{
return $this->requestSecurityTokenResponse;
}


/**
* 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(
RequestSecurityTokenResponse::getChildrenOfClass($xml),
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);

foreach ($this->getRequestSecurityTokenResponse() as $r) {
$r->toXML($e);
}

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

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

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

/**
* A BinarySecret element
*
* @package tvdijen/ws-security
*/
final class BinarySecret extends AbstractBinarySecretType
{
}
14 changes: 14 additions & 0 deletions src/XML/wst/IssuedTokens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

/**
* A IssuedTokens element
*
* @package tvdijen/ws-security
*/
final class IssuedTokens extends AbstractRequestSecurityTokenResponseCollectionType
{
}
Loading

0 comments on commit c4a1e67

Please sign in to comment.