Skip to content
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<exclude-pattern>**/HTTPRedirectTest.php</exclude-pattern>
<exclude-pattern>**/SOAPTest.php</exclude-pattern>
<exclude-pattern>tests/SAML2/Assertion/Validation/AssertionValidatorTest.php</exclude-pattern>
<exclude-pattern>tests/SAML2/Entity/ServiceProviderTest.php</exclude-pattern>
<exclude-pattern>tests/SAML2/XML/saml/AssertionTest.php</exclude-pattern>
<exclude-pattern>tests/SAML2/XML/saml/AttributeValueTest.php</exclude-pattern>
<exclude-pattern>tests/SAML2/XML/saml/AuthnContextTest.php</exclude-pattern>
Expand Down
48 changes: 42 additions & 6 deletions src/Binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
*/
abstract class Binding
{
/**
* The schema to be used for schema validation
*
* @var string
*/
protected static string $schemaFile = 'resources/schemas/saml-schema-protocol-2.0.xsd';

/**
* Whether or not to perform schema validation
*
* @var bool
*/
protected bool $schemaValidation = true;

/**
* The RelayState associated with the message.
*
Expand Down Expand Up @@ -157,7 +171,20 @@ public function getDestination(): ?string


/**
* Set the RelayState associated with he message.
* Override the destination of a message.
*
* Set to null to use the destination set in the message.
*
* @param string|null $destination The destination the message should be delivered to.
*/
public function setDestination(?string $destination = null): void
{
$this->destination = $destination;
}


/**
* Set the RelayState associated with the message.
*
* @param string|null $relayState The RelayState.
*/
Expand All @@ -179,15 +206,24 @@ public function getRelayState(): ?string


/**
* Override the destination of a message.
* Set the schema validation for the message.
*
* Set to null to use the destination set in the message.
* @param bool $schemaValidation
*/
public function setSchemaValidation(bool $schemaValidation): void
{
$this->schemaValidation = $schemaValidation;
}


/**
* Get the schema validation setting.
*
* @param string|null $destination The destination the message should be delivered to.
* @return bool
*/
public function setDestination(?string $destination = null): void
public function getSchemaValidation(): bool
{
$this->destination = $destination;
return $this->schemaValidation;
}


Expand Down
6 changes: 4 additions & 2 deletions src/Binding/HTTPPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ public function receive(ServerRequestInterface $request): AbstractMessage
}

$msgStr = base64_decode($msgStr, true);
$msgStr = DOMDocumentFactory::fromString($msgStr)->saveXML();

$document = DOMDocumentFactory::fromString($msgStr);
$document = DOMDocumentFactory::fromString(
xml: $msgStr,
schemaFile: $this->getSchemaValidation() ? self::$schemaFile : null,
);
Utils::getContainer()->debugMessage($document->documentElement, 'in');

$msg = MessageFactory::fromXML($document->documentElement);
Expand Down
5 changes: 4 additions & 1 deletion src/Binding/HTTPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ public function receive(ServerRequestInterface $request): AbstractMessage
throw new Exception('Error while inflating SAML message.');
}

$document = DOMDocumentFactory::fromString($message);
$document = DOMDocumentFactory::fromString(
xml: $message,
schemaFile: $this->getSchemaValidation() ? self::$schemaFile : null,
);
Utils::getContainer()->debugMessage($document->documentElement, 'in');
$message = MessageFactory::fromXML($document->documentElement);

Expand Down
6 changes: 5 additions & 1 deletion src/Binding/SOAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ public function receive(/** @scrutinizer ignore-unused */ServerRequestInterface
$xpCache = XPath::getXPath($document->documentElement);
/** @var \DOMElement[] $results */
$results = XPath::xpQuery($xml, '/SOAP-ENV:Envelope/SOAP-ENV:Body/*[1]', $xpCache);
$document = DOMDocumentFactory::fromString(
xml: $results[0]->ownerDocument->saveXML($results[0]),
schemaFile: $this->getSchemaValidation() ? self::$schemaFile : null,
);

return MessageFactory::fromXML($results[0]);
return MessageFactory::fromXML($document->documentElement);
}


Expand Down
12 changes: 12 additions & 0 deletions src/Exception/ConstraintValidationFailedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML2\Exception;

/**
* Exception to be raised when validation of a constraint fails.
*/
class ConstraintViolationFailedException extends RuntimeException
{
}
12 changes: 12 additions & 0 deletions src/Exception/MetadataNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML2\Exception;

/**
* Exception to be raised when no metadata was found for a specific entityID
*/
class MetadataNotFoundException extends RuntimeException
{
}
Loading
Loading