Skip to content

Commit

Permalink
Merge pull request #734 from Erwane/729-v3-authorization-fail
Browse files Browse the repository at this point in the history
#729 v3 authorization fail
  • Loading branch information
markstory authored Feb 6, 2020
2 parents beb1f55 + 19b6cd0 commit f2ed910
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 97 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"jdorn/sql-formatter": "^1.2.0"
},
"require-dev": {
"cakephp/authorization": "^1.3.2",
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "^5.7.14|^6.0"
},
Expand Down
6 changes: 4 additions & 2 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ Configuration
// Allow e.g. http://foo.bar.dev or http://my-shop.local domains locally
Configure::write('DebugKit.safeTld', ['dev', 'local', 'example']);

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

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

* ``DebugKit.ignoreAuthorization`` - Set to true to ignore Cake Authorization plugin for DebugKit requests. Disabled by default.

Database Configuration
----------------------

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

You can safely remove the **tmp/debug_kit.sqlite** file at any point.
You can safely remove the **tmp/debug_kit.sqlite** file at any point.
DebugKit will regenerate it when necessary.

Toolbar Usage
Expand Down
5 changes: 5 additions & 0 deletions docs/fr/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Ensuite, vous devez activer le plugin en exécutant la ligne suivante::

bin/cake plugin load DebugKit

Configuration
=============

* ``DebugKit.ignoreAuthorization`` - Définie à true pour ignorer le plugin Cake Authorization uniquement pour les requêtes DebugKit. Par défaut à false.

Stockage de DebugKit
====================

Expand Down
21 changes: 1 addition & 20 deletions src/Controller/ComposerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
*/
namespace DebugKit\Controller;

use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;
use Cake\View\JsonView;
use Composer\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -25,9 +21,8 @@
/**
* Provides utility features need by the toolbar.
*/
class ComposerController extends Controller
class ComposerController extends DebugKitController
{

/**
* {@inheritDoc}
*/
Expand All @@ -38,20 +33,6 @@ public function initialize()
$this->viewBuilder()->setClassName(JsonView::class);
}

/**
* Before filter handler.
*
* @param \Cake\Event\Event $event The event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
if (!Configure::read('debug')) {
throw new NotFoundException();
}
}

/**
* Check outdated composer dependencies
*
Expand Down
11 changes: 2 additions & 9 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,22 @@
*/
namespace DebugKit\Controller;

use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;

/**
* Dashboard and common DebugKit backend.
*/
class DashboardController extends Controller
class DashboardController extends DebugKitController
{
/**
* Before filter handler.
*
* @param \Cake\Event\Event $event The event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
// TODO add config override.
if (!Configure::read('debug')) {
throw new NotFoundException('Not available without debug mode on.');
}
parent::beforeFilter($event);

$this->viewBuilder()->setLayout('dashboard');
}
Expand Down
54 changes: 54 additions & 0 deletions src/Controller/DebugKitController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Controller;

use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;
use Cake\Log\Log;

/**
* DebugKit Controller.
*/
class DebugKitController extends Controller
{
/**
* Before filter handler.
*
* @param \Cake\Event\Event $event The event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
if (!Configure::read('debug')) {
throw new NotFoundException('Not available without debug mode on.');
}

// If CakePHP Authorization\Authorization plugin is enabled,
// ignore it, only if `DebugKit.ignoreAuthorization` is set to true
$authorizationService = $this->getRequest()->getAttribute('authorization');
if ($authorizationService instanceof \Authorization\AuthorizationService) {
if (Configure::read('DebugKit.ignoreAuthorization')) {
$authorizationService->skipAuthorization();
} else {
Log::info(
"Cake Authorization plugin is enabled. If you would like " .
"to force DebugKit to ignore it, set `DebugKit.ignoreAuthorization` " .
" Configure option to true."
);
}
}
}
}
18 changes: 1 addition & 17 deletions src/Controller/MailPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
namespace DebugKit\Controller;

use Cake\Collection\CollectionInterface;
use Cake\Controller\Controller;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin as CorePlugin;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;
Expand All @@ -33,22 +31,8 @@
*
* @property \DebugKit\Model\Table\PanelsTable $Panels
*/
class MailPreviewController extends Controller
class MailPreviewController extends DebugKitController
{
/**
* Before filter callback.
*
* @param \Cake\Event\Event $event The beforeFilter event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
if (!Configure::read('debug')) {
throw new NotFoundException();
}
}

/**
* Before render handler.
*
Expand Down
20 changes: 1 addition & 19 deletions src/Controller/PanelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
namespace DebugKit\Controller;

use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;

Expand All @@ -22,31 +20,15 @@
*
* @property \DebugKit\Model\Table\PanelsTable $Panels
*/
class PanelsController extends Controller
class PanelsController extends DebugKitController
{

/**
* components
*
* @var array
*/
public $components = ['RequestHandler', 'Cookie'];

/**
* Before filter handler.
*
* @param \Cake\Event\Event $event The event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
// TODO add config override.
if (!Configure::read('debug')) {
throw new NotFoundException();
}
}

/**
* Before render handler.
*
Expand Down
12 changes: 2 additions & 10 deletions src/Controller/RequestsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,24 @@
*/
namespace DebugKit\Controller;

use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;

/**
* Provides access to panel data.
*
* @property \DebugKit\Model\Table\RequestsTable $Requests
*/
class RequestsController extends Controller
class RequestsController extends DebugKitController
{

/**
* Before filter handler.
*
* @param \Cake\Event\Event $event The event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
// TODO add config override
if (!Configure::read('debug')) {
throw new NotFoundException();
}
parent::beforeFilter($event);

$this->response = $this->response->withHeader('Content-Security-Policy', '');
}
Expand Down
21 changes: 1 addition & 20 deletions src/Controller/ToolbarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
namespace DebugKit\Controller;

use Cake\Cache\Cache;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;

/**
* Provides utility features need by the toolbar.
*/
class ToolbarController extends Controller
class ToolbarController extends DebugKitController
{

/**
* components
*
Expand All @@ -38,21 +34,6 @@ class ToolbarController extends Controller
*/
public $viewClass = 'Cake\View\JsonView';

/**
* Before filter handler.
*
* @param \Cake\Event\Event $event The event.
* @return void
* @throws \Cake\Http\Exception\NotFoundException
*/
public function beforeFilter(Event $event)
{
// TODO add config override.
if (!Configure::read('debug')) {
throw new NotFoundException();
}
}

/**
* Clear a named cache.
*
Expand Down
Loading

0 comments on commit f2ed910

Please sign in to comment.