-
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
5 changed files
with
258 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML11\XML\samlp; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\SAML11\Constants as C; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
|
||
/** | ||
* SAML StatusCode data type. | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
abstract class AbstractStatusCodeType extends AbstractSamlpElement | ||
{ | ||
/** | ||
* Initialize a samlp:StatusCode | ||
* | ||
* @param string $Value | ||
* @param \SimpleSAML\SAML11\XML\samlp\StatusCode[] $subCodes | ||
*/ | ||
final public function __construct( | ||
protected string $Value = C::STATUS_SUCCESS, | ||
protected array $subCodes = [], | ||
) { | ||
Assert::validQName($Value); | ||
Assert::maxCount($subCodes, C::UNBOUNDED_LIMIT); | ||
Assert::allIsInstanceOf($subCodes, StatusCode::class); | ||
} | ||
|
||
|
||
/** | ||
* Collect the Value | ||
* | ||
* @return string | ||
*/ | ||
public function getValue(): string | ||
{ | ||
return $this->Value; | ||
} | ||
|
||
|
||
/** | ||
* Collect the subcodes | ||
* | ||
* @return \SimpleSAML\SAML11\XML\samlp\StatusCode[] | ||
*/ | ||
public function getSubCodes(): array | ||
{ | ||
return $this->subCodes; | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into a StatusCode | ||
* | ||
* @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 | ||
* @throws \SimpleSAML\XML\Exception\MissingAttributeException | ||
* if the supplied element is missing one of the mandatory attributes | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, 'StatusCode', InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, StatusCode::NS, InvalidDOMElementException::class); | ||
|
||
$Value = self::getAttribute($xml, 'Value'); | ||
$subCodes = StatusCode::getChildrenOfClass($xml); | ||
|
||
return new static( | ||
$Value, | ||
$subCodes, | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Convert this StatusCode to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we should append this StatusCode to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
$e->setAttribute('Value', $this->getValue()); | ||
|
||
foreach ($this->getSubCodes() as $subCode) { | ||
$subCode->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\SAML11\XML\samlp; | ||
|
||
/** | ||
* Class representing a saml:StatusCode element. | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
final class StatusCode extends AbstractStatusCodeType | ||
{ | ||
} |
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 @@ | ||
<samlp:StatusCode xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" Value="samlp:Responder"> | ||
<samlp:StatusCode Value="samlp:RequestDenied"/> | ||
</samlp:StatusCode> |
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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\SAML11\XML\samlp; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\SAML11\Constants as C; | ||
use SimpleSAML\SAML11\XML\samlp\AbstractSamlpElement; | ||
use SimpleSAML\SAML11\XML\samlp\StatusCode; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SimpleSAML\SAML11\XML\samlp\StatusCodeTest | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
#[Group('samlp')] | ||
#[CoversClass(StatusCode::class)] | ||
#[CoversClass(AbstractSamlpElement::class)] | ||
final class StatusCodeTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 6) . '/resources/schemas/oasis-sstc-saml-schema-protocol-1.1.xsd'; | ||
|
||
self::$testedClass = StatusCode::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 5) . '/resources/xml/samlp_StatusCode.xml', | ||
); | ||
} | ||
|
||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
|
||
$statusCode = new StatusCode( | ||
C::STATUS_RESPONDER, | ||
[ | ||
new StatusCode(C::STATUS_REQUEST_DENIED), | ||
], | ||
); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($statusCode), | ||
); | ||
} | ||
} |