AssertionValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
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\Assertion;
12
13
class AssertionValidator
14
{
15
    /**
16
     * @var \SimpleSAML\SAML2\Assertion\Validation\AssertionConstraintValidator[]
17
     */
18
    protected array $constraints;
19
20
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\AssertionConstraintValidator $constraint
34
     */
35
    public function addConstraintValidator(AssertionConstraintValidator $constraint): void
36
    {
37
        if ($constraint instanceof IdentityProviderAware) {
38
            $constraint->setIdentityProvider($this->identityProvider);
39
        }
40
41
        if ($constraint instanceof ServiceProviderAware) {
42
            $constraint->setServiceProvider($this->serviceProvider);
43
        }
44
45
        $this->constraints[] = $constraint;
46
    }
47
48
49
    /**
50
     * @param \SimpleSAML\SAML2\XML\saml\Assertion $assertion
51
     * @return \SimpleSAML\SAML2\Assertion\Validation\Result
52
     */
53
    public function validate(Assertion $assertion): Result
54
    {
55
        $result = new Result();
56
57
        foreach ($this->constraints as $validator) {
58
            $validator->validate($assertion, $result);
59
        }
60
61
        return $result;
62
    }
63
}
64