GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BasicAuthenticationHook::executeBefore()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 15
nc 4
nop 2
1
<?php
2
3
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Common\Http;
11
12
use SURFnet\VPN\Common\Http\Exception\HttpException;
13
14
class BasicAuthenticationHook implements BeforeHookInterface
15
{
16
    /** @var array */
17
    private $userPass;
18
19
    /** @var string */
20
    private $realm;
21
22
    public function __construct(array $userPass, $realm = 'Protected Area')
23
    {
24
        $this->userPass = $userPass;
25
        $this->realm = $realm;
26
    }
27
28
    public function executeBefore(Request $request, array $hookData)
29
    {
30
        $authUser = $request->getHeader('PHP_AUTH_USER', false);
31
        $authPass = $request->getHeader('PHP_AUTH_PW', false);
32
        if (is_null($authUser) || is_null($authPass)) {
33
            throw new HttpException(
34
                'missing authentication information',
35
                401,
36
                ['WWW-Authenticate' => sprintf('Basic realm="%s"', $this->realm)]
37
            );
38
        }
39
40
        if (array_key_exists($authUser, $this->userPass)) {
41
            if (0 === \Sodium\compare($authPass, $this->userPass[$authUser])) {
42
                return $authUser;
43
            }
44
        }
45
46
        throw new HttpException(
47
            'invalid authentication information',
48
            401,
49
            ['WWW-Authenticate' => sprintf('Basic realm="%s"', $this->realm)]
50
        );
51
    }
52
}
53