Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-30-2008, 12:53 PM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default Help with Zend_Acl

Hey guys,

Using Zend_Acl and I have run into a little problem.

Firstly I will just show you the output of my debugging code:

Code:
Add role: guest with parent:
Add role: member with parent:
Add role: administrator with parent: member

Add resource: admin with parent:
Add resource: user with parent:

Allow to Role: for Resource: with Exceptions:
Deny to Role: for Resource: user with Exceptions:
Deny to Role: for Resource: admin with Exceptions:
Allow to Role: guest for Resource: user with Exceptions: login, fetchpassword, register
Allow to Role: administrator for Resource: admin with Exceptions:
Allow to Role: member for Resource: user with Exceptions:

Administrator denied to admin
And the code itself:
PHP Code:
        foreach($roles as $role){
            
$ret[] = sprintf('Add role: %s with parent: %s'$role['name'], $role['parent']);
            
$this->acl->addRole(new Zend_Acl_Role($role['name']), $role['parent']);
        }
        
        
$ret[] = ' ';
        
        foreach(
$res as $resource){
            
$ret[] = sprintf('Add resource: %s with parent: %s'$resource['name'], $resource['parent']);
            
$this->acl->add(new Zend_Acl_Resource($resource['name']), $resource['parent']);
        }
        
        
$ret[] = ' ';
        
        foreach(
$allow_deny as $action){
            
$string '%s to Role: %s for Resource: %s with Exceptions: %s';
            if(
$action['access'] == 1){
                
$ret[] = sprintf($string'Allow'$action['role'], $action['resource'], $action['extra']);
                
$this->acl->allow($action['role'], $action['resource'], $this->convertCSV($action['extra']));
            }else{
                
$ret[] = sprintf($string'Deny'$action['role'], $action['resource'], $action['extra']);
                
$this->acl->deny($action['role'], $action['resource'], $this->convertCSV($action['extra']));
            }
        }
        
        
$ret[] = ' ';
        
        if(
$this->acl->isAllowed('administrator''admin')){
            
$ret[] = '<b>administrator allowed to admin</b>';
        }else{
            
$ret[] = '<b>administrator denied to admin</b>';
        }
        
        die(
implode('<br />'$ret)); 

In the $allow_deny loop, the 'access' key is 1 for allow and 0 for deny. Roles, Resources and Allow/Deny is all loaded from a database.
The method covertCSV() simply converts a comma-seprarate values string into and array. It explodes by ', '.

So my quest is, why isn't admin allow (see the bold)? It also happens with other variations as well.

Cheers,
Cobby
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-31-2008, 07:17 AM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default Fixed! =)

Found the problem:

PHP Code:
protected function convertCSV($csv){
    return 
explode(', '$csv);

This was causing the error, it should be:
PHP Code:
protected function convertCSV($csv){
    if(
strlen($csv) == 0){
        return 
null;
    }
    return 
explode(', '$csv);

Cheers,
Cobby
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:14 AM.