-
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
4 changed files
with
175 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wst; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingElementException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
use SimpleSAML\XML\ExtendableElementTrait; | ||
use SimpleSAML\XML\SerializableElementInterface; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
use function array_pop; | ||
|
||
/** | ||
* Class defining the RequestedSecurityTokenType element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractRequestedSecurityTokenType extends AbstractWstElement | ||
{ | ||
use ExtendableElementTrait; | ||
|
||
/** The namespace-attribute for the xs:any element */ | ||
public const XS_ANY_ELT_NAMESPACE = NS::ANY; | ||
|
||
|
||
/** | ||
* AbstractRequestedSecurityTokenType constructor | ||
* | ||
* @param \SimpleSAML\XML\SerializableElementInterface[]|null $child | ||
*/ | ||
final public function __construct( | ||
SerializableElementInterface $child | ||
) { | ||
$this->setElements([$child]); | ||
} | ||
|
||
|
||
/** | ||
* 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; | ||
} | ||
|
||
$children[] = new Chunk($child); | ||
} | ||
|
||
Assert::minCount($children, 1, MissingElementInterfaceException::class); | ||
Assert::maxCount($children, 1, TooManyElementsInterfaceException::class); | ||
|
||
return new static(array_pop($children)); | ||
} | ||
|
||
|
||
/** | ||
* Add this RequestedSecurityTokenType to an XML element. | ||
* | ||
* @param \DOMElement $parent The element we should append this element to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = parent::instantiateParentElement($parent); | ||
|
||
foreach ($this->getElements() as $child) { | ||
if (!$child->isEmptyElement()) { | ||
$child->toXML($e); | ||
} | ||
} | ||
|
||
return $e; | ||
} | ||
} |
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\wst; | ||
|
||
/** | ||
* A RequestedSecurityToken element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestedSecurityToken extends AbstractRequestedSecurityTokenType | ||
{ | ||
} |
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\WSSecurity\XML\wst; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\SOAP\Constants as SOAP; | ||
use SimpleSAML\Test\WSSecurity\Constants as C; | ||
use SimpleSAML\WSSecurity\XML\wsa\MessageID; | ||
use SimpleSAML\WSSecurity\XML\wst\RequestedSecurityToken; | ||
use SimpleSAML\XML\Attribute as XMLAttribute; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
|
||
/** | ||
* Class \SimpleSAML\WSSecurity\XML\wst\RequestedSecurityTokenTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\RequestedSecurityToken | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractRequestedSecurityTokenType | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestedSecurityTokenTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; | ||
|
||
self::$testedClass = RequestedSecurityToken::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/wst_RequestedSecurityToken.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a RequestedSecurityToken object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); | ||
$msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); | ||
|
||
$requestedSecurityToken = new RequestedSecurityToken($msgId); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($requestedSecurityToken), | ||
); | ||
} | ||
} |
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,3 @@ | ||
<wst:RequestedSecurityToken xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/"> | ||
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing" soapenv:mustUnderstand="1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de</wsa:MessageID> | ||
</wst:RequestedSecurityToken> |