Skip to content

Commit f2ed910

Browse files
authored
Merge pull request #734 from Erwane/729-v3-authorization-fail
#729 v3 authorization fail
2 parents beb1f55 + 19b6cd0 commit f2ed910

File tree

11 files changed

+169
-97
lines changed

11 files changed

+169
-97
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"jdorn/sql-formatter": "^1.2.0"
3232
},
3333
"require-dev": {
34+
"cakephp/authorization": "^1.3.2",
3435
"cakephp/cakephp-codesniffer": "^3.0",
3536
"phpunit/phpunit": "^5.7.14|^6.0"
3637
},

docs/en/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ Configuration
4444
// Allow e.g. http://foo.bar.dev or http://my-shop.local domains locally
4545
Configure::write('DebugKit.safeTld', ['dev', 'local', 'example']);
4646

47-
* ``DebugKit.forceEnable`` - Force DebugKit to display. Careful with this, it is usually
47+
* ``DebugKit.forceEnable`` - Force DebugKit to display. Careful with this, it is usually
4848
safer to simply whitelist your local TLDs. Example usage::
4949

5050
// Before loading DebugKit
5151
Configure::write('DebugKit.forceEnable', true);
5252

53+
* ``DebugKit.ignoreAuthorization`` - Set to true to ignore Cake Authorization plugin for DebugKit requests. Disabled by default.
54+
5355
Database Configuration
5456
----------------------
5557

@@ -77,7 +79,7 @@ connection in your **config/app.php** file. For example::
7779
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
7880
],
7981

80-
You can safely remove the **tmp/debug_kit.sqlite** file at any point.
82+
You can safely remove the **tmp/debug_kit.sqlite** file at any point.
8183
DebugKit will regenerate it when necessary.
8284

8385
Toolbar Usage

docs/fr/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Ensuite, vous devez activer le plugin en exécutant la ligne suivante::
3030

3131
bin/cake plugin load DebugKit
3232

33+
Configuration
34+
=============
35+
36+
* ``DebugKit.ignoreAuthorization`` - Définie à true pour ignorer le plugin Cake Authorization uniquement pour les requêtes DebugKit. Par défaut à false.
37+
3338
Stockage de DebugKit
3439
====================
3540

src/Controller/ComposerController.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
*/
1414
namespace DebugKit\Controller;
1515

16-
use Cake\Controller\Controller;
17-
use Cake\Core\Configure;
18-
use Cake\Event\Event;
19-
use Cake\Http\Exception\NotFoundException;
2016
use Cake\View\JsonView;
2117
use Composer\Console\Application;
2218
use Symfony\Component\Console\Input\ArrayInput;
@@ -25,9 +21,8 @@
2521
/**
2622
* Provides utility features need by the toolbar.
2723
*/
28-
class ComposerController extends Controller
24+
class ComposerController extends DebugKitController
2925
{
30-
3126
/**
3227
* {@inheritDoc}
3328
*/
@@ -38,20 +33,6 @@ public function initialize()
3833
$this->viewBuilder()->setClassName(JsonView::class);
3934
}
4035

41-
/**
42-
* Before filter handler.
43-
*
44-
* @param \Cake\Event\Event $event The event.
45-
* @return void
46-
* @throws \Cake\Http\Exception\NotFoundException
47-
*/
48-
public function beforeFilter(Event $event)
49-
{
50-
if (!Configure::read('debug')) {
51-
throw new NotFoundException();
52-
}
53-
}
54-
5536
/**
5637
* Check outdated composer dependencies
5738
*

src/Controller/DashboardController.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,22 @@
1212
*/
1313
namespace DebugKit\Controller;
1414

15-
use Cake\Controller\Controller;
16-
use Cake\Core\Configure;
1715
use Cake\Event\Event;
18-
use Cake\Http\Exception\NotFoundException;
1916

2017
/**
2118
* Dashboard and common DebugKit backend.
2219
*/
23-
class DashboardController extends Controller
20+
class DashboardController extends DebugKitController
2421
{
2522
/**
2623
* Before filter handler.
2724
*
2825
* @param \Cake\Event\Event $event The event.
2926
* @return void
30-
* @throws \Cake\Http\Exception\NotFoundException
3127
*/
3228
public function beforeFilter(Event $event)
3329
{
34-
// TODO add config override.
35-
if (!Configure::read('debug')) {
36-
throw new NotFoundException('Not available without debug mode on.');
37-
}
30+
parent::beforeFilter($event);
3831

3932
$this->viewBuilder()->setLayout('dashboard');
4033
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* Redistributions of files must retain the above copyright notice.
8+
*
9+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
10+
* @link http://cakephp.org CakePHP(tm) Project
11+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
12+
*/
13+
namespace DebugKit\Controller;
14+
15+
use Cake\Controller\Controller;
16+
use Cake\Core\Configure;
17+
use Cake\Event\Event;
18+
use Cake\Http\Exception\NotFoundException;
19+
use Cake\Log\Log;
20+
21+
/**
22+
* DebugKit Controller.
23+
*/
24+
class DebugKitController extends Controller
25+
{
26+
/**
27+
* Before filter handler.
28+
*
29+
* @param \Cake\Event\Event $event The event.
30+
* @return void
31+
* @throws \Cake\Http\Exception\NotFoundException
32+
*/
33+
public function beforeFilter(Event $event)
34+
{
35+
if (!Configure::read('debug')) {
36+
throw new NotFoundException('Not available without debug mode on.');
37+
}
38+
39+
// If CakePHP Authorization\Authorization plugin is enabled,
40+
// ignore it, only if `DebugKit.ignoreAuthorization` is set to true
41+
$authorizationService = $this->getRequest()->getAttribute('authorization');
42+
if ($authorizationService instanceof \Authorization\AuthorizationService) {
43+
if (Configure::read('DebugKit.ignoreAuthorization')) {
44+
$authorizationService->skipAuthorization();
45+
} else {
46+
Log::info(
47+
"Cake Authorization plugin is enabled. If you would like " .
48+
"to force DebugKit to ignore it, set `DebugKit.ignoreAuthorization` " .
49+
" Configure option to true."
50+
);
51+
}
52+
}
53+
}
54+
}

src/Controller/MailPreviewController.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
namespace DebugKit\Controller;
1515

1616
use Cake\Collection\CollectionInterface;
17-
use Cake\Controller\Controller;
1817
use Cake\Core\App;
19-
use Cake\Core\Configure;
2018
use Cake\Core\Plugin as CorePlugin;
2119
use Cake\Event\Event;
2220
use Cake\Http\Exception\NotFoundException;
@@ -33,22 +31,8 @@
3331
*
3432
* @property \DebugKit\Model\Table\PanelsTable $Panels
3533
*/
36-
class MailPreviewController extends Controller
34+
class MailPreviewController extends DebugKitController
3735
{
38-
/**
39-
* Before filter callback.
40-
*
41-
* @param \Cake\Event\Event $event The beforeFilter event.
42-
* @return void
43-
* @throws \Cake\Http\Exception\NotFoundException
44-
*/
45-
public function beforeFilter(Event $event)
46-
{
47-
if (!Configure::read('debug')) {
48-
throw new NotFoundException();
49-
}
50-
}
51-
5236
/**
5337
* Before render handler.
5438
*

src/Controller/PanelsController.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
*/
1313
namespace DebugKit\Controller;
1414

15-
use Cake\Controller\Controller;
16-
use Cake\Core\Configure;
1715
use Cake\Event\Event;
1816
use Cake\Http\Exception\NotFoundException;
1917

@@ -22,31 +20,15 @@
2220
*
2321
* @property \DebugKit\Model\Table\PanelsTable $Panels
2422
*/
25-
class PanelsController extends Controller
23+
class PanelsController extends DebugKitController
2624
{
27-
2825
/**
2926
* components
3027
*
3128
* @var array
3229
*/
3330
public $components = ['RequestHandler', 'Cookie'];
3431

35-
/**
36-
* Before filter handler.
37-
*
38-
* @param \Cake\Event\Event $event The event.
39-
* @return void
40-
* @throws \Cake\Http\Exception\NotFoundException
41-
*/
42-
public function beforeFilter(Event $event)
43-
{
44-
// TODO add config override.
45-
if (!Configure::read('debug')) {
46-
throw new NotFoundException();
47-
}
48-
}
49-
5032
/**
5133
* Before render handler.
5234
*

src/Controller/RequestsController.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,24 @@
1212
*/
1313
namespace DebugKit\Controller;
1414

15-
use Cake\Controller\Controller;
16-
use Cake\Core\Configure;
1715
use Cake\Event\Event;
18-
use Cake\Http\Exception\NotFoundException;
1916

2017
/**
2118
* Provides access to panel data.
2219
*
2320
* @property \DebugKit\Model\Table\RequestsTable $Requests
2421
*/
25-
class RequestsController extends Controller
22+
class RequestsController extends DebugKitController
2623
{
27-
2824
/**
2925
* Before filter handler.
3026
*
3127
* @param \Cake\Event\Event $event The event.
3228
* @return void
33-
* @throws \Cake\Http\Exception\NotFoundException
3429
*/
3530
public function beforeFilter(Event $event)
3631
{
37-
// TODO add config override
38-
if (!Configure::read('debug')) {
39-
throw new NotFoundException();
40-
}
32+
parent::beforeFilter($event);
4133

4234
$this->response = $this->response->withHeader('Content-Security-Policy', '');
4335
}

src/Controller/ToolbarController.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313
namespace DebugKit\Controller;
1414

1515
use Cake\Cache\Cache;
16-
use Cake\Controller\Controller;
17-
use Cake\Core\Configure;
18-
use Cake\Event\Event;
1916
use Cake\Http\Exception\NotFoundException;
2017

2118
/**
2219
* Provides utility features need by the toolbar.
2320
*/
24-
class ToolbarController extends Controller
21+
class ToolbarController extends DebugKitController
2522
{
26-
2723
/**
2824
* components
2925
*
@@ -38,21 +34,6 @@ class ToolbarController extends Controller
3834
*/
3935
public $viewClass = 'Cake\View\JsonView';
4036

41-
/**
42-
* Before filter handler.
43-
*
44-
* @param \Cake\Event\Event $event The event.
45-
* @return void
46-
* @throws \Cake\Http\Exception\NotFoundException
47-
*/
48-
public function beforeFilter(Event $event)
49-
{
50-
// TODO add config override.
51-
if (!Configure::read('debug')) {
52-
throw new NotFoundException();
53-
}
54-
}
55-
5637
/**
5738
* Clear a named cache.
5839
*

0 commit comments

Comments
 (0)