Yii Framework Forum: Script to help set up RBAC - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Script to help set up RBAC Rate Topic: -----

#1 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 30 January 2009 - 09:19 AM

Just a simple command that helps to set up initial RBAC rules. You can put it into protected/commands/shell and add some operations, tasks, roles and user assignments. Use yiic shell and enter setuprbac to use.

Make sure you have configured CDbAuthManager:
<?php
    'components'=array(
        'authManager'=>array(
            'class'=>'CDbAuthManager',
            'connectionID'=>'db',
        ),



Maybe it's useful for someone :).

Attached File(s)


0

#2 User is offline   emix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 02-March 09
  • Location:Poland

Posted 16 March 2009 - 05:53 AM

can you specify how to run that one step by step?
0

#3 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 16 March 2009 - 10:30 AM

This command is thought to be used only once to set up your basic RBAC operations, tasks and roles.

1. Put the file into protected/commands/shell of your application
2. Edit the file to match your basic layout of roles/tasks and users
3. Add db configuration and CDbAuthManager to your config file
4. Run the command like yiic shell and then setuprbac

Simple example:

<?php
    private $operations=array(
        array('readUnit', 'Read Unit'),
        array('createUnit', 'Create Unit'),
        array('updateUnit', 'Update Unit'),
        array('deleteUnit', 'Delete Unit'),
    );

    private $tasks=array(
        array(
            'adminUnit',
            'Administrate Units',
            array('readUnit','createUnit','updateUnit','deleteUnit')
        ),
    );

    private $roles=array(
        array(
            'admin',
            'Administrators with full access rights',
            array('adminUnit'),
        ),
    );

    private $users=array(
        '1' => array('admin')
    );

1

#4 User is offline   m100k 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 17-March 09

Posted 19 March 2009 - 09:26 AM

but how can i define bizrules than?
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 19 March 2009 - 09:58 AM

Add them as additional array parameter. To e.g. define a operation "editOwnPosts":

<?php
private $operations=array(
    array('editOwnPosts','Edit my own posts', array(), 'return Yii::app()->user->id==$params["post"]->authorID'),

(The empty array stands for the children of this item).

As described in the top of the script, each array entry in $operations, $tasks and $roles uses this form:

array( 'ItemName' , 'Item description', array('names','of','children') , 'optional business rule');

0

#6 User is offline   m100k 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 17-March 09

Posted 20 March 2009 - 07:02 AM

hello,
i guess i'm not doin' it right.
i have to ask.

i've built a php file named setuprbac.php, added my roles, operations and tasks and put it into the shell folder of my app
i've created the database like it should be.
then i ran the commend like /yii/framework/yiic shell
next i typed in setuprbac resp. setuprbac.php

and guess what, nothing happened.

to you i may seem like a complete clueless tool, but i just don't get the whole rbac-topic, pleas help
0

#7 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 20 March 2009 - 12:47 PM

Did you check the database? Are any entries created in your Auth* tables? That's the whole purpose of this script...
0

#8 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 17 April 2009 - 09:20 AM

It would have been great if you mentioned that your script executes the schema.sql for creating the tables which includes a prior DROP TABLE IF EXISTS!

I know that your script is for initial setup, but i didn't expected that it would drop my existing tables without checking or asking  :(

I've already added some items and was now searching for an easier way to do the heavy work...

Maybe at least something like:
		$createTables = false;
// Check whether tables already exist
if($this->_db->schema->getTable('AuthItem') || $this->_db->schema->getTable('AuthItemChild') || $this->_db->schema->getTable('AuthAssignment')){
echo "At least one Auth* table already exists in database!n Overwrite existing Auth* tables? [Yes|No] ";
if(!strncasecmp(trim(fgets(STDIN)),'y',1))
  $createTables = true;
}

        // Read schema file and create db tables
if($createTables===true)
{
$schemafile=Yii::getPathOfAlias('system.web.auth').DIRECTORY_SEPARATOR.'schema.sql';
if (($schema=file_get_contents($schemafile))===false)
die("Could not read schema file in $schemafile.n");
$this->_db->createCommand($schema)->execute();
}


Thanks anyway for this script!

Greetings
0

#9 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 17 April 2009 - 12:03 PM

The script was just a quick mashup to help me install RBAC rules for fresh installations. It uses the sql schema file that comes with Yii to create all required tables. Sorry, if that was unclear.
0

#10 User is offline   thomas.mery 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 04-January 09

Posted 17 April 2009 - 12:15 PM

Hi,

thanks for this !

Could not make it work but :

I added :



just before the  RBAC setup finished successful. message

it was not working for me prior to this addition

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users