Problem Creating A Role

Hey,

I have this RbacCommand.php file under the commands/shell directory:

public function run($args)

{


	if (($this->_authManager = Yii::app()->authManager) === null)


	{


		echo "Error executing the run($args) function\n";


		return;


	}


	echo "Would you like to continue?[Yes|No]";


	if (!strncasecmp(trim(fgets(STDIN)), 'y',1))


	{


		


		$this->_authManager->clearAll();


		$this->_authManager->createOperation("createUser" , "Create a new user" );


		$this->_authManager->createOperation("readUser" , "Read user profile information");


		$this->_authManager->createOperation("updateUser" , "Update user profile information");


		$this->_authManager->createOperation("deleteUser" , "Delete a user from a group");


		$this->_authManager->createOperation("createGroup" , "Create a new group");


		$this->_authManager->createOperation("readGroup" , "Read group information");


		$this->_authManager->createOperation("updateGroup" , "Update group information");


		$this->_authManager->createOperation("deleteGroup" , "Delete a group");


		$this->_authManager->createOperation("createDiscussion" , "Create a new Discussion");


		$this->_authManager->createOperation("readDiscussion" , "Read Discussion information");


		$this->_authManager->createOperation("updateDiscussion" , "Update Discussion information");


		$this->_authManager->createOperation("deleteDiscussion" , "Delete a Discussion from a project");


		$role = $this->_authManager->createRole("reader");


		$role->addChild('readUser');


		echo "5555555555555555555555555555555555555555555555555555555555555555";

When I run the yiic shell at the CommandPrompt i get an error, and I found that the line that causes it is the last one before the “echo” - $role->addChild(‘readUser’);

Are my RBAC tables could be wrong?

well, I wrote down from the start all 3 tables - authitem, authitemchild and authassignment.

Now at the CommandPrompt i get this error:

exception ‘CDbException’ with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 unknown column ‘date’ in ‘field list’. The SQL statement was:

INSERT INTO ‘AuthAssignment’ <‘itemname’,‘userid’,‘bizrule’,‘date’> VALUES <:itemname,:userid,:bizrule,:date>’

in C:\xampp\htdocs\yii\framework\db\CDbCommand.php:354

any ideas?

Thanks,

Eyal.

In the RbacCommand.php I have this line that makes all the trouble:

$this->_authManager->assign(‘adminManagement’,2);

I’m trying to give the adminManagement role to the user whose id=2.

The field "date" is indeed wrong, because the field name must be "data".

According to <yii framework folder>/web/auth/schema-mysql.sql file the table needs to be:


create table `AuthAssignment`

(

   `itemname`         	varchar(64) not null,

   `userid`           	varchar(64) not null,

   `bizrule`          	text,

   `data`             	text,

   primary key (`itemname`,`userid`),

   foreign key (`itemname`) references `AuthItem` (`name`) on delete cascade on update cascade

) engine InnoDB;



Hello,

I have the below code in protected/command/shell/auth.php

$auth=Yii::app()->authManager;

$bizRule=‘return !Yii::app()->user->isGuest;’;

$auth->createRole(‘authenticated’, ‘authenticated user’, $bizRule);

$bizRule=‘return Yii::app()->user->isGuest;’;

$auth->createRole(‘guest’, ‘guest user’, $bizRule);

$bizRule=‘return Yii::app()->user->name === “admin”;’;

$role = $auth->createRole(‘admin’, ‘administrator’);

$auth->assign(‘admin’,1); // adding admin to first user created

$auth->save();

I dont know how to execute this file but when i try to run it as :

php framework/yiic.php shell /var/www/yii/test/protected/commands/shell/auth.php

it gives following error:

PHP Notice: Trying to get property of non-object in /var/www/yii/test/protected/commands/shell/auth.php on line 3

PHP Stack trace:

PHP 1. {main}() /var/www/yii/framework/yiic.php:0

PHP 2. CApplication->run() /var/www/yii/framework/yiic.php:33

PHP 3. CConsoleApplication->processRequest() /var/www/yii/framework/base/CApplication.php:169

PHP 4. CConsoleCommandRunner->run() /var/www/yii/framework/console/CConsoleApplication.php:91

PHP 5. ShellCommand->run() /var/www/yii/framework/console/CConsoleCommandRunner.php:67

PHP 6. require() /var/www/yii/framework/cli/commands/ShellCommand.php:78

PHP Fatal error: Call to a member function createRole() on a non-object in /var/www/yii/test/protected/commands/shell/auth.php on line 6

PHP Stack trace:

PHP 1. {main}() /var/www/yii/framework/yiic.php:0

PHP 2. CApplication->run() /var/www/yii/framework/yiic.php:33

PHP 3. CConsoleApplication->processRequest() /var/www/yii/framework/base/CApplication.php:169

PHP 4. CConsoleCommandRunner->run() /var/www/yii/framework/console/CConsoleApplication.php:91

PHP 5. ShellCommand->run() /var/www/yii/framework/console/CConsoleCommandRunner.php:67

PHP 6. require() /var/www/yii/framework/cli/commands/ShellCommand.php:78

and nothing gets inserted into any tables.

I have made below changes in to both main.php and console.php

‘db’=>array(

		'connectionString' =&gt; 'mysql:host=localhost;dbname=yii',


		'emulatePrepare' =&gt; true,


		'username' =&gt; 'root',


		'password' =&gt; '',


		'charset' =&gt; 'utf8',


	),


	'authManager'=&gt;array(


		'class'=&gt;'CDbAuthManager',


		'connectionID'=&gt;'db',


		'defaultRoles'=&gt;array('authenticated','guest', 'admin'), 


	),

Pl help… got stuck from quite a few days.

solved: pl check on http://www.yiiframework.com/forum/index.php/topic/44894-creating-authorization-roles/