diff --git a/src/SAML2/Exception/ConstraintValidationFailedException.php b/src/SAML2/Exception/ConstraintValidationFailedException.php new file mode 100644 index 000000000..3ad396f44 --- /dev/null +++ b/src/SAML2/Exception/ConstraintValidationFailedException.php @@ -0,0 +1,12 @@ +spMetadata->getAssertionConsumerService() as $assertionConsumerService) { + if ($assertionConsumerService->getLocation() === $response->getDestination()) { + if (Binding::getBinding($assertionConsumerService->getBinding()) instanceof $this->binding) { + return; + } + } + } + throw new ResourceNotRecognizedException(); + } +} diff --git a/src/SAML2/Process/IdentityProviderAwareInterface.php b/src/SAML2/Process/IdentityProviderAwareInterface.php new file mode 100644 index 000000000..d45021828 --- /dev/null +++ b/src/SAML2/Process/IdentityProviderAwareInterface.php @@ -0,0 +1,15 @@ +idpMetadata = $idpMetadata; + } +} diff --git a/src/SAML2/Process/ServiceProviderAwareInterface.php b/src/SAML2/Process/ServiceProviderAwareInterface.php new file mode 100644 index 000000000..7c04a265c --- /dev/null +++ b/src/SAML2/Process/ServiceProviderAwareInterface.php @@ -0,0 +1,15 @@ +spMetadata = $spMetadata; + } +} diff --git a/src/SAML2/Process/Validator/ResponseValidator.php b/src/SAML2/Process/Validator/ResponseValidator.php new file mode 100644 index 000000000..4e84af67f --- /dev/null +++ b/src/SAML2/Process/Validator/ResponseValidator.php @@ -0,0 +1,42 @@ +addConstraintValidator(new DestinationMatches($spMetadata, $binding)); +// $validator->addConstraintValidator(new IsSuccesful()); + + return $validator; + } +} diff --git a/src/SAML2/Process/Validator/ValidatorInterface.php b/src/SAML2/Process/Validator/ValidatorInterface.php new file mode 100644 index 000000000..6e9bccada --- /dev/null +++ b/src/SAML2/Process/Validator/ValidatorInterface.php @@ -0,0 +1,26 @@ + */ + protected array $validators; + + + /** + * Add a validation to the chain. + * + * @param \SimpleSAML\SAML2\Process\ConstraintValidation\ConstraintValidatorInterface $validation + */ + public function addConstraintValidator(ConstraintValidatorInterface $validator) + { + if ($validator instanceof IdentityProviderAwareInterface) { + $validator->setIdentityProvider($this->idpMetadata); + } + + if ($validator instanceof ServiceProviderAwareInterface) { + $validator->setServiceProvider($this->spMetadata); + } + + $this->validators[] = $validator; + } + + + /** + * Runs all the validations in the validation chain. + * + * If this function returns, all validations have been succesful. + * + * @throws \SimpleSAML\SAML2\Exception\ConstraintViolationFailedException when one of the conditions fail. + */ + public function validate(SerializableElementInterface $element): void + { + foreach ($this->validators as $validator) { + $validator->validate($element); + } + } +}