-
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
279 changed files
with
6,457 additions
and
8 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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\Utils; | ||
|
||
use DOMNode; | ||
use DOMXPath; | ||
use SimpleSAML\WSSecurity\Constants as C; | ||
|
||
/** | ||
* Compilation of utilities for XPath. | ||
* | ||
* @package tvdijen/wssecurity | ||
*/ | ||
class XPath extends \SimpleSAML\XMLSecurity\Utils\XPath | ||
{ | ||
/** | ||
* Get a DOMXPath object that can be used to search for WS Security elements. | ||
* | ||
* @param \DOMNode $node The document to associate to the DOMXPath object. | ||
* | ||
* @return \DOMXPath A DOMXPath object ready to use in the given document, with several | ||
* ws-related namespaces already registered. | ||
*/ | ||
public static function getXPath(DOMNode $node): DOMXPath | ||
{ | ||
$xp = parent::getXPath($node); | ||
|
||
$xp->registerNamespace('addr', C::NS_ADDR); | ||
$xp->registerNamespace('auth', C::NS_AUTH); | ||
$xp->registerNamespace('fed', C::NS_FED); | ||
$xp->registerNamespace('trust', C::NS_TRUST); | ||
$xp->registerNamespace('policy', C::NS_POLICY); | ||
$xp->registerNamespace('sp', C::NS_SEC_POLICY); | ||
$xp->registerNamespace('wsse', C::NS_SEC_EXT); | ||
$xp->registerNamespace('wsu', C::NS_SEC_UTIL); | ||
|
||
return $xp; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\sp; | ||
|
||
/** | ||
* An AbsXPath element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class AbsXPath extends AbstractQNameAssertionType | ||
{ | ||
} |
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\sp; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
|
||
use function sprintf; | ||
|
||
/** | ||
* Class representing WS security policy EmptyType. | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractEmptyType extends AbstractSpElement | ||
{ | ||
/** | ||
* AbstractEmptyType constructor. | ||
*/ | ||
final public function __construct() | ||
{ | ||
} | ||
|
||
|
||
/** | ||
* Initialize an EmptyType. | ||
* | ||
* 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 | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
$qualifiedName = static::getClassName(static::class); | ||
Assert::eq( | ||
$xml->localName, | ||
$qualifiedName, | ||
sprintf('Unexpected name for EmptyType: %s. Expected: %s.', $xml->localName, $qualifiedName), | ||
InvalidDOMElementException::class | ||
); | ||
|
||
|
||
return new static(); | ||
} | ||
|
||
|
||
/** | ||
* 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 | ||
{ | ||
return $this->instantiateParentElement($parent); | ||
} | ||
} |
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,129 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\sp; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
use function sprintf; | ||
|
||
/** | ||
* Class representing WS security policy HeaderType. | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractHeaderType extends AbstractSpElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
|
||
/** The namespace-attribute for the xs:anyAttribute element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::ANY; | ||
|
||
|
||
/** | ||
* AbstractHeaderType constructor. | ||
* | ||
* @param string $namespace | ||
* @param string|null $name | ||
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes | ||
*/ | ||
final public function __construct( | ||
protected string $namespace, | ||
protected ?string $name = null, | ||
array $namespacedAttributes = [] | ||
) { | ||
Assert::nullOrValidURI($namespace); | ||
Assert::validQName($name); | ||
|
||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the Name property. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the Namespace property. | ||
* | ||
* @return string | ||
*/ | ||
public function getNamespace(): string | ||
{ | ||
return $this->namespace; | ||
} | ||
|
||
|
||
/** | ||
* Initialize an HeaderType. | ||
* | ||
* 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 | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
$qualifiedName = static::getClassName(static::class); | ||
Assert::eq( | ||
$xml->localName, | ||
$qualifiedName, | ||
sprintf('Unexpected name for HeaderType: %s. Expected: %s.', $xml->localName, $qualifiedName), | ||
InvalidDOMElementException::class | ||
); | ||
|
||
$namespacedAttributes = self::getAttributesNSFromXML($xml); | ||
foreach ($namespacedAttributes as $i => $attr) { | ||
if ($attr->getNamespaceURI() === null) { | ||
if ($attr->getAttrName() === 'Name' || $attr->getAttrName() === 'Namespace') { | ||
unset($namespacedAttributes[$i]); | ||
} | ||
} | ||
} | ||
|
||
return new static( | ||
self::getAttribute($xml, 'Namespace'), | ||
self::getOptionalAttribute($xml, 'Name', null), | ||
$namespacedAttributes, | ||
); | ||
} | ||
|
||
|
||
/** | ||
* 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); | ||
|
||
if ($this->getName() !== null) { | ||
$e->setAttribute('Name', $this->getName()); | ||
} | ||
|
||
$e->setAttribute('Namespace', $this->getNamespace()); | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
Oops, something went wrong.