Skip to content

Commit

Permalink
Add ws-trust 200502
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Oct 2, 2024
1 parent 5830721 commit 167df65
Show file tree
Hide file tree
Showing 189 changed files with 7,646 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/XML/element.registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,55 @@
'TransformationParameters' => '\SimpleSAML\WSSecurity\XML\wsse\TransformationParameters',
'UsernameToken' => '\SimpleSAML\WSSecurity\XML\wsse\UsernameToken',
],
'http://schemas.xmlsoap.org/ws/2005/02/trust' => [
'AllowPostdating' => '\SimpleSAML\WSSecurity\XML\wst_200502\AllowPostdating',
'AuthenticationType' => '\SimpleSAML\WSSecurity\XML\wst_200502\AuthenticationType',
'Authenticator' => '\SimpleSAML\WSSecurity\XML\wst_200502\Authenticator',
'BinaryExchange' => '\SimpleSAML\WSSecurity\XML\wst_200502\BinaryExchange',
'BinarySecret' => '\SimpleSAML\WSSecurity\XML\wst_200502\BinarySecret',
'CancelTarget' => '\SimpleSAML\WSSecurity\XML\wst_200502\CancelTarget',
'CanonicalizationAlgorithm' => '\SimpleSAML\WSSecurity\XML\wst_200502\CanonicalizationAlgorithm',
'Challenge' => '\SimpleSAML\WSSecurity\XML\wst_200502\Challenge',
'Claims' => '\SimpleSAML\WSSecurity\XML\wst_200502\Claims',
'CombinedHash' => '\SimpleSAML\WSSecurity\XML\wst_200502\CombinedHash',
'ComputedKey' => '\SimpleSAML\WSSecurity\XML\wst_200502\ComputedKey',
'ComputedKeyAlgorithm' => '\SimpleSAML\WSSecurity\XML\wst_200502\ComputedKeyAlgorithm',
'Delegatable' => '\SimpleSAML\WSSecurity\XML\wst_200502\Delegatable',
'DelegateTo' => '\SimpleSAML\WSSecurity\XML\wst_200502\DelegateTo',
'EncryptWith' => '\SimpleSAML\WSSecurity\XML\wst_200502\EncryptWith',
'Encryption' => '\SimpleSAML\WSSecurity\XML\wst_200502\Encryption',
'EncryptionAlgorithm' => '\SimpleSAML\WSSecurity\XML\wst_200502\EncryptionAlgorithm',
'Entropy' => '\SimpleSAML\WSSecurity\XML\wst_200502\Entropy',
'Forwardable' => '\SimpleSAML\WSSecurity\XML\wst_200502\Forwardable',
'IssuedTokens' => '\SimpleSAML\WSSecurity\XML\wst_200502\IssuedTokens',
'Issuer' => '\SimpleSAML\WSSecurity\XML\wst_200502\Issuer',
'KeyExchangeToken' => '\SimpleSAML\WSSecurity\XML\wst_200502\KeyExchangeToken',
'KeySize' => '\SimpleSAML\WSSecurity\XML\wst_200502\KeySize',
'KeyType' => '\SimpleSAML\WSSecurity\XML\wst_200502\KeyType',
'Lifetime' => '\SimpleSAML\WSSecurity\XML\wst_200502\Lifetime',
'OnBehalfOf' => '\SimpleSAML\WSSecurity\XML\wst_200502\OnBehalfOf',
'Participants' => '\SimpleSAML\WSSecurity\XML\wst_200502\Participants',
'ProofEncryption' => '\SimpleSAML\WSSecurity\XML\wst_200502\ProofEncryption',
'RenewTarget' => '\SimpleSAML\WSSecurity\XML\wst_200502\RenewTarget',
'Renewing' => '\SimpleSAML\WSSecurity\XML\wst_200502\Renewing',
'RequestKET' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestKET',
'RequestSecurityToken' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestSecurityToken',
'RequestSecurityTokenResponse' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestSecurityTokenResponse',
'RequestSecurityTokenResponseCollection' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestSecurityTokenResponseCollection',
'RequestType' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestType',
'RequestedAttachedReference' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestedAttachedReference',
'RequestedProofToken' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestedProofToken',
'RequestedSecurityToken' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestedSecurityToken',
'RequestedTokenCancelled' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestedTokenCancelled',
'RequestedUnattachedReference' => '\SimpleSAML\WSSecurity\XML\wst_200502\RequestedUnattachedReference',
'SignChallenge' => '\SimpleSAML\WSSecurity\XML\wst_200502\SignChallenge',
'SignChallengeResponse' => '\SimpleSAML\WSSecurity\XML\wst_200502\SignChallengeResponse',
'SignWith' => '\SimpleSAML\WSSecurity\XML\wst_200502\SignWith',
'SignatureAlgorithm' => '\SimpleSAML\WSSecurity\XML\wst_200502\SignatureAlgorithm',
'Status' => '\SimpleSAML\WSSecurity\XML\wst_200502\Status',
'TokenType' => '\SimpleSAML\WSSecurity\XML\wst_200502\TokenType',
'UseKey' => '\SimpleSAML\WSSecurity\XML\wst_200502\UseKey',
],
'http://docs.oasis-open.org/ws-sx/ws-trust/200512/' => [
'AllowPostdating' => '\SimpleSAML\WSSecurity\XML\wst_200512\AllowPostdating',
'AuthenticationType' => '\SimpleSAML\WSSecurity\XML\wst_200512\AuthenticationType',
Expand Down
106 changes: 106 additions & 0 deletions src/XML/wst_200502/AbstractAuthenticatorType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst_200502;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\XsNamespace as NS;

use function array_pop;

/**
* Class defining the AuthenticatorType element
*
* @package simplesamlphp/ws-security
*/
abstract class AbstractAuthenticatorType extends AbstractWstElement
{
use ExtendableElementTrait;

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


/**
* AbstractAuthenticatorType constructor
*
* @param \SimpleSAML\WSSecurity\XML\wst_200502\CombinedHash|null $combinedHash
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children
*/
final public function __construct(
protected ?CombinedHash $combinedHash = null,
array $children = [],
) {
$this->setElements($children);
}


/**
* @return \SimpleSAML\WSSecurity\XML\wst_200502\CombinedHash|null
*/
public function getCombinedHash(): ?CombinedHash
{
return $this->combinedHash;
}


/**
* Test if an object, at the state it's in, would produce an empty XML-element
*
* @return bool
*/
public function isEmptyElement(): bool
{
return empty($this->getCombinedHash())
&& empty($this->getElements());
}


/**
* 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);

$combinedHash = CombinedHash::getChildrenOfClass($xml);

return new static(
array_pop($combinedHash),
self::getChildElementsFromXML($xml),
);
}


/**
* Add this AuthenticatorType 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);

$this->getCombinedHash()?->toXML($e);

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

return $e;
}
}
114 changes: 114 additions & 0 deletions src/XML/wst_200502/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_200502;

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 simplesamlphp/ws-security
*/
abstract class AbstractBinaryExchangeType extends AbstractWstElement
{
use ExtendableAttributesTrait;
use StringElementTrait;

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


/**
* @param string $content
* @param string $valueType
* @param string $encodingType
* @param array<\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;
}
}
116 changes: 116 additions & 0 deletions src/XML/wst_200502/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_200502;

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 simplesamlphp/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_200502\BinarySecretTypeEnum|string)[]|null $Type
* @param array<\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;
}
}
Loading

0 comments on commit 167df65

Please sign in to comment.