From 5246e7dd1da92ae8a2959ff5a0d5349ac47c7f57 Mon Sep 17 00:00:00 2001 From: Daniel Luiz Pakuschewski Date: Wed, 26 Oct 2011 22:07:17 -0200 Subject: [PATCH 1/4] Allow AuthComponent to deny all actions with single deny() or deny('*') --- .../Controller/Component/AuthComponent.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index f099cd3ce..a1dae987f 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -461,16 +461,20 @@ class AuthComponent extends Component { */ public function deny($action = null) { $args = func_get_args(); - if (isset($args[0]) && is_array($args[0])) { - $args = $args[0]; - } - foreach ($args as $arg) { - $i = array_search($arg, $this->allowedActions); - if (is_int($i)) { - unset($this->allowedActions[$i]); + if(empty($args) || $args == array('*')){ + $this->allowedActions = array(); + }else{ + if (isset($args[0]) && is_array($args[0])) { + $args = $args[0]; } + foreach ($args as $arg) { + $i = array_search($arg, $this->allowedActions); + if (is_int($i)) { + unset($this->allowedActions[$i]); + } + } + $this->allowedActions = array_values($this->allowedActions); } - $this->allowedActions = array_values($this->allowedActions); } /** From 8738ef3dc2ad04f54d4fbaaba9f10770773a0b0c Mon Sep 17 00:00:00 2001 From: Daniel Luiz Pakuschewski Date: Wed, 26 Oct 2011 22:07:57 -0200 Subject: [PATCH 2/4] Added tests to deny() and deny('*') --- .../Component/AuthComponentTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index c82aeb347..fa718f11c 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -636,6 +636,25 @@ class AuthComponentTest extends CakeTestCase { $this->Controller->request['action'] = 'camelCase'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->Auth->allow('*'); + $this->Controller->Auth->deny('*'); + + $this->Controller->request['action'] = 'camelCase'; + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->request['action'] = 'add'; + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->Auth->allow('camelCase'); + $this->Controller->Auth->deny(); + + $this->Controller->request['action'] = 'camelCase'; + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->request['action'] = 'login'; + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + } /** From 09579198a94422ea0195f662f52c409e317e2e21 Mon Sep 17 00:00:00 2001 From: Daniel Pakuschewski Date: Sat, 29 Oct 2011 13:54:35 -0200 Subject: [PATCH 3/4] Droped support to deny('*'). --- lib/Cake/Controller/Component/AuthComponent.php | 5 +++-- .../Case/Controller/Component/AuthComponentTest.php | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index a1dae987f..83c6dab1f 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -452,7 +452,8 @@ class AuthComponent extends Component { * You can use deny with either an array, or var args. * * `$this->Auth->deny(array('edit', 'add'));` or - * `$this->Auth->deny('edit', 'add');` + * `$this->Auth->deny('edit', 'add');` or + * `$this->Auth->deny();` to remove all items from the allowed list * * @param mixed $action,... Controller action name or array of actions * @return void @@ -461,7 +462,7 @@ class AuthComponent extends Component { */ public function deny($action = null) { $args = func_get_args(); - if(empty($args) || $args == array('*')){ + if(empty($args)){ $this->allowedActions = array(); }else{ if (isset($args[0]) && is_array($args[0])) { diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index fa718f11c..9bbc0002f 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -638,7 +638,7 @@ class AuthComponentTest extends CakeTestCase { $this->assertFalse($this->Controller->Auth->startup($this->Controller)); $this->Controller->Auth->allow('*'); - $this->Controller->Auth->deny('*'); + $this->Controller->Auth->deny(); $this->Controller->request['action'] = 'camelCase'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); @@ -655,6 +655,15 @@ class AuthComponentTest extends CakeTestCase { $this->Controller->request['action'] = 'login'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + $this->Controller->Auth->allow(); + $this->Controller->Auth->deny('*'); + + $this->Controller->request['action'] = 'camelCase'; + $this->assertTrue($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->request['action'] = 'login'; + $this->assertTrue($this->Controller->Auth->startup($this->Controller)); + } /** From 7cde0b654c6694f133d7f303890702885300c2e1 Mon Sep 17 00:00:00 2001 From: Daniel Pakuschewski Date: Sat, 29 Oct 2011 13:57:04 -0200 Subject: [PATCH 4/4] Removed tests for deny('*') to prevent people get confused with it --- .../Case/Controller/Component/AuthComponentTest.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index 9bbc0002f..4e2aa268a 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -654,16 +654,6 @@ class AuthComponentTest extends CakeTestCase { $this->Controller->request['action'] = 'login'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); - - $this->Controller->Auth->allow(); - $this->Controller->Auth->deny('*'); - - $this->Controller->request['action'] = 'camelCase'; - $this->assertTrue($this->Controller->Auth->startup($this->Controller)); - - $this->Controller->request['action'] = 'login'; - $this->assertTrue($this->Controller->Auth->startup($this->Controller)); - } /**