Skip to content

Commit

Permalink
Add securitypolicy classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 22, 2023
1 parent 0392ba5 commit 0d6239f
Show file tree
Hide file tree
Showing 279 changed files with 6,214 additions and 8 deletions.
38 changes: 30 additions & 8 deletions resources/schemas/ws-securitypolicy-1.2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
blockDefault="#all" >

<xs:import namespace="http://www.w3.org/2005/08/addressing"
schemaLocation="http://www.w3.org/2006/03/addressing/ws-addr.xsd" />
schemaLocation="ws-addr.xsd" />

<!--
4. Protection Assertions
Expand Down Expand Up @@ -78,6 +78,13 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="ContentEncryptedElements" type="tns:SerElementsType" >
<xs:annotation>
<xs:documentation xml:lang="en">
4.2.3 ContentEncryptedElements Assertion
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="RequiredElements" type="tns:SerElementsType" >
<xs:annotation>
<xs:documentation xml:lang="en" >
Expand All @@ -94,6 +101,21 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
<xs:anyAttribute namespace="##any" processContents="lax" />
</xs:complexType>

<xs:element name="RequiredParts" type="tns:ReqPartsType" >
<xs:annotation>
<xs:documentation xml:lang="en">
4.3.2 RequiredParts Assertion
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="ReqPartsType">
<xs:sequence>
<xs:element name="Header" type="tns:HeaderType" minOccurs="0" maxOccurs="unbounded" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax"/>
</xs:sequence>
<xs:anyAttribute namespace="##any" processContents="lax" />
</xs:complexType>

<!--
5. Token Assertions
-->
Expand All @@ -109,11 +131,11 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
</xs:simpleType>
<xs:simpleType name="IncludeTokenType">
<xs:restriction base="xs:anyURI" >
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-trust/200702/ws-securitypolicy/IncludeToken/Never" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-trust/200702/ws-securitypolicy/IncludeToken/Once" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-trust/200702/ws-securitypolicy/IncludeToken/AlwaysToRecipient" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-trust/200702/ws-securitypolicy/IncludeToken/AlwaysToInitiator" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-trust/200702/ws-securitypolicy/IncludeToken/Always" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Once" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToInitiator" />
<xs:enumeration value="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always" />
</xs:restriction>
</xs:simpleType>

Expand Down Expand Up @@ -1194,12 +1216,12 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="RequireAppiesTo" type="tns:QNameAssertionType">
<xs:element name="RequireAppliesTo" type="tns:QNameAssertionType">
<xs:annotation>
<xs:documentation xml:lang="en">
10.1 Trust13 Assertion
</xs:documentation>
</xs:annotation>
</xs:element>

</xs:schema>
</xs:schema>
5 changes: 5 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Constants extends \SimpleSAML\SAML2\Constants
*/
public const NS_SEC_EXT = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

/**
* The namespace for WS Security Policy.
*/
public const NS_SEC_POLICY = 'http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702';

/**
* The namespace for WS-Security utilities protocol.
*/
Expand Down
41 changes: 41 additions & 0 deletions src/Utils/XPath.php
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;
}
}
14 changes: 14 additions & 0 deletions src/XML/sp/AbsXPath.php
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
{
}
64 changes: 64 additions & 0 deletions src/XML/sp/AbstractEmptyType.php
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);
}
}
129 changes: 129 additions & 0 deletions src/XML/sp/AbstractHeaderType.php
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;
}
}
Loading

0 comments on commit 0d6239f

Please sign in to comment.