-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
338 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ConstraintViolationException extends RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Process; | ||
|
||
use SimpleSAML\SAML2\Metadata; | ||
|
||
interface IdentityProviderAwareInterface | ||
{ | ||
/** | ||
* Set the IdP metadata. | ||
*/ | ||
public function setIdPMetadata(Metadata\IdentityProvider $idpMetadata): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Process; | ||
|
||
use SimpleSAML\SAML2\Metadata; | ||
|
||
trait IdentityProviderAwareTrait | ||
{ | ||
protected Metadata\IdentityProvider $idpMetadata; | ||
|
||
/** | ||
* Set the IdP metadata. | ||
*/ | ||
public function setIdPMetadata(Metadata\IdentityProvider $idpMetadata): void | ||
{ | ||
$this->idpMetadata = $idpMetadata; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Process; | ||
|
||
use SimpleSAML\SAML2\Metadata; | ||
|
||
interface ServiceProviderAwareInterface | ||
{ | ||
/** | ||
* Set the SP metadata. | ||
*/ | ||
public function setSPMetadata(Metadata\ServiceProvider $spMetadata): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Process; | ||
|
||
use SimpleSAML\SAML2\Metadata; | ||
|
||
trait ServiceProviderAwareTrait | ||
{ | ||
protected Metadata\ServiceProvider $spMetadata; | ||
|
||
/** | ||
* Set the SP metadata. | ||
*/ | ||
public function setSPMetadata(Metadata\ServiceProvider $spMetadata): void | ||
{ | ||
$this->spMetadata = $spMetadata; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/SAML2/Process/Validation/ConstraintValidatorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Validation; | ||
|
||
interface ConstraintValidatorInterface | ||
{ | ||
/** | ||
* Runs the validation. | ||
* | ||
* If this function returns, the validation has been succesful. | ||
* | ||
* @throws \SimpleSAML\SAML2\Exception\ConstraintViolationException when the condition fails. | ||
*/ | ||
public function validate(): void; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/SAML2/Process/Validation/Response/DestinationMatches.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Process\Validation\Response; | ||
|
||
use SimpleSAML\SAML2\{Binding, Metadata}; | ||
use SimpleSAML\SAML2\Process\{ServiceProviderAwareInterface, ServiceProviderAwareTrait}; | ||
use SimpleSAML\SAML2\Process\Response\ConstraintValidatorInterface; | ||
use SimpleSAML\SAML2\XML\samlp\Response; | ||
|
||
final class DestinationMatches implements ConstraintValidatorInterface | ||
{ | ||
/** | ||
* DestinationMatches constructor. | ||
* | ||
* @param \SimpleSAML\SAML2\Metadata\ServiceProvider $spMetadata | ||
* @param \SimpleSAML\SAML2\Binding $binding | ||
*/ | ||
public function __construct( | ||
private Metadata\ServiceProvider $spMetadata, | ||
private Binding $binding, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* @param \SimpleSAML\SAML2\XML\samlp\Response $response | ||
*/ | ||
public function validate(Response $response): void | ||
{ | ||
// Validate that the destination matches the appropriate endpoint from the SP-metadata | ||
foreach ($this->spMetadata->getAssertionConsumerService() as $assertionConsumerService) { | ||
if ($assertionConsumerService->getLocation() === $response->getDestination()) { | ||
if (Binding::getBinding($assertionConsumerService->getBinding()) instanceof $this->binding) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
throw new ResourceNotRecognizedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\Process\Validation; | ||
|
||
use SimpleSAML\SAML2\{Binding, Metadata}; | ||
use SimpleSAML\SAML2\Process\Validation\Response\{DestinationMatches, IsSuccessful}; | ||
|
||
class ResponseValidator implements ValidatorInterface | ||
{ | ||
use ValidatorTrait; | ||
|
||
/** | ||
* @param \SimpleSAML\SAML2\Metadata\IdentityProvider The IdP-metadata | ||
* @param \SimpleSAML\SAML2\Metadata\ServiceProvider The SP-metadata | ||
*/ | ||
private function __construct() | ||
{ | ||
protected Metadata\IdentityProvider $idpMetadata, | ||
protected Metadata\ServiceProvider $spMetadata, | ||
} | ||
|
||
|
||
/** | ||
* @param \SimpleSAML\SAML2\Metadata\IdentityProvider $idpMetadata | ||
* @param \SimpleSAML\SAML2\Metadata\ServiceProvider $spMetadata | ||
* @param string $binding | ||
* @return \SimpleSAML\SAML2\Validation\ResponseValidator | ||
*/ | ||
public static function createResponseValidator( | ||
Metadata\IdentityProvider $idpMetadata, | ||
Metadata\ServiceProvider $spMetadata, | ||
Binding $binding, | ||
): ResponseValidator { | ||
$validator = new self(); | ||
$validator->addConstraintValidator(new DestinationMatches($binding)); | ||
$validator->addConstraintValidator(new IsSuccesful()); | ||
|
||
return $validator; | ||
} | ||
} |
Oops, something went wrong.