SubjectConfirmationResponseToMatches   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 13 4
A getInResponseTo() 0 3 1
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