Skip to content

Commit

Permalink
The allow option now replaces the rules option. true (default) lets t…
Browse files Browse the repository at this point in the history
…he request go though, false prevents the request and an array of closures is passed to _parseClosures for evaluation
  • Loading branch information
Richard Vanbergen committed May 26, 2011
1 parent a868ce0 commit 0714cc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions extensions/adapter/security/access/AuthRbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class AuthRbac extends \lithium\core\Object {

/**
* The `Rbac` adapter will iterate trough the rbac data Array.
* @todo: Implement file based data access
* @todo: Shorter $match syntax
*
* @param mixed $user The user data array that holds all necessary information about
* the user requesting access. Or false (because Auth::check() can return false).
Expand Down Expand Up @@ -51,12 +49,12 @@ public function check($user, $request, array $options = array()) {
$accessGranted = $match;

$requesters = isset($role['requesters']) ? $role['requesters'] : '*';
$allow = isset($role['allow']) ? (boolean) $role['allow'] : true;
$allow = isset($role['allow']) ? $role['allow'] : true;
$diff = array_diff((array) $requesters, array_keys($authedRoles));

if ((!$allow) ||
if (($allow === false) ||
(count($diff) === count($authedRoles)) ||
(!empty($role['rules']) && !static::_parseClosures($role['rules'], $request))
(is_array($allow) && !static::_parseClosures($allow, $request))
) {
$accessGranted = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setUp() {
'roles' => array(
array(
'requesters' => 'user',
'rules' => array(function($request) {
'allow' => array(function($request) {
return $request->params['success'] ? true : false;
}),
'match' => array(
Expand Down

0 comments on commit 0714cc6

Please sign in to comment.