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

SubjectConfirmationNotBefore   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

2 Methods

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