-
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
180 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/XML/wst/AbstractRequestSecurityTokenCollectionType.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,82 @@ | ||
<?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; | ||
|
||
/** | ||
* A RequestSecurityTokenCollectionType element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractRequestSecurityTokenCollectionType extends AbstractWstElement | ||
{ | ||
/** | ||
* @param \SimpleSAML\WSSecurity\XML\wst\RequestSecurityToken[] $requestSecurityToken | ||
*/ | ||
final public function __construct( | ||
protected array $requestSecurityToken | ||
) { | ||
Assert::minCount($requestSecurityToken, 2, MissingElementException::class); | ||
Assert::allIsInstanceOf( | ||
$requestSecurityToken, | ||
RequestSecurityToken::class, | ||
SchemaViolationException::class, | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Get the requestSecurityToken property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XMLwst\RequestSecurityToken[] | ||
*/ | ||
public function getRequestSecurityToken(): array | ||
{ | ||
return $this->requestSecurityToken; | ||
} | ||
|
||
|
||
/** | ||
* 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( | ||
RequestSecurityToken::getChildrenOfClass($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->getRequestSecurityToken() as $r) { | ||
$r->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 RequestSecurityTokenCollection element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestSecurityTokenCollection extends AbstractRequestSecurityTokenCollectionType | ||
{ | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/WSSecurity/XML/wst/RequestSecurityTokenCollectionTest.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,76 @@ | ||
<?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\RequestSecurityToken; | ||
use SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenCollection; | ||
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\RequestSecurityTokenCollectionTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenCollection | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractRequestSecurityTokenCollectionType | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestSecurityTokenCollectionTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; | ||
|
||
self::$testedClass = RequestSecurityTokenCollection::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/wst_RequestSecurityTokenCollection.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a RequestSecurityTokenCollection 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'); | ||
$msgId1 = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); | ||
$msgId2 = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7df', [$attr1]); | ||
|
||
$requestSecurityToken1 = new RequestSecurityToken(C::NAMESPACE, [$msgId1], [$attr2]); | ||
$requestSecurityToken2 = new RequestSecurityToken(C::NAMESPACE, [$msgId2], [$attr3]); | ||
|
||
$requestSecurityTokenCollection = new RequestSecurityTokenCollection([ | ||
$requestSecurityToken1, | ||
$requestSecurityToken2, | ||
]); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($requestSecurityTokenCollection), | ||
); | ||
} | ||
} |
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,8 @@ | ||
<wst:RequestSecurityTokenCollection xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/"> | ||
<wst:RequestSecurityToken xmlns:ssp="urn:x-simplesamlphp:namespace" Context="urn:x-simplesamlphp:namespace" ssp:attr1="testval1"> | ||
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:mustUnderstand="1">uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de</wsa:MessageID> | ||
</wst:RequestSecurityToken> | ||
<wst:RequestSecurityToken xmlns:ssp="urn:x-simplesamlphp:namespace" Context="urn:x-simplesamlphp:namespace" ssp:attr2="testval2"> | ||
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:mustUnderstand="1">uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7df</wsa:MessageID> | ||
</wst:RequestSecurityToken> | ||
</wst:RequestSecurityTokenCollection> |