BasicRestfulAuthenticator::authenticate()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 4
nop 0
dl 0
loc 22
rs 9.5222
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\RestfulServer;
4
5
use SilverStripe\Security\Authenticator;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Security\Security;
8
9
/**
10
 * A simple authenticator for the Restful server.
11
 *
12
 * This allows users to be authenticated against that RestfulServer using their
13
 * login details, however they will be passed 'in the open' and will require the
14
 * application accessing the RestfulServer to store logins in plain text (or in
15
 * decrytable form)
16
 */
17
class BasicRestfulAuthenticator
18
{
19
    /**
20
     * The authenticate function
21
     *
22
     * Takes the basic auth details and attempts to log a user in from the DB
23
     *
24
     * @return Member|false The Member object, or false if no member
0 ignored issues
show
Bug introduced by
The type SilverStripe\RestfulServer\Member was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
     */
26
    public static function authenticate()
27
    {
28
        //if there is no username or password, fail
29
        if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
30
            return null;
31
        }
32
33
        // With a valid user and password, check the password is correct
34
        $data = [
35
            'Email' => $_SERVER['PHP_AUTH_USER'],
36
            'Password' => $_SERVER['PHP_AUTH_PW'],
37
        ];
38
        $request = Controller::curr()->getRequest();
39
        $authenticators = Security::singleton()->getApplicableAuthenticators(Authenticator::LOGIN);
40
        $member = null;
41
        foreach ($authenticators as $authenticator) {
42
            $member = $authenticator->authenticate($data, $request);
43
            if ($member) {
44
                break;
45
            }
46
        }
47
        return $member;
48
    }
49
}
50