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

NotOnOrAfter::__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\SAML2\Assertion\Validation\AssertionConstraintValidator;
10
use SimpleSAML\SAML2\Assertion\Validation\Result;
11
use SimpleSAML\SAML2\Utils;
12
use SimpleSAML\SAML2\XML\saml\Assertion;
13
14
class NotOnOrAfter implements AssertionConstraintValidator
15
{
16
    /** @var \Beste\Clock */
17
    private static Clock $clock;
18
19
20
    /**
21
     */
22
    public function __construct()
23
    {
24
        self::$clock = Utils::getContainer()->getClock();
25
    }
26
27
28
    /**
29
     * @param \SimpleSAML\SAML2\XML\saml\Assertion $assertion
30
     * @param \SimpleSAML\SAML2\Assertion\Validation\Result $result
31
     */
32
    public function validate(Assertion $assertion, Result $result): void
33
    {
34
        $conditions = $assertion->getConditions();
35
        if ($conditions !== null) {
36
            $notValidOnOrAfterTimestamp = $conditions->getNotOnOrAfter();
37
            $currentTime = self::$clock->now();
38
            if (($notValidOnOrAfterTimestamp !== null) && ($notValidOnOrAfterTimestamp <= ($currentTime->sub(new DateInterval('PT60S'))))) {
39
                $result->addError(
40
                    'Received an assertion that has expired. Check clock synchronization on IdP and SP.',
41
                );
42
            }
43
        }
44
    }
45
}
46