Skip to content

Commit

Permalink
allow more elaborate regex rules
Browse files Browse the repository at this point in the history
  • Loading branch information
0x20h committed Jan 13, 2012
1 parent b5671eb commit bfaea78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
30 changes: 14 additions & 16 deletions lib/Cake/Controller/Component/Acl/PhpAcl.php
Expand Up @@ -43,9 +43,9 @@ public function __construct() {
);
}
/**
* Phptialize method
*
* @param AclBase $component
* Initialize method
*
* @param AclComponent $Component Component instance
* @return void
*/
public function initialize($Component) {
Expand All @@ -61,12 +61,13 @@ public function initialize($Component) {
$Component->Aro = $this->Aro;
}


public function build($config) {
if ($config instanceOf ConfigReaderInterface) {
$config = $config->read(basename($this->options['config']));
}

/**
* build and setup internal ACL representation
*
* @param array $config configuration array, see docs
* @return void
*/
public function build(array $config) {
if (empty($config['roles'])) {
throw new AclException(__d('cake_dev','"roles" section not found in configuration.'));
}
Expand Down Expand Up @@ -110,14 +111,15 @@ public function deny($aro, $aco, $action = "*") {
}

/**
* No op method, inherit cannot be done with PhpAcl
* No op method
*
* @param string $aro ARO The requesting object identifier.
* @param string $aco ACO The controlled object identifier.
* @param string $action Action (defaults to *)
* @return boolean Success
*/
public function inherit($aro, $aco, $action = "*") {
return false;
}

/**
Expand Down Expand Up @@ -192,7 +194,7 @@ public function __construct(array $rules = array()) {
}

/**
* return path to the requested ACO with allow and deny rules for each level
* return path to the requested ACO with allow and deny rules attached on each level
*
* @return array
*/
Expand All @@ -202,7 +204,7 @@ public function path($aco) {
$level = 0;
$root = $this->tree;
$stack = array(array($root, 0));

while (!empty($stack)) {
list($root, $level) = array_pop($stack);

Expand All @@ -211,10 +213,6 @@ public function path($aco) {
}

foreach ($root as $node => $elements) {
if (strpos($node, '*') === false && $node != $aco[$level]) {
continue;
}

$pattern = '#^'.str_replace(array_keys(self::$modifiers), array_values(self::$modifiers), $node).'$#';

if ($node == $aco[$level] || preg_match($pattern, $aco[$level])) {
Expand Down
4 changes: 1 addition & 3 deletions lib/Cake/Test/test_app/Config/acl.php
Expand Up @@ -59,9 +59,7 @@
'/controllers/invoices/*' => 'Role/accounting',
'/controllers/invoices/edit'=> 'User/db_manager_2',
'/controllers/db/*' => 'Role/database_manager',
'/controllers/*/add' => 'User/stan',
'/controllers/*/edit' => 'User/stan',
'/controllers/*/publish' => 'User/stan',
'/controllers/*/(add|edit|publish)' => 'User/stan',
'/controllers/users/dashboard' => 'Role/default',
// test for case insensitivity
'controllers/Forms/NEW' => 'Role/data_acquirer',
Expand Down

0 comments on commit bfaea78

Please sign in to comment.