libSmalldb
v0.6
|
IAuth implementation using Smalldb state machine and shared session token in a cookie to identify SharedTokenMachine instance.
This class handles cookies only, it is up to session machine to maintain session.
To log in, use getSessionMachine() and invoke a login transition. To log out, use a logout transition. The registered callback will take care of the cookies in both cases.
Public Member Functions | |
__construct ($config, AbstractBackend $smalldb) | |
Constructor. More... | |
checkSession () | |
Check session - read & update cookies, setup session state machine and register callbacks. More... | |
getSessionMachine () | |
Get session machine which manages all stuff around login and session. More... | |
getUserId () | |
Get user's ID. More... | |
hasUserRoles ($roles) | |
Check whether user has given role(s). More... | |
isAllMighty () | |
Is user all mighty? (Admin or something like that.) More... | |
Protected Member Functions | |
getUserRoles () | |
Get list of user's roles, or null if not logged in. More... | |
Protected Attributes | |
$smalldb | |
Smalldb backend More... | |
$session_machine | |
Reference to session state machine. More... | |
Configuration | |
$cookie_name = 'AuthToken' | |
Cookie name. More... | |
$cookie_ttl = 2592000 | |
Cookie duration [seconds] (default: 30 days) More... | |
$user_id_property = 'user_id' | |
Name of the session machine property with user's ID. More... | |
$user_roles_property = 'user_roles' | |
Name of the session machine property with user's role. More... | |
$all_mighty_user_role = null | |
Name of all mighty user role (admin) More... | |
$all_mighty_cli = false | |
Is command line all mighty? More... | |
$session_machine_null_ref = 'session' | |
Null reference to session machine (array; use session_machine_ref_prefix if not set) More... | |
$session_machine_ref_prefix = 'session' | |
Prefix of session machine reference (array; token ID will be appended) More... | |
__construct | ( | $config, | |
AbstractBackend | $smalldb | ||
) |
Constructor.
$config | Configuration options - see Configuration section. |
$smalldb | Instance of Smalldb backend (AbstractBackend). |
checkSession | ( | ) |
Check session - read & update cookies, setup session state machine and register callbacks.
This must be called before using any state machines. No transitions are invoked at this point, only the session state machine reference is created.
Implements IAuth.
getSessionMachine | ( | ) |
Get session machine which manages all stuff around login and session.
getUserId | ( | ) |
Get user's ID.
User's ID is limited to single scalar value (any integer or string).
Implements IAuth.
hasUserRoles | ( | $roles | ) |
Check whether user has given role(s).
Smalldb does not understand user roles, it can only check whether user's roles contain one of required values. User's roles are global and they are not related to any instance of anything.
User may have any number of roles.
$roles | Name of required role (string), or array of required roles (array of strings). |
Implements IAuth.
isAllMighty | ( | ) |
Is user all mighty? (Admin or something like that.)
When this function returns true, access control will be disabled.
Implements IAuth.
|
protected |
Get list of user's roles, or null if not logged in.
|
protected |
Smalldb backend
|
protected |
Reference to session state machine.
|
protected |
Cookie name.
|
protected |
Cookie duration [seconds] (default: 30 days)
|
protected |
Name of the session machine property with user's ID.
|
protected |
Name of the session machine property with user's role.
|
protected |
Name of all mighty user role (admin)
|
protected |
Is command line all mighty?
|
protected |
Null reference to session machine (array; use session_machine_ref_prefix if not set)
|
protected |
Prefix of session machine reference (array; token ID will be appended)