Passed
Push — main ( 04a742...5b603f )
by
unknown
04:37 queued 12s
created

__getWWWAuthenticateString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Aoe\Restler\Controller;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2021 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use Aoe\Restler\System\TYPO3\Loader;
30
use Luracast\Restler\iAuthenticate;
31
use Luracast\Restler\Restler;
32
use Luracast\Restler\Scope;
33
34
/**
35
 * This class checks, if client is allowed to access the requested and protected API-class
36
 * This class checks, if BE-user is logged in
37
 */
38
class BeUserAuthenticationController implements iAuthenticate
39
{
40
    /**
41
     * This property defines (when it's set), that this controller should check authentication
42
     * This property will be automatically set by restler, when in the API-class/controller this
43
     * is configured (in PHPdoc/annotations)
44
     *
45
     * Where do we set this property?
46
     * When the property should be used, than it must be set inside the PHPdoc-comment of the API-class-method,
47
     * which handle the API-request
48
     *
49
     * Syntax:
50
     * The PHPdoc-comment must look like this:
51
     * @class [className] {@[propertyName] [propertyValue]}
52
     *
53
     * Example:
54
     * When this controller should be used for authentication-checks, than the PHPdoc-comment must look like this:
55
     * @class Aoe\Restler\Controller\BeUserAuthenticationController {@checkAuthentication true}
56
     */
57
    public bool $checkAuthentication = false;
58
59
    /**
60
     * Instance of Restler class injected at runtime.
61
     *
62
     * @var Restler
63
     */
64
    public $restler;
65
66
    private Loader $typo3Loader;
67
68 4
    public function __construct(Loader $typo3Loader)
69
    {
70 4
        $this->typo3Loader = $typo3Loader;
71 4
        $this->restler = Scope::get('Restler');
72 4
    }
73
74
    /**
75
     * This method checks, if client is allowed to access the requested API-class
76
     *
77
     * @return boolean
78
     */
79
    // phpcs:ignore
80 3
    public function __isAllowed()
81
    {
82 3
        if (!$this->checkAuthentication) {
83
            // this controller is not responsible for the authentication
84 1
            return false;
85
        }
86
87 2
        $this->typo3Loader->initializeBackendUser();
88
89 2
        return $this->typo3Loader->hasActiveBackendUser();
90
    }
91
92
    /**
93
     * return dummy string, because we DON'T need that for our case (we use NO base-authentification via REST-API)
94
     *
95
     * @return string
96
     * @see \Luracast\Restler\iAuthenticate
97
     */
98
    // phpcs:ignore
99 1
    public function __getWWWAuthenticateString()
100
    {
101 1
        return '';
102
    }
103
}
104