Skip to content

Commit

Permalink
WIP: add saml:AuthorizationDecisionStatement element
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Mar 10, 2024
1 parent 0c832d2 commit 1b4672f
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
142 changes: 142 additions & 0 deletions src/SAML11/XML/saml/AbstractAuthorizationDecisionStatementType.php
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;
}
}
14 changes: 14 additions & 0 deletions src/SAML11/XML/saml/AuthorizationDecisionStatement.php
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
{
}

0 comments on commit 1b4672f

Please sign in to comment.