Skip to content

Commit c2ab36b

Browse files
committed
Add constants and enums for saml:Action and validate the contents of the lement
1 parent 15fbb73 commit c2ab36b

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

src/Constants.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,21 @@ class Constants extends \SimpleSAML\XMLSecurity\Constants
464464
*/
465465
public const string STATUS_VERSION_MISMATCH = 'urn:oasis:names:tc:SAML:2.0:status:VersionMismatch';
466466

467+
/**
468+
* Read/Write/Execute/Delete/Control
469+
*/
470+
public const string ACTION_RWEDC = 'urn:oasis:names:tc:SAML:1.0:action:rwedc';
471+
472+
/**
473+
* Read/Write/Execute/Delete/Control with Negation
474+
*/
475+
public const string ACTION_RWEDC_NEGATION = 'urn:oasis:names:tc:SAML:1.0:action:rwedc-negation';
476+
477+
/**
478+
* Get/Head/Put/Post
479+
*/
480+
public const string ACTION_GHPP = 'urn:oasis:names:tc:SAML:1.0:action:ghpp';
481+
467482
/**
468483
* The maximum size for any entityid as per specification
469484
*/

src/XML/saml/Action.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
use DOMElement;
88
use SimpleSAML\SAML2\Assert\Assert;
9+
use SimpleSAML\SAML2\Constants as C;
10+
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
911
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
1012
use SimpleSAML\SAML2\Type\SAMLStringValue;
1113
use SimpleSAML\XML\TypedTextContentTrait;
1214
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
1315

16+
use function array_column;
1417
use function strval;
1518

1619
/**
@@ -38,6 +41,26 @@ public function __construct(
3841
protected SAMLAnyURIValue $namespace,
3942
SAMLStringValue $content,
4043
) {
44+
if ($namespace->equals(C::ACTION_RWEDC)) {
45+
Assert::oneOf(
46+
$content->getValue(),
47+
array_column(RWEDCEnum::cases(), 'value'),
48+
ProtocolViolationException::class,
49+
);
50+
} elseif ($namespace->equals(C::ACTION_RWEDC_NEGATION)) {
51+
Assert::oneOf(
52+
$content->getValue(),
53+
array_column(RWEDCNegationEnum::cases(), 'value'),
54+
ProtocolViolationException::class,
55+
);
56+
} elseif ($namespace->equals(C::ACTION_GHPP)) {
57+
Assert::oneOf(
58+
$content->getValue(),
59+
array_column(GHPPEnum::cases(), 'value'),
60+
ProtocolViolationException::class,
61+
);
62+
}
63+
4164
$this->setContent($content);
4265
}
4366

@@ -61,7 +84,7 @@ public function getNamespace(): SAMLAnyURIValue
6184
*/
6285
public static function fromXML(DOMElement $xml): static
6386
{
64-
Assert::same($xml->localName, 'Action', InvalidDOMElementException::class);
87+
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
6588
Assert::same($xml->namespaceURI, Action::NS, InvalidDOMElementException::class);
6689

6790
return new self(

src/XML/saml/GHPPEnum.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\XML\saml;
6+
7+
enum GHPPEnum: string
8+
{
9+
case GET = 'GET';
10+
case HEAD = 'HEAD';
11+
case PUT = 'PUT';
12+
case POST = 'POST';
13+
}

src/XML/saml/RWEDCEnum.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\XML\saml;
6+
7+
enum RWEDCEnum: string
8+
{
9+
case Read = 'Read';
10+
case Write = 'Write';
11+
case Execute = 'Execute';
12+
case Delete = 'Delete';
13+
case Control = 'Control';
14+
}

src/XML/saml/RWEDCNegationEnum.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\XML\saml;
6+
7+
enum RWEDCNegationEnum: string
8+
{
9+
case Read = 'Read';
10+
case Write = 'Write';
11+
case Execute = 'Execute';
12+
case Delete = 'Delete';
13+
case Control = 'Control';
14+
case NotRead = '~Read';
15+
case NotWrite = '~Write';
16+
case NotExecute = '~Execute';
17+
case NotDelete = '~Delete';
18+
case NotControl = '~Control';
19+
}

0 commit comments

Comments
 (0)