From 1b4672fd8e3f2a262315b1c2f59b1ce3aa7635ef Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Fri, 8 Mar 2024 20:58:24 +0100 Subject: [PATCH] WIP: add saml:AuthorizationDecisionStatement element --- ...ractAuthorizationDecisionStatementType.php | 142 ++++++++++++++++++ .../saml/AuthorizationDecisionStatement.php | 14 ++ 2 files changed, 156 insertions(+) create mode 100644 src/SAML11/XML/saml/AbstractAuthorizationDecisionStatementType.php create mode 100644 src/SAML11/XML/saml/AuthorizationDecisionStatement.php diff --git a/src/SAML11/XML/saml/AbstractAuthorizationDecisionStatementType.php b/src/SAML11/XML/saml/AbstractAuthorizationDecisionStatementType.php new file mode 100644 index 0000000..1986cb0 --- /dev/null +++ b/src/SAML11/XML/saml/AbstractAuthorizationDecisionStatementType.php @@ -0,0 +1,142 @@ + $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; + } +} diff --git a/src/SAML11/XML/saml/AuthorizationDecisionStatement.php b/src/SAML11/XML/saml/AuthorizationDecisionStatement.php new file mode 100644 index 0000000..16d79e8 --- /dev/null +++ b/src/SAML11/XML/saml/AuthorizationDecisionStatement.php @@ -0,0 +1,14 @@ +