I need an ACL for my application layer and I've been looking into Zend ACL which seems to cover my needs but I'm confused by the following [1]:
For example, if a default rule is to be applied to each building in a city, one would simply assign the rule to the city, instead of assigning the same rule to each building. Some buildings may require exceptions to such a rule, however, and this can be achieved in
Zend\Permissions\Acl\Aclby assigning such exception rules to each building that requires such an exception.
This is great. Exactly what I need. However, how do I accomplish this?
From reading through the documentation for Zend ACL, I can't actually find an example of this. So, lets say I have a City and Building resource and each implements the ResourceInterface. Something like this:
class City implements ResourceInterface {
public function getResourceId()
{
return "city"; // Is this supposed to be the "type" or the "unique Id"?
}
public $buildings = array();
}
class Building implements ResourceInterface {
public function getResourceId()
{
return "building"; // Again, the "type" or "unique Id"?
}
}
As the comments in the code above might already make clear, what is the resource Id? does it represent the "type" of the resource, i.e. this is a City or Building, or does it require to be a unique Id, i.e. "city-1", etc?
If the answer is that it needs to be the "type" then the question becomes; how do I specify unique buildings? However, if the answer is that the Id needs to be unique then the question becomes; how do I identify the "type" of the resource and "blanket" permission each building as stated in the quote taken from the documentation.
Any insight would be much appreciated.
[1] http://zf2.readthedocs.org/en/latest/modules/zend.permissions.acl.intro.html
the
resource Idneeds to be a unique value. and for assigning global rules you need to use inheritance for the resources . simple you need to pass thecityresource as the parent for thebuildingresource when you adding resources to the acl.here is a sample :
the child resource
buldinginherits the rules from parentcityif none is defined for it.UPDATE for comment :
ACL doesn't know and doesn't care what resource type you have as long as they have unique resource ids, acl threats all resources as equal and only looks for
resourceIdand inheritance.when you defining the rules you only need to provide the
resourceIdfor theallowanddeny, it doesn't matter what type they are as long as they are defined as a resource and added to the ACL's stack.and when you doing
$acl->inAllowedyou only need aroleIdandresourceIdand again acl doesn't care about their type , only that they have been defined as a resource abd that they have parent or not...Sample : i hope this is enough sample