CAuthManager
CAuthManager is the base class for authorization manager classes.
CAuthManager extends
CApplicationComponent and implements some methods
that are common among authorization manager classes.
CAuthManager together with its concrete child classes implement the Role-Based
Access Control (RBAC).
The main idea is that permissions are organized as a hierarchy of
authorization items. Items on higer level inherit the permissions
represented by items on lower level. And roles are simply top-level authorization items
that may be assigned to individual users. A user is said to have a permission
to do something if the corresponding authorization item is inherited by one of his roles.
Using authorization manager consists of two aspects. First, the authorization hierarchy
and assignments have to be established. CAuthManager and its child classes
provides APIs to accomplish this task. Developers may need to develop some GUI
so that it is more intuitive to end-users. Second, developers call
IAuthManager::checkAccess
at appropriate places in the application code to check if the current user
has the needed permission for an operation.
Property Details
public array $defaultRoles;
list of role names that are assigned to all users implicitly.
These roles do not need to be explicitly assigned to any user.
When calling checkAccess, these roles will be checked first.
For performance reason, you should minimize the number of such roles.
A typical usage of such roles is to define an 'authenticated' role and associate
it with a biz rule which checks if the current user is authenticated.
And then declare 'authenticated' in this property so that it can be applied to
every authenticated user.
Returns operations.
This is a shortcut method to IAuthManager::getAuthItems.
public array
getRoles(mixed $userId=NULL)
Returns roles.
This is a shortcut method to IAuthManager::getAuthItems.
public boolean $showErrors;
Enable error reporting for bizRules.
public array
getTasks(mixed $userId=NULL)
Returns tasks.
This is a shortcut method to IAuthManager::getAuthItems.
Method Details
|
protected void checkItemChildType(integer $parentType, integer $childType)
|
| $parentType |
integer |
parent item type |
| $childType |
integer |
child item type |
Checks the item types to make sure a child can be added to a parent.
|
public void createOperation(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
|
| $name |
string |
the item name |
| $description |
string |
the item description. |
| $bizRule |
string |
the business rule associated with this item |
| $data |
mixed |
additional data to be passed when evaluating the business rule |
Creates an operation.
This is a shortcut method to IAuthManager::createAuthItem.
|
public void createRole(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
|
| $name |
string |
the item name |
| $description |
string |
the item description. |
| $bizRule |
string |
the business rule associated with this item |
| $data |
mixed |
additional data to be passed when evaluating the business rule |
Creates a role.
This is a shortcut method to IAuthManager::createAuthItem.
|
public void createTask(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
|
| $name |
string |
the item name |
| $description |
string |
the item description. |
| $bizRule |
string |
the business rule associated with this item |
| $data |
mixed |
additional data to be passed when evaluating the business rule |
Creates a task.
This is a shortcut method to IAuthManager::createAuthItem.
|
public boolean executeBizRule(string $bizRule, array $params, mixed $data)
|
| $bizRule |
string |
the business rule to be executed. |
| $params |
array |
parameters passed to IAuthManager::checkAccess. |
| $data |
mixed |
additional data associated with the authorization item or assignment. |
| {return} |
boolean |
whether the business rule returns true.
If the business rule is empty, it will still return true. |
Executes the specified business rule.
|
public array getOperations(mixed $userId=NULL)
|
| $userId |
mixed |
the user ID. If not null, only the operations directly assigned to the user
will be returned. Otherwise, all operations will be returned. |
| {return} |
array |
operations (name=>CAuthItem) |
Returns operations.
This is a shortcut method to IAuthManager::getAuthItems.
|
public array getRoles(mixed $userId=NULL)
|
| $userId |
mixed |
the user ID. If not null, only the roles directly assigned to the user
will be returned. Otherwise, all roles will be returned. |
| {return} |
array |
roles (name=>CAuthItem) |
Returns roles.
This is a shortcut method to IAuthManager::getAuthItems.
|
public array getTasks(mixed $userId=NULL)
|
| $userId |
mixed |
the user ID. If not null, only the tasks directly assigned to the user
will be returned. Otherwise, all tasks will be returned. |
| {return} |
array |
tasks (name=>CAuthItem) |
Returns tasks.
This is a shortcut method to IAuthManager::getAuthItems.