Passed
Pull Request — master (#336)
by Tim
03:28 queued 01:20
created

SubjectConfirmationNotBefore::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assertion\Validation\ConstraintValidator;
6
7
use Beste\Clock;
8
use DateInterval;
9
use SimpleSAML\Assert\Assert;
10
use SimpleSAML\SAML2\Assertion\Validation\Result;
11
use SimpleSAML\SAML2\Assertion\Validation\SubjectConfirmationConstraintValidator;
12
use SimpleSAML\SAML2\Utils;
13
use SimpleSAML\SAML2\XML\saml\SubjectConfirmation;
14
15
class SubjectConfirmationNotBefore implements SubjectConfirmationConstraintValidator
16
{
17
    /** @var \Beste\Clock */
18
    private static Clock $clock;
19
20
21
    /**
22
     */
23
    public function __construct()
24
    {
25
        self::$clock = Utils::getContainer()->getClock();
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(
36
        SubjectConfirmation $subjectConfirmation,
37
        Result $result,
38
    ): void {
39
        $data = $subjectConfirmation->getSubjectConfirmationData();
40
        Assert::notNull($data);
41
42
        /** @psalm-suppress PossiblyNullReference */
43
        $notBefore = $data->getNotBefore();
44
        $currentTime = self::$clock->now();
45
        if ($notBefore !== null && $notBefore > ($currentTime->add(new DateInterval('PT60S')))) {
46
            $result->addError('NotBefore in SubjectConfirmationData is in the future');
47
        }
48
    }
49
}
50