SubjectConfirmationResponseToMatches::validate()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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