cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Problem with ACL inheriting (Gentoo, PHP-FPM 5.4)

Open alexzaporozhets opened this issue 13 years ago • 7 comments

Phalcon\Acl\Exception: Role 'Guests' does not exist in the role list File=/home/site/stage/_config.php Line=46 #0 [internal function]: Phalcon\Acl\Adapter\Memory->addInherit('Administrators', Object(Phalcon\Acl\Role)) #1 /home/site/stage/_config.php(46): Phalcon\Acl\Adapter\Memory->addRole(Object(Phalcon\Acl\Role), Object(Phalcon\Acl\Role)) #2 /home/site/stage/_loader.php(63): require_once('/home/site/stag...') #3 /home/site/stage/index.php(9): require_once('/home/site/stag...') #4 {main}

$acl = new Phalcon\Acl\Adapter\Memory();
// disallow all resources by default
$acl->setDefaultAction(Phalcon\Acl::DENY);

try {
    // Create some roles
    $roleAdmins = new \Phalcon\Acl\Role("Administrators", "Super-User role");
    $roleGuests = new \Phalcon\Acl\Role("Guests");

    // Add "Guests" role to acl
    $acl->addRole($roleGuests);

    // Add "Administrators" role inheriting from "Guests" its accesses
    $acl->addRole($roleAdmins, $roleGuests);
} catch (\Phalcon\Exception $e) {
    echo get_class($e), ": ", $e->getMessage(), "\n";
    echo " File=", $e->getFile(), "\n";
    echo " Line=", $e->getLine(), "\n";
    echo $e->getTraceAsString();
}

alexzaporozhets avatar Feb 28 '13 10:02 alexzaporozhets

This line must be:

$acl->addRole($roleAdmins, "Guests");

The object-syntax is now supported in 1.0.0

ghost avatar Mar 05 '13 11:03 ghost

Ok, but how I can do inheriting from multiple roles? It did not work properly in 0.9.1

alexzaporozhets avatar Mar 05 '13 11:03 alexzaporozhets

You could call:

$acl->addRole($roleAdmins, "Guests1");
$acl->addRole($roleAdmins, "Guests2");

ghost avatar Mar 05 '13 11:03 ghost

I tried on latest versions 1.0, roles-inheriting does not work:

setDefaultAction(Phalcon\Acl::DENY); try { // Create some roles $roleAdmins = new \Phalcon\Acl\Role("Administrators", "Super-User role"); $roleManager = new \Phalcon\Acl\Role("Manager"); $roleGuests = new \Phalcon\Acl\Role("Guests"); ``` $acl->addRole($roleGuests); $acl->addRole($roleManager); // Add "Administrators" role inheriting from "Guests" its accesses $acl->addRole($roleManager, "Guests"); $acl->addRole($roleAdmins, "Manager"); $acl->addResource(new Phalcon\Acl\Resource('main'), ['view', 'moderator']); // allow resource for Guests $acl->allow("Guests", 'main', 'view'); echo " Guests: " . $acl->isAllowed("Guests", 'main', 'view'); echo " Manager: " . $acl->isAllowed("Manager", 'main', 'view'); echo " Administrators: " . $acl->isAllowed("Administrators", 'main', 'view'); ``` } catch (\Phalcon\Exception $e) { echo get_class($e), ": ", $e->getMessage(), "\n"; echo " File=", $e->getFile(), "\n"; echo " Line=", $e->getLine(), "\n"; echo $e->getTraceAsString(); } ... Guests: 1 Manager: 0 Administrators: 0

alexzaporozhets avatar Mar 07 '13 12:03 alexzaporozhets

The same problem. Check forum discussion please: http://forum.phalconphp.com/discussion/103/acl-roles-inheritance

iforp avatar Mar 07 '13 13:03 iforp

Is any news about this bug?

alexzaporozhets avatar Mar 13 '13 14:03 alexzaporozhets

This is fixed in the 1.0.0 branch

ghost avatar Mar 13 '13 23:03 ghost