CDbAuthManager
CDbAuthManager represents an authorization manager that stores authorization information in database.
The database connection is specified by
connectionID. And the database schema
should be as described in "framework/web/auth/schema.sql". You may change the names of
the three tables used to store the authorization data by setting
itemTable,
itemChildTable and
assignmentTable.
Property Details
public string $assignmentTable;
the name of the table storing authorization item assignments. Defaults to 'AuthAssignment'.
public array
getAuthItems(integer $type=NULL, mixed $userId=NULL)
Returns the authorization items of the specific type and user.
public string $connectionID;
the ID of the CDbConnection application component. Defaults to 'db'.
The database must have the tables as declared in "framework/web/auth/schema.sql".
the database connection. By default, this is initialized
automatically as the application component whose ID is indicated as connectionID.
the DB connection instance
public string $itemChildTable;
the name of the table storing authorization item hierarchy. Defaults to 'AuthItemChild'.
public string $itemTable;
the name of the table storing authorization items. Defaults to 'AuthItem'.
Method Details
Destructor.
Disconnect the db connection.
|
public void addItemChild(string $itemName, string $childName)
|
| $itemName |
string |
the parent item name |
| $childName |
string |
the child item name |
Adds an item as a child of another item.
public CAuthAssignment assign(string $itemName, mixed $userId, string $bizRule=NULL, mixed $data=NULL)
|
| $itemName |
string |
the item name |
| $userId |
mixed |
the user ID (see IWebUser::getId) |
| $bizRule |
string |
the business rule to be executed when checkAccess is called
for this particular authorization item. |
| $data |
mixed |
additional data associated with this assignment |
| {return} |
CAuthAssignment |
the authorization assignment information. |
Assigns an authorization item to a user.
|
public boolean checkAccess(string $itemName, mixed $userId, array $params=array (
))
|
| $itemName |
string |
the name of the operation that need access check |
| $userId |
mixed |
the user ID. This should can be either an integer and a string representing
the unique identifier of a user. See IWebUser::getId. |
| $params |
array |
name-value pairs that would be passed to biz rules associated
with the tasks and roles assigned to the user. |
| {return} |
boolean |
whether the operations can be performed by the user. |
Performs access check for the specified user.
|
protected boolean checkAccessRecursive(string $itemName, mixed $userId, array $params, array $assignments)
|
| $itemName |
string |
the name of the operation that need access check |
| $userId |
mixed |
the user ID. This should can be either an integer and a string representing
the unique identifier of a user. See IWebUser::getId. |
| $params |
array |
name-value pairs that would be passed to biz rules associated
with the tasks and roles assigned to the user. |
| $assignments |
array |
the assignments to the specified user |
| {return} |
boolean |
whether the operations can be performed by the user. |
Performs access check for the specified user.
This method is internally called by checkAccess.
Removes all authorization data.
|
public void clearAuthAssignments()
|
Removes all authorization assignments.
public CAuthItem createAuthItem(string $name, integer $type, string $description='', string $bizRule=NULL, mixed $data=NULL)
|
| $name |
string |
the item name. This must be a unique identifier. |
| $type |
integer |
the item type (0: operation, 1: task, 2: role). |
| $description |
string |
description of the item |
| $bizRule |
string |
business rule associated with the item. This is a piece of
PHP code that will be executed when checkAccess is called for the item. |
| $data |
mixed |
additional data associated with the item. |
| {return} |
CAuthItem |
the authorization item |
Creates an authorization item.
An authorization item represents an action permission (e.g. creating a post).
It has three types: operation, task and role.
Authorization items form a hierarchy. Higher level items inheirt permissions representing
by lower level items.
|
protected boolean detectLoop(string $itemName, string $childName)
|
| $itemName |
string |
parent item name |
| $childName |
string |
the name of the child item that is to be added to the hierarchy |
| {return} |
boolean |
whether a loop exists |
Checks whether there is a loop in the authorization item hierarchy.
|
|
| $itemName |
string |
the item name |
| $userId |
mixed |
the user ID (see IWebUser::getId) |
| {return} |
CAuthAssignment |
the item assignment information. Null is returned if
the item is not assigned to the user. |
Returns the item assignment information.
|
public array getAuthAssignments(mixed $userId)
|
| $userId |
mixed |
the user ID (see IWebUser::getId) |
| {return} |
array |
the item assignment information for the user. An empty array will be
returned if there is no item assigned to the user. |
Returns the item assignments for the specified user.
|
|
| $name |
string |
the name of the item |
| {return} |
CAuthItem |
the authorization item. Null if the item cannot be found. |
Returns the authorization item with the specified name.
|
public array getAuthItems(integer $type=NULL, mixed $userId=NULL)
|
| $type |
integer |
the item type (0: operation, 1: task, 2: role). Defaults to null,
meaning returning all items regardless of their type. |
| $userId |
mixed |
the user ID. Defaults to null, meaning returning all items even if
they are not assigned to a user. |
| {return} |
array |
the authorization items of the specific type. |
Returns the authorization items of the specific type and user.
|
public array getItemChildren(mixed $names)
|
| $names |
mixed |
the parent item name. This can be either a string or an array.
The latter represents a list of item names (available since version 1.0.5). |
| {return} |
array |
all child items of the parent |
Returns the children of the specified item.
|
public boolean hasItemChild(string $itemName, string $childName)
|
| $itemName |
string |
the parent item name |
| $childName |
string |
the child item name |
| {return} |
boolean |
whether the child exists |
Returns a value indicating whether a child exists within a parent.
Initializes the application component.
This method overrides the parent implementation by establishing the database connection.
|
public boolean isAssigned(string $itemName, mixed $userId)
|
| $itemName |
string |
the item name |
| $userId |
mixed |
the user ID (see IWebUser::getId) |
| {return} |
boolean |
whether the item has been assigned to the user. |
Returns a value indicating whether the item has been assigned to the user.
|
public boolean removeAuthItem(string $name)
|
| $name |
string |
the name of the item to be removed |
| {return} |
boolean |
whether the item exists in the storage and has been removed |
Removes the specified authorization item.
|
public boolean removeItemChild(string $itemName, string $childName)
|
| $itemName |
string |
the parent item name |
| $childName |
string |
the child item name |
| {return} |
boolean |
whether the removal is successful |
Removes a child from its parent.
Note, the child item is not deleted. Only the parent-child relationship is removed.
|
public boolean revoke(string $itemName, mixed $userId)
|
| $itemName |
string |
the item name |
| $userId |
mixed |
the user ID (see IWebUser::getId) |
| {return} |
boolean |
whether removal is successful |
Revokes an authorization assignment from a user.
Saves the authorization data to persistent storage.
Saves the changes to an authorization assignment.
public void saveAuthItem( CAuthItem $item, string $oldName=NULL)
|
| $item |
CAuthItem |
the item to be saved. |
| $oldName |
string |
the old item name. If null, it means the item name is not changed. |
Saves an authorization item to persistent storage.
|
protected boolean usingSqlite()
|
| {return} |
boolean |
whether the database is a SQLite database |