Skip to content

Commit

Permalink
Merge pull request #258 from CakeDC/issue/rbac-negative-rules-30
Browse files Browse the repository at this point in the history
fix bug on rule calculation when negative rules matched
  • Loading branch information
steinkel committed Oct 15, 2015
2 parents f8e4cef + 5533ca7 commit 3ce3872
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Auth/SimpleRbacAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ protected function _checkRules(array $user, $role, Request $request)
{
$permissions = $this->config('permissions');
foreach ($permissions as $permission) {
if ($allowed = $this->_matchRule($permission, $user, $role, $request)) {
$allowed = $this->_matchRule($permission, $user, $role, $request);
if ($allowed !== null) {
return $allowed;
}
}
Expand All @@ -189,7 +190,7 @@ protected function _checkRules(array $user, $role, Request $request)
* @param array $user current user
* @param string $role effective user role
* @param Request $request request
* @return bool
* @return bool if rule matched, null if rule not matched
*/
protected function _matchRule($permission, $user, $role, $request)
{
Expand All @@ -216,7 +217,7 @@ protected function _matchRule($permission, $user, $role, $request)
}
}

return false;
return null;
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/TestCase/Auth/SimpleRbacAuthorizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,38 @@ public function providerAuthorize()
//expected
true
],
'array-prefix' => [
//permissions
[
[
'role' => ['test'],
'prefix' => ['one', 'admin'],
'controller' => '*',
'action' => 'one',
'allowed' => false,
],
[
'role' => ['test'],
'prefix' => ['one', 'admin'],
'controller' => '*',
'action' => '*',
],
],
//user
[
'id' => 1,
'username' => 'luke',
'role' => 'test',
],
//request
[
'prefix' => 'admin',
'controller' => 'Tests',
'action' => 'one'
],
//expected
false
],
];
}
}

0 comments on commit 3ce3872

Please sign in to comment.