|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\Assertion\Validation\ConstraintValidator; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert; |
|
8
|
|
|
use SimpleSAML\SAML2\Assertion\Validation\Result; |
|
9
|
|
|
use SimpleSAML\SAML2\Assertion\Validation\SubjectConfirmationConstraintValidator; |
|
10
|
|
|
use SimpleSAML\SAML2\XML\saml\SubjectConfirmation; |
|
11
|
|
|
use SimpleSAML\SAML2\XML\samlp\Response; |
|
12
|
|
|
|
|
13
|
|
|
use function sprintf; |
|
14
|
|
|
use function strval; |
|
15
|
|
|
|
|
16
|
|
|
class SubjectConfirmationResponseToMatches implements SubjectConfirmationConstraintValidator |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor for SubjectConfirmationResponseToMatches |
|
20
|
|
|
* |
|
21
|
|
|
* @param \SimpleSAML\SAML2\XML\samlp\Response $response |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct( |
|
24
|
|
|
private Response $response, |
|
25
|
|
|
) { |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param \SimpleSAML\SAML2\XML\saml\SubjectConfirmation $subjectConfirmation |
|
31
|
|
|
* @param \SimpleSAML\SAML2\Assertion\Validation\Result $result |
|
32
|
|
|
* |
|
33
|
|
|
* @throws \SimpleSAML\Assert\AssertionFailedException if assertions are false |
|
34
|
|
|
*/ |
|
35
|
|
|
public function validate(SubjectConfirmation $subjectConfirmation, Result $result): void |
|
36
|
|
|
{ |
|
37
|
|
|
$data = $subjectConfirmation->getSubjectConfirmationData(); |
|
38
|
|
|
Assert::notNull($data); |
|
39
|
|
|
|
|
40
|
|
|
/** @psalm-suppress PossiblyNullReference */ |
|
41
|
|
|
$inResponseTo = $data->getInResponseTo(); |
|
42
|
|
|
if ($inResponseTo && ($this->getInResponseTo() !== false) && ($this->getInResponseTo() !== $inResponseTo)) { |
|
43
|
|
|
$result->addError(sprintf( |
|
44
|
|
|
'InResponseTo in SubjectConfirmationData ("%s") does not match the Response InResponseTo ("%s")', |
|
45
|
|
|
$inResponseTo, |
|
46
|
|
|
strval($this->getInResponseTo()), |
|
47
|
|
|
)); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string|bool |
|
54
|
|
|
*/ |
|
55
|
|
|
private function getInResponseTo() |
|
56
|
|
|
{ |
|
57
|
|
|
$inResponseTo = $this->response->getInResponseTo(); |
|
58
|
|
|
if ($inResponseTo === null) { |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $inResponseTo; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|