[EXTENSION] srbac : Web interface for the administration of rbac

Of course! I don’t why that never occurred to me, but that makes sense. Sorry for the stupid question <_<

… But, when I do that, I still get the ‘Call to a member function getControllerPath() on a non-object in C:\xampplite\htdocs\agapecenter\agapeProject\app\protected\modules\srbac\controllers\AuthitemController.php on line 698’ error. Did my version just get corrupted somehow?

can you go to that file/line and befor you execute this line ($contPath = Yii::app()->getModule($c[0])->getControllerPath(); ) make this




var_dump($c, $modul, $controller);



and then post the result or check if you have the module/controller that you get dumped.

Hmm, I think I found the problem.

I get


array(2) {

  [0]=>

  string(9) "Community"

  [1]=>

  string(17) "partnerController"

}

string(10) "Community_"

string(17) "partnerController"



… and the controller is named Community_partnerController. On line 694 is


//Check if it's a module controller

if(substr_count($controller, "_")) {

, so it would appear that it is splitting my controller name and confusing itself. The table name is community_partner, so I don’t really see a good way around this if anybody else has tables with a ‘’ in the name. I could add a bit to the if statement to make sure it isn’t one of my controllers whose name contains the '’, but that’s very application specific. Maybe the if statement could check to see if the controller is under the application’s main /controller folder before this assumption?

The proble with _ is already fixed in svn (r168). You could download it from http://code.google.com/p/srbac/source/checkout

Thanks, solved my problem

I just downloaded srbac and am installing it following the 1.1 pdf

when I went to run myapp/index.php?r=srbac I get the following error:

CException

Description

Property "CWebApplication.authManager" is read only.

since I pretty much did a cut 'n paste of the code from the docs I don’t know what the problem is…

thanks

Hi,

can you please post your config? Maybe I can Help you then.

I think I got the config part sorted out - but now the error is:

Unable to resolve the request "srbac".

One possibility - in the instructions pdf it said to extract the zip file in the modules directory, but that leaves you with a directory named srbac 1.1.0.1, and inside of that is the srbac directory…

EDIT: that didn’t help…

EDIT#2 actually it DID - but only after I really fixed the config…

here you go:




<?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(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Bianchini',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.modules.srbac.controllers.SBaseController',

	),


	// application components

	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

	

	

		'authManager'=>array(

		// The type of Manager (Database)

			'class'=>'CDbAuthManager',

		// The database component used

			'connectionID'=>'db',

		// The itemTable name (default:authitem)

			'itemTable'=>'items',

		// The assignmentTable name (default:authassignment)

			'assignmentTable'=>'assignments',

		// The itemChildTable name (default:authitemchild)

			'itemChildTable'=>'itemchildren',

		),

	   'modules' => array(	

			'srbac' => array(

				'userclass'=>'User', 

				'userid'=>'user_ID', 

				'username'=>'username', 

				'debug'=>true, 

				'pageSize'=>10, 

				'superUser' =>'Authority', 

				'css'=>'srbac.css', 

				'layout'=>'application.views.layouts.admin', 

				'notAuthorizedView'=>'srbac.views.authitem.unauthorized ', 

				'alwaysAllowed'=>array('SiteLogin','SiteLogout','SiteIndex','SiteAdmin','SiteError', 'SiteContact'),

				'userActions'=>array('Show','View','List'),

				'listBoxNumberOfLines' => 15, 

				'alwaysAllowedPath'=>'srbac.components', 

				),	

			),


		

              /*


		'db'=>array(

			'connectionString' => 'sqlite:protected/data/testdrive.db',

		),


		*/

		// uncomment the following to use a MySQL database

		

		'db'=>array(

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

			'emulatePrepare' => true,

			'username' => 'garuda_michael',

			'password' => 'Guru.Dragpur',

			'charset' => 'utf8',

			'tablePrefix' => 'tbl_',


		),

		

			

		'errorHandler'=>array(

			// use 'site/error' action to display errors

            'errorAction'=>'site/error',

        ),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'garuda@wi.rr.com',

	),

);

OK, the modules section was nested too deep - I fixed that and now I get to

myexample/index.php?r=srbac/authitem/install

So at least I am accessing the module, but I now get this error:

PHP Error

Description

include(User.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

here is a little more info on the error:

Stack Trace

#0 /home/garuda/public_html/yii/framework/YiiBase.php(338): autoload()

#1 unknown(0): autoload()

#2 /home/garuda/public_html/bianchini2/protected/modules/srbac/SrbacModule.php(265): spl_autoload_call()

#3 /home/garuda/public_html/bianchini2/protected/modules/srbac/components/Helper.php(417): SrbacModule->getUserModel()

#4 /home/garuda/public_html/bianchini2/protected/modules/srbac/views/authitem/install/install.php(102): checkInstall()

and here is the line in question (338):

/home/garuda/public_html/yii/framework/YiiBase.php(338)

00326: * @param string class name

00327: * @return boolean whether the class has been loaded successfully

00328: */

00329: public static function autoload($className)

00330: {

00331: // use include so that the error PHP file may appear

00332: if(isset(self::$_coreClasses[$className]))

00333: include(YII_PATH.self::$_coreClasses[$className]);

00334: else if(isset(self::$_classes[$className]))

00335: include(self::$_classes[$className]);

00336: else

00337: {

00338: include($className.’.php’);

00339: return class_exists($className,false) || interface_exists($className,false);

00340: }

00341: return true;

00342: }

00343:

I am getting closer to the install, but I don’t understand why it hangs here…

OK this error we can fix.

This is you config




'srbac' => array(

    'userclass'=>'User', 

    'userid'=>'user_ID', 

    'username'=>'username', 



So you have to create the User model and the User table inside

your Database. There you have to define a field user_ID and a field username.

But this is not a MUST. This is how I named it.




'srbac' => array(

    'userclass'=>'User',

    'userid'=>'ID',

    'username'=>'strUsername',



Important is that you don’t enter the name of the table. You need the name of the Model.

My Table is named tbl_user

Thanks - as I mentioned in my first post upthread, I copied this stuff from the documentation / installation instructions - which doesn’t give any database schema at all (a little weird considering that setting up database access was part of the instructions!) I guess I assumed that the installer would create the tables, but as you can see from the above post, the installer did not run but rather errored out…

Do we need to explicitly assign roles to every user through SRBAC, or is there a way when someone creates a user that if a field (e.g: is_volunteer) is true, that user will automatically be assigned a volunteer role?

Hi, I am a relative newbie to Yii and srbac, so sorry for this question if it’s too simple. I have configured srbac, but can’t get to the ?r=srbac page at all, nor other pages in my site. I suspect I have not fully set up something, but the error I get is: Property “CWebApplication.authManager” is read only. (/Applications/MAMP/htdocs/yii/framework/base/CModule.php(435)). These seems really basic, but I don’t understand it. Here is my config:

<?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(

'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'JPIM',





// preloading 'log' component


'preload'=&gt;array('log'),





// autoloading model and component classes


'import'=&gt;array(


	'application.models.*',


	'application.components.*',


	'application.modules.srbac.controllers.SBaseController',


),





'modules'=&gt;array(


	'srbac',


),





// application components


'components'=&gt;array(


	'user'=&gt;array(


		// enable cookie-based authentication


		'allowAutoLogin'=&gt;true,


	),


    /*


	'db'=&gt;array(


		'connectionString' =&gt; 'sqlite:protected/data/testdrive.db',  


	),


*/


	// uncomment the following to use a MySQL database		


	'db'=&gt;array(


		'connectionString' =&gt; 'mysql:host=192.168.1.98;dbname=xxx;port=8889',


		'emulatePrepare' =&gt; true,


		'username' =&gt; 'xxx',


		'password' =&gt; 'xxx',


		'charset' =&gt; 'utf8',


	),		


	'errorHandler'=&gt;array(


		// use 'site/error' action to display errors


        'errorAction'=&gt;'site/error',


    ),


	'log'=&gt;array(


		'class'=&gt;'CLogRouter',


		'routes'=&gt;array(


			array(


				'class'=&gt;'CFileLogRoute',


				'levels'=&gt;'error, warning',


			),


			// uncomment the following to show log messages on web pages


			/*


			array(


				'class'=&gt;'CWebLogRoute',


			),


			*/


		),


	),


),





// application-level parameters that can be accessed


// using Yii::app()-&gt;params['paramName']


'params'=&gt;array(


	// this is used in contact page


	'adminEmail'=&gt;'jon.herstein@gmail.com',


),





'authManager'=&gt;array(


	// The type of Manager (Database)


	'class'=&gt;'CDbAuthManager',


	// The database component used


	'connectionID'=&gt;'db',


	// The itemTable name (default:authitem)


	'itemTable'=&gt;'authitem',


	// The assignmentTable name (default:authassignment)


	'assignmentTable'=&gt;'authassignment',


	// The itemChildTable name (default:authitemchild)


	'itemChildTable'=&gt;'authitemchild',


),





'srbac' =&gt; array(


	'userclass'=&gt;'User', //optional defaults to User


	'userid'=&gt;'user_ID', //optional defaults to userid


	'username'=&gt;'username', //optional defaults to username


	'debug'=&gt;true, //optional defaults to false


	'pageSize'=&gt;10, //optional defaults to 15


	'superUser' =&gt;'Authority', //optional defaults to Authorizer


	'css'=&gt;'srbac.css', //optional defaults to srbac.css


	'layout'=&gt;'application.views.layouts.admin', //optional defaults to empty string must be an existing alias


	'notAuthorizedView'=&gt;'srbac.views.authitem.unauthorized ', // optional defaults to srbac.views.authitem.unauthorized, must be an existing alias


	'alwaysAllowed'=&gt;array( 


		//optional defaults to gui


		'SiteLogin','SiteLogout','SiteIndex','SiteAdmin',


		'SiteError', 'SiteContact'


	),


	'userActions'=&gt;array(


		//optional defaults to empty array


		'Show','View','List'


	),


	'listBoxNumberOfLines' =&gt; 15, //optional defaults to 10 'imagesPath' =&gt; 'srbac.images', //optional defaults to srbac.images 


	'imagesPack'=&gt;'noia', //optional defaults to noia 


	'iconText'=&gt;true, //optional defaults to false 


	'header'=&gt;'srbac.views.authitem.header', //optional defaults to srbac.views.authitem.header, must be an existing alias 


	'footer'=&gt;'srbac.views.authItem.footer', //optional defaults to srbac.views.authitem.footer, must be an existing alias 


	'showHeader'=&gt;true, //optional defaults to false 


	'showFooter'=&gt;true, //optional defaults to false


	'alwaysAllowedPath'=&gt;'srbac.components', //optional defaults to srbac.components must be an existing alias


),	

);


Any and all help welcome - what am I missing?!

It took me a moment to figure out that I needed to create the tables myself and it doesn’t happen in the install - did you do that?

What I can see here is that you made a extra field in your configuration array for srbac.

The configuration of srbac has to be inside the modules part like this:




'modules'=>array(

    'srbac' => array(

		'userclass'=>'User', //optional defaults to User

		'userid'=>'user_ID', //optional defaults to userid

		'username'=>'username', //optional defaults to username

		'debug'=>true, //optional defaults to false

		'pageSize'=>10, //optional defaults to 15

		'superUser' =>'Authority', //optional defaults to Authorizer

		'css'=>'srbac.css', //optional defaults to srbac.css

		'layout'=>'application.views.layouts.admin', 

		'notAuthorizedView'=>'srbac.views.authitem.unauthorized ',

		'alwaysAllowed'=>array( 

			//optional defaults to gui

			'SiteLogin','SiteLogout','SiteIndex','SiteAdmin',

			'SiteError', 'SiteContact'

		),

		'userActions'=>array(

			//optional defaults to empty array

			'Show','View','List'

		),

		'listBoxNumberOfLines' => 15, 

		'imagesPack'=>'noia', //optional defaults to noia 

		'iconText'=>true, //optional defaults to false 

		'header'=>'srbac.views.authitem.header', 

		'footer'=>'srbac.views.authItem.footer', 

		'showHeader'=>true, //optional defaults to false 

		'showFooter'=>true, //optional defaults to false

		'alwaysAllowedPath'=>'srbac.components', 

	),

),



otherwise the configuration is not passed through to you model.

I will try this. Are you just talking about the ‘user’ table? Where do I find the detail on setting this up?

OK, thanks, will try this…

I think you need a user table… you need a user class, and Yii will model that off the table. You also need the tables that are under /yii/framework/web/auth/schema.sql - assuming you’re using MySQL. Yii’s RBAC and authmananager use these tables to store role/task/operation information.

Thanks, will try these suggestions tonight!