Chapter 8 – RBAC

This chapter confuses many people and I was one this person. Read some hints (here in this subforum) and make several tests, I finaly made it works.

I’ll try explain it with code blocks. Keep in mind that I made these tests using Ubuntu 10.04.

Step #1 – Pg 179 - Configuring the authorization manager

Here we need to configure our protected/config/main.php, however I thought this part is confuse. Where I put the code suggested? I will show where we must put it.

Open the file trackstar/protected/config/main.php. (I’ll show a piece of code)


<?php

// uncomment the following to define a path alias 

// Yii::setPathOfAlias('local','path/to/local-folder'); 


// This is the main Web application configuration. Any writable 

// CWebApplication properties can be configured here. 

return array(

	

	Begin of File


	// application components 

	'components'=>array( 

		'user'=>array( 

			// enable cookie-based authentication 

			'allowAutoLogin'=>true, 

		), 

		// uncomment the following to enable URLs in path-format		 

		'urlManager'=>array( 

			'urlFormat'=>'path', 

			'showScriptName' => false, 

			'urlSuffix' => '.html', 

			'rules'=>array( 

				'<controller:\w+>/<id:\d+>'=>'<controller>/view', 

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 

			), 

		),

		// uncomment the following to use a MySQL database		 

		'db'=>array( 

			'connectionString' => 'mysql:host=localhost;dbname=trackstar_dev', 

			'emulatePrepare' => true, 

			'username' => 'root', 

			'password' => 'xxxxxxx', 

			'charset' => 'utf8', 

		), 

		 

		//Here we must put the code suggested.

		//This code is under components array()

		'authManager'=>array( 

           			 'class'=>'CDbAuthManager', 

           			 'connectionID'=>'db', 

      		 ),

	…


	),


	…

	

	End of file

);

?>

Step #2 – Pg 183 - Writing a console application command

We need to create a file RbacCommand.php in /protected/commands/shell/ . The first method of this class it’s not necessary (for me it didn’t work). So, remove it.

public function getHelp()

{

return <<<EOD

USAGE

rbac

DESCRIPTION

This command generates an initial RBAC authorization hierarchy.

EOD;

}

This part must be removed.

Step #3 – Pg 186 – (runing the command)

Access the folder trackstar (I use GNU/Linux) so: /var/www/trackstar. <enter>.

On the prompt type, protected/yiic shell protected/config/main.php. You should see something like it:

Yii Interactive Tool v1.1 (based on Yii v1.1.2)

Please type ‘help’ for help. Type ‘exit’ to quit.

>>

Now type help to see a list of available commands:

>> help

At the prompt, you may enter a PHP statement or one of the following

commands:

  • controller

  • crud

  • form

  • help

  • model

  • module

  • rbac

If you see the command rbac in the list. It’s evereting ok. So run the command.

>> rbac

You will see it:

This command will create three roles: Owner, Member, and Reader and the

following premissions:

create, read, update and delete user

create, read, update and delete project

create, read, update and delete issue

Would you like to continue? [Yes|No] Yes

Authorization hierarchy successfully generated.

type “Yes” after run the command type “exit”.

I realy hope that it, help you with this topic.

Credits for the topics from @hman and @windsor. Sorry if I forgot someone.

Excuse my bad English.

Thanks for the info, i was running into the same problem

Thank You!

Yeah thanks dear… I cannot understand about why we are creating associateUserToRole() and removeUserFromRole() where we are using there methods there are too confusing me please help…

Please explain about this topic rbac i understand about authorization hierarchy… But there chapter confuses me very much Please expand this thread upto the end of rbac given in agile web application development