mongodbauthmanager Extends CPhpAuthmanager by saving/loading the data in a mongodb collection

  1. NOTE: This extension is now part of the directmongosuite
  2. Requirements
  3. Usage
  4. Usage
  5. Changelog

NOTE: This extension is now part of the directmongosuite

A quick hack with a few lines of code. CMongoDbAuthManager extends CPhpAuthManager: 'loadFromFile' and 'saveToFile' will load/save to a mongodb collection

New: Added support for multiple configurations in the collection. It is like you would work with different authfiles in CPhpAuthmanager.

Requirements

Yii 1.1.5

Extension yiimongodbsuite

Usage

  • Install and configure yiimongodbsuite.
  • Copy CMongoDbAuthManager.php to /protected/components
  • Install and use CMongoDbAuthManager the same way as you would use CPhpAuthManager.
'components'=>array(
        'mongodb'=>array(
            ... configure yiimongodbsuite ....
        ),

        'authManager'=>array(
            'class'=>'CMongoDbAuthManager',
            //'mongoConnectionId'=>'mongodb', (default)
            //'authFile' => 'mongodb_authmanager' (default, is now the collection name)
        ),
    ),

Usage

See documentation role-based-access-control

$auth = new CMongoDbAuthManager();

$auth->createOperation('createPost','create a post');
$auth->createOperation('readPost','read a post');
...
$role=$auth->createRole('admin');
$role->addChild('createPost');
...
$auth->save();


//switch to a TestEnviroment
$auth->switchConfig('TestEnviroment');

$role=$auth->createRole('reader');
$role->addChild('readPost');
...
$auth->save();


//switch back to 'default' and load data
$auth->switchConfig(null,true);
//or $auth->switchConfig(); $auth->init();
var_dump($auth);

//switch to 'TestEnviroment' and load data
$auth->switchConfig('TestEnviroment',true);
var_dump($auth);

Note: Run the above code to save authdata one time, and NOT for every request.

Use checkAccess, assign users... the same way as you would do with CPhpAuthManager Don't forget to load the data from mongodb by calling init();

$auth = new CMongoDbAuthManager('TestEnviroment');
$auth->init(); //load the data

....

Changelog

  • Bugfixes (see comments)
  • Support for multiple configurations
4 0
7 followers
742 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Auth
Developed by: Joblo
Created on: Feb 5, 2011
Last updated: 6 years ago

Downloads

show all

Related Extensions