BasicAuthentication::authRequestTimeout()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace kalanis\Restful\Security\Process;
4
5
6
use kalanis\Restful\Http\IInput;
7
use kalanis\Restful\Security\Exceptions\AuthenticationException;
8
use kalanis\Restful\Security\Exceptions\RequestTimeoutException;
9
use Nette\Security\User;
10
11
12
/**
13
 * BasicAuthentication
14
 * @package kalanis\Restful\Security\Process
15
 */
16
class BasicAuthentication extends AuthenticationProcess
17
{
18
19
    public function __construct(
20
        private readonly User $user,
21
    )
22
    {
23
    }
24
25
    /**
26
     * Authenticate request data
27
     */
28
    protected function authRequestData(IInput $input): bool
29
    {
30
        if (!$this->user->isLoggedIn()) {
31
            throw new AuthenticationException('User not logged in');
32
        }
33
        return true;
34
    }
35
36
    /**
37
     * Authenticate request timeout
38
     * @throws RequestTimeoutException
39
     */
40
    protected function authRequestTimeout(IInput $input): bool
41
    {
42
        if (User::LogoutInactivity === $this->user->getLogoutReason()) {
43
            throw new RequestTimeoutException('User session expired');
44
        }
45
        return true;
46
    }
47
}
48