-
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
192 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php
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,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wst; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
/** | ||
* A RequestSecurityTokenResponseCollectionType element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractRequestSecurityTokenResponseCollectionType extends AbstractWstElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
|
||
/** @var string|\SimpleSAML\XML\XsNamespace */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* @param \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponse[] $requestSecurityTokenResponse | ||
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes | ||
*/ | ||
final public function __construct( | ||
protected array $requestSecurityTokenResponse, | ||
array $namespacedAttributes | ||
) { | ||
Assert::minCount($requestSecurityTokenResponse, 1, MissingElementException::class); | ||
Assert::allIsInstanceOf( | ||
$requestSecurityTokenResponse, | ||
RequestSecurityTokenResponse::class, | ||
SchemaViolationException::class, | ||
); | ||
|
||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Get the requestSecurityTokenResponse property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XMLwst\RequestSecurityTokenResponse[] | ||
Check failure on line 50 in src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php GitHub Actions / Quality controlUndefinedDocblockClass
|
||
*/ | ||
public function getRequestSecurityTokenResponse(): array | ||
{ | ||
return $this->requestSecurityTokenResponse; | ||
} | ||
|
||
|
||
/** | ||
* 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( | ||
RequestSecurityTokenResponse::getChildrenOfClass($xml), | ||
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); | ||
|
||
foreach ($this->getRequestSecurityTokenResponse() as $r) { | ||
$r->toXML($e); | ||
Check failure on line 90 in src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php GitHub Actions / Quality controlUndefinedDocblockClass
|
||
} | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->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 RequestSecurityTokenResponseCollection element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestSecurityTokenResponseCollection extends AbstractRequestSecurityTokenResponseCollectionType | ||
{ | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/WSSecurity/XML/wst/RequestSecurityTokenResponseCollectionTest.php
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,74 @@ | ||
<?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\RequestSecurityTokenResponse; | ||
use SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponseCollection; | ||
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\RequestSecurityTokenResponseCollectionTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponseCollection | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractRequestSecurityTokenResponseCollectionType | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestSecurityTokenResponseCollectionTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; | ||
|
||
self::$testedClass = RequestSecurityTokenResponseCollection::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/wst_RequestSecurityTokenResponseCollection.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a RequestSecurityTokenResponseCollection object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); | ||
$attr2 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1'); | ||
$attr3 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr2', 'testval2'); | ||
$msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); | ||
|
||
$requestSecurityTokenResponse = new RequestSecurityTokenResponse(C::NAMESPACE, [$msgId], [$attr2]); | ||
|
||
$requestSecurityTokenResponseCollection = new RequestSecurityTokenResponseCollection( | ||
[$requestSecurityTokenResponse], | ||
[$attr3], | ||
); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($requestSecurityTokenResponseCollection), | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/resources/xml/wst_RequestSecurityTokenResponseCollection.xml
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,5 @@ | ||
<wst:RequestSecurityTokenResponseCollection xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ssp:attr2="testval2"> | ||
<wst:RequestSecurityTokenResponse Context="urn:x-simplesamlphp:namespace" ssp:attr1="testval1"> | ||
<wsa:MessageID soapenv:mustUnderstand="1">uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de</wsa:MessageID> | ||
</wst:RequestSecurityTokenResponse> | ||
</wst:RequestSecurityTokenResponseCollection> |