-
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.
WIP: add saml:AuthorizationDecisionStatement element
- Loading branch information
Showing
2 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
src/SAML11/XML/saml/AbstractAuthorizationDecisionStatementType.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,142 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML11\XML\saml; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
|
||
/** | ||
* SAML AuthorizationDecisionStatementType abstract data type. | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
abstract class AbstractAuthorizationDecisionStatementType extends AbstractSubjectStatementType | ||
{ | ||
/** | ||
* Initialize a saml:AuthorizationDecisionStatementType from scratch | ||
* | ||
* @param string $resource | ||
* @param \SimpleSAML\SAML11\XML\saml\DecisionTypeEnum $decision | ||
* @param \SimpleSAML\SAML11\XML\saml\Subject $subject | ||
* @param array<\SimpleSAML\SAML11\XML\saml\Action> $action | ||
* @param \SimpleSAML\SAML11\XML\saml\Evidence|null $evidence | ||
*/ | ||
public function __construct( | ||
Subject $subject, | ||
protected string $resource, | ||
protected DecisionTypeEnum $decision, | ||
protected array $action = [], | ||
protected ?Evidence $evidence = null, | ||
) { | ||
Assert::validURI($resource); | ||
Assert::minCount($action, 1, MissingElementException::class); | ||
Assert::allIsInstanceOf($action, Action::class, SchemaViolationException::class); | ||
|
||
parent::__construct($subject); | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the resource-property | ||
* | ||
* @return string | ||
*/ | ||
public function getResource(): string | ||
{ | ||
return $this->resource; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the decision-property | ||
* | ||
* @return \SimpleSAML\SAML11\XML\saml\DecisionTypeEnum | ||
*/ | ||
public function getDecision(): DecisionTypeEnum | ||
{ | ||
return $this->decision; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the evidence-property | ||
* | ||
* @return \SimpleSAML\SAML11\XML\saml\Evidence|null | ||
*/ | ||
public function getEvidence(): ?Evidence | ||
{ | ||
return $this->evidence; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the action-property | ||
* | ||
* @return array<\SimpleSAML\SAML11\XML\saml\Action> | ||
*/ | ||
public function getAction(): array | ||
{ | ||
return $this->action; | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into an AuthorizationDecisionStatementType | ||
* | ||
* @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); | ||
|
||
$subject = Subject::getChildrenOfClass($xml); | ||
Assert::minCount($subject, 1, MissingElementException::class); | ||
Assert::maxCount($subject, 1, TooManyElementsException::class); | ||
|
||
$evidence = Evidence::getChildrenOfClass($xml); | ||
Assert::maxCount($evidence, 1, TooManyElementsException::class); | ||
|
||
return new static( | ||
array_pop($subject), | ||
self::getAttribute($xml, 'Resource'), | ||
DecisionTypeEnum::from(self::getAttribute($xml, 'Decision')), | ||
Action::getChildrenOfClass($xml), | ||
array_pop($evidence), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Convert this AuthorizationDecisionStatementType to XML. | ||
* | ||
* @param \DOMElement $parent The element we are converting to XML. | ||
* @return \DOMElement The XML element after adding the data | ||
* corresponding to this AuthorizationDecisionStatementType. | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = parent::toXML($parent); | ||
|
||
$e->setAttribute('Resource', $this->getResource()); | ||
$e->setAttribute('Decision', $this->getDecision()->value); | ||
|
||
foreach ($this->getAction() as $action) { | ||
$action->toXML($e); | ||
} | ||
|
||
$this->getEvidence()?->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\saml; | ||
|
||
/** | ||
* Class representing a saml:AuthorizationDecisionStatement element. | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
final class AuthorizationDecisionStatement extends AbstractAuthorizationDecisionStatementType | ||
{ | ||
} |