Skip to content

Commit

Permalink
Create fed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 21, 2024
1 parent cfadcb9 commit 5147e2c
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/XML/fed/AbstractFilterPseudonymsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function fromXML(DOMElement $xml): static


/**
* Add this PseudonymType to an XML element.
* Add this FilterPseudonymsType to an XML element.
*
* @param \DOMElement $parent The element we should append this username token to.
* @return \DOMElement
Expand Down
2 changes: 1 addition & 1 deletion src/XML/fed/AbstractPseudonymType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use DateTimeImmutable;
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\WSSecurity\XML\wsu\Expires;
use SimpleSAML\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\XML\wsu\Expires;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
Expand Down
104 changes: 104 additions & 0 deletions src/XML/fed/AbstractSignOutBasisType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\fed;

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

/**
* A SignOutBasisType
*
* @package tvdijen/ws-security
*/
abstract class AbstractSignOutBasisType extends AbstractFedElement
{
use ExtendableAttributesTrait;
use ExtendableElementTrait;

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

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


/**
* SignOutBasisType constructor.
*
* @param \SimpleSAML\XML\SerializableElementInterface[] $childeren
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
*/
final public function __construct(
array $children = [],
array $namespacedAttributes = [],
) {
Assert::minCount($children, 1, MissingElementException::class);

$this->setElements($children);
$this->setAttributesNS($namespacedAttributes);
}


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

return new static(
$children,
self::getAttributesNSFromXML($xml),
);
}


/**
* Add this SignOutBasisType 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->getAttributesNS() as $attr) {
$attr->toXML($e);
}

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

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

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\fed;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\XML\wsu\Expires;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\Exception\TooElementsException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\XsNamespace as NS;

/**
* A SignOutType
*
* @package tvdijen/ws-security
*/
abstract class AbstractSignOutType extends AbstractFedElement
{
use ExtendableAttributesTrait;
use ExtendableElementTrait;

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

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


/**
* SignOutType constructor.
*
* @param \SimpleSAML\WSSecurity\XML\fed\SignOutBasis $signOutBasis
* @param \SimpleSAML\WSSecurity\XML\fed\Realm|null $realm
* @param string|null $Id
* @param \SimpleSAML\XML\SerializableElementInterface[] $childeren
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
*/
final public function __construct(
protected SignOutBasis $signOutBasis,
protected ?Realm $realm = null,
protected ?string $Id = null,
array $children = [],
array $namespacedAttributes = [],
) {
Assert::nullOrValidNCName($Id);

$this->setElements($children);
$this->setAttributesNS($namespacedAttributes);
}


/**
* Collect the value of the signOutBasis-property
*
* @return \SimpleSAML\WSSecurity\XML\fed\SignOutBasis
*/
public function getSignOutBasis(): SignOutBasis
{
return $this->signOutBasis;
}


/**
* Collect the value of the realm-property
*
* @return \SimpleSAML\WSSecurity\XML\fed\Realm|null
*/
public function getRealm(): ?Realm
{
return $this->realm;
}


/**
* Collect the value of the Id-property
*
* @return string|null
*/
public function getId(): ?string
{
return $this->Id;
}


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

$signOutBasis = SignOutBasis::getChildrenOfClass($xml);
Assert::minCount($signOutBasis, 1, MissingElementException::class);
Assert::maxCount($signOutBasis, 1, TooManyElementsException::class);

$realm = Realm::getChildrenOfClass($xml);
Assert::maxCount($realm, 1, TooManyElementsException::class);

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

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

$nsAttributes = self::getAttributesNSFromXML($xml);

$Id = null;
foreach ($nsAttributes as $i => $attr) {
if ($attr->getNamespaceURI() === C::NS_SEC_UTIL && $attr->getAttrName() === 'Id') {
$Id = $attr->getAttrValue();
unset($nsAttributes[$i]);
break;
}
}

return new static(
array_pop($signOutBasis),
array_pop($realm),
$Id,
$children,
$nsAttributes,
);
}


/**
* Add this SignOutType 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->getRealm()?->toXML($e);
$this->getSignOutBasis()->toXML($e);

$attributes = $this->getAttributesNS();
if ($this->getId() !== null) {
$idAttr = new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', $this->getId());
array_unshift($attributes, $idAttr);
}

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

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

return $e;
}
}
2 changes: 0 additions & 2 deletions src/XML/fed/AdditionalContextProcessed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace SimpleSAML\WSSecurity\XML\fed;

use SimpleSAML\WSSecurity\XML\fed\AbstractAssertionType;

/**
* An AdditionalContextProcessed element
*
Expand Down
14 changes: 14 additions & 0 deletions src/XML/fed/SignOut.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\fed;

/**
* Class defining the SignOut element
*
* @package tvdijen/ws-security
*/
final class SignOut extends AbstractSignOutType
{
}
14 changes: 14 additions & 0 deletions src/XML/fed/SignOutBasis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\fed;

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

0 comments on commit 5147e2c

Please sign in to comment.