addConstraintValidator()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assertion\Validation;
6
7
use SimpleSAML\SAML2\Configuration\IdentityProvider;
8
use SimpleSAML\SAML2\Configuration\IdentityProviderAware;
9
use SimpleSAML\SAML2\Configuration\ServiceProvider;
10
use SimpleSAML\SAML2\Configuration\ServiceProviderAware;
11
use SimpleSAML\SAML2\XML\saml\SubjectConfirmation;
12
13
class SubjectConfirmationValidator
14
{
15
    /** @var \SimpleSAML\SAML2\Assertion\Validation\SubjectConfirmationConstraintValidator[] */
16
    protected array $constraints;
17
18
19
    /**
20
     * Constructor for SubjectConfirmationValidator
21
     *
22
     * @param \SimpleSAML\SAML2\Configuration\IdentityProvider $identityProvider
23
     * @param \SimpleSAML\SAML2\Configuration\ServiceProvider $serviceProvider
24
     */
25
    public function __construct(
26
        private IdentityProvider $identityProvider,
27
        private ServiceProvider $serviceProvider,
28
    ) {
29
    }
30
31
32
    /**
33
     * @param \SimpleSAML\SAML2\Assertion\Validation\SubjectConfirmationConstraintValidator $constraint
34
     */
35
    public function addConstraintValidator(
36
        SubjectConfirmationConstraintValidator $constraint,
37
    ): void {
38
        if ($constraint instanceof IdentityProviderAware) {
39
            $constraint->setIdentityProvider($this->identityProvider);
40
        }
41
42
        if ($constraint instanceof ServiceProviderAware) {
43
            $constraint->setServiceProvider($this->serviceProvider);
44
        }
45
46
        $this->constraints[] = $constraint;
47
    }
48
49
50
    /**
51
     * @param \SimpleSAML\SAML2\XML\saml\SubjectConfirmation $subjectConfirmation
52
     * @return \SimpleSAML\SAML2\Assertion\Validation\Result
53
     */
54
    public function validate(SubjectConfirmation $subjectConfirmation): Result
55
    {
56
        $result = new Result();
57
        foreach ($this->constraints as $validator) {
58
            $validator->validate($subjectConfirmation, $result);
59
        }
60
61
        return $result;
62
    }
63
}
64