Passed
Push — main ( 5e2501...644501 )
by Felix
03:02
created

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