class Permission extends Object implements IAuthorizator

Access control list (ACL) functionality and privileges management.

This solution is mostly based on Zend_Acl (c) Zend Technologies USA Inc. (http://www.zend.com), new BSD license

Properties

array read-only $roles
array read-only $resources
mixed read-only $queriedRole
mixed read-only $queriedResource

Methods

addRole($role, $parents = NULL)

Adds a Role to the list. The most recently added parent takes precedence over parents that were previously added.

bool
hasRole($role)

Returns TRUE if the Role exists in the list.

array
getRoles()

Returns all Roles.

array
getRoleParents($role)

Returns existing Role's parents ordered by ascending priority.

bool
roleInheritsFrom($role, $inherit, $onlyParents = FALSE)

Returns TRUE if $role inherits from $inherit. If $onlyParents is TRUE, then $role must inherit directly from $inherit.

removeRole($role)

Removes the Role from the list.

removeAllRoles()

Removes all Roles from the list.

addResource($resource, $parent = NULL)

Adds a Resource having an identifier unique to the list.

bool
hasResource($resource)

Returns TRUE if the Resource exists in the list.

array
getResources()

Returns all Resources.

bool
resourceInheritsFrom($resource, $inherit, $onlyParent = FALSE)

Returns TRUE if $resource inherits from $inherit. If $onlyParents is TRUE, then $resource must inherit directly from $inherit.

removeResource($resource)

Removes a Resource and all of its children.

removeAllResources()

Removes all Resources.

allow($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL, $assertion = NULL)

Allows one or more Roles access to [certain $privileges upon] the specified Resource(s).

deny($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL, $assertion = NULL)

Denies one or more Roles access to [certain $privileges upon] the specified Resource(s).

removeAllow($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL)

Removes "allow" permissions from the list in the context of the given Roles, Resources, and privileges.

removeDeny($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL)

Removes "deny" restrictions from the list in the context of the given Roles, Resources, and privileges.

setRule($toAdd, $type, $roles, $resources, $privileges, $assertion = NULL)

Performs operations on Access Control List rules.

bool
isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL)

Returns TRUE if and only if the Role has access to [certain $privileges upon] the Resource.

mixed
getQueriedRole()

Returns real currently queried Role. Use by assertion.

mixed
getQueriedResource()

Returns real currently queried Resource. Use by assertion.

Details

at line 65
Permission addRole($role, $parents = NULL)

Adds a Role to the list. The most recently added parent takes precedence over parents that were previously added.

Parameters

$role
$parents

Return Value

Permission

Exceptions

InvalidArgumentException
InvalidStateException

at line 100
bool hasRole($role)

Returns TRUE if the Role exists in the list.

Parameters

$role

Return Value

bool

at line 129
array getRoles()

Returns all Roles.

Return Value

array

at line 140
array getRoleParents($role)

Returns existing Role's parents ordered by ascending priority.

Parameters

$role

Return Value

array

at line 156
bool roleInheritsFrom($role, $inherit, $onlyParents = FALSE)

Returns TRUE if $role inherits from $inherit. If $onlyParents is TRUE, then $role must inherit directly from $inherit.

Parameters

$role
$inherit
$onlyParents

Return Value

bool

Exceptions

InvalidStateException

at line 184
Permission removeRole($role)

Removes the Role from the list.

Parameters

$role

Return Value

Permission

Exceptions

InvalidStateException

at line 223
Permission removeAllRoles()

Removes all Roles from the list.

Return Value

Permission

at line 253
Permission addResource($resource, $parent = NULL)

Adds a Resource having an identifier unique to the list.

Parameters

$resource
$parent

Return Value

Permission

Exceptions

InvalidArgumentException
InvalidStateException

at line 280
bool hasResource($resource)

Returns TRUE if the Resource exists in the list.

Parameters

$resource

Return Value

bool

at line 309
array getResources()

Returns all Resources.

Return Value

array

at line 325
bool resourceInheritsFrom($resource, $inherit, $onlyParent = FALSE)

Returns TRUE if $resource inherits from $inherit. If $onlyParents is TRUE, then $resource must inherit directly from $inherit.

Parameters

$resource
$inherit
$onlyParent

Return Value

bool

Exceptions

InvalidStateException

at line 360
Permission removeResource($resource)

Removes a Resource and all of its children.

Parameters

$resource

Return Value

Permission

Exceptions

InvalidStateException

at line 392
Permission removeAllResources()

Removes all Resources.

Return Value

Permission

at line 420
Permission allow($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL, $assertion = NULL)

Allows one or more Roles access to [certain $privileges upon] the specified Resource(s).

If $assertion is provided, then it must return TRUE in order for rule to apply.

Parameters

$roles
$resources
$privileges
$assertion

Return Value

Permission

at line 437
Permission deny($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL, $assertion = NULL)

Denies one or more Roles access to [certain $privileges upon] the specified Resource(s).

If $assertion is provided, then it must return TRUE in order for rule to apply.

Parameters

$roles
$resources
$privileges
$assertion

Return Value

Permission

at line 452
Permission removeAllow($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL)

Removes "allow" permissions from the list in the context of the given Roles, Resources, and privileges.

Parameters

$roles
$resources
$privileges

Return Value

Permission

at line 467
Permission removeDeny($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL)

Removes "deny" restrictions from the list in the context of the given Roles, Resources, and privileges.

Parameters

$roles
$resources
$privileges

Return Value

Permission

at line 485
protected Permission setRule($toAdd, $type, $roles, $resources, $privileges, $assertion = NULL)

Performs operations on Access Control List rules.

Parameters

$toAdd
$type
$roles
$resources
$privileges
$assertion

Return Value

Permission

Exceptions

InvalidStateException

at line 598
bool isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL)

Returns TRUE if and only if the Role has access to [certain $privileges upon] the Resource.

This method checks Role inheritance using a depth-first traversal of the Role list. The highest priority parent (i.e., the parent most recently added) is checked first, and its respective parents are checked similarly before the lower-priority parents of the Role are checked.

Parameters

$role
$resource
$privilege

Return Value

bool

Exceptions

InvalidStateException

at line 654
mixed getQueriedRole()

Returns real currently queried Role. Use by assertion.

Return Value

mixed

at line 664
mixed getQueriedResource()

Returns real currently queried Resource. Use by assertion.

Return Value

mixed