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

Just for kicks, I created a "DefaultController" in the root app (instead of a module), and EVERYTHING showed up as expected. It also allowed me to administer the "DefaultController" for gii,sbrac.

See Attached

Any ideas?

679

Fullscreen capture 5112010 115807 AM.jpg

680

Fullscreen capture 5112010 120029 PM.jpg

I think that you should have 1 default controller in application.controllers and all your controllers (that use srbac) should extend this one. If you have multiple default controllers in each module things may mess up

In the documentation "srbac 1.1.0.2 guide" on page 3 there is a misstake.

'srbac.views.authitem.unauthorized ’

is written with a space character like i posted it here, so when sb copies it, he/she will get an error like i got. :D

Hello,

How do I properly use code to add specific role to specific user.

Like

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

$auth->assign(‘reader’,‘readerA’);

When trying:


	protected function processActivationCommand()

	{

		if(isset($_POST['command'], $_POST['id']) && $_POST['command']==='activate')

		{

			$user=$this->loadP2User($_POST['id']);

			$user->status=P2User::STATUS_ACTIVE;

			$user->save();

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

			$auth->assign('member',$user->id);

			$this->module->mailer->sendUserActivation($user);

			// reload the current page to avoid duplicated activation actions

			$this->refresh();

		}

	}

I get stumbled up on:

     itemname|userid| bizrule|data


 member|5|s:0:"";

New rec: member|6|NULL|N;

It still works but the new records are not equal to Srbac added :)

Best regards,

CoLT

I am occurring strange error when user without permissions try to access Gii CRUD tables:

I suppose its not critical Srbac issue as CMenu is involved here, but your opinion would be appreciated:


PHP Error

Description

Invalid argument supplied for foreach()


Source File

C:\wamp\www\ssis\lib\yii\zii\widgets\CMenu.php(176)


00164:         }

00165:     }

00166: 

00167:     /**

00168:      * Normalizes the {@link items} property so that the 'active' state is properly identified for every menu item.

00169:      * @param array the items to be normalized.

00170:      * @param string the route of the current request.

00171:      * @param boolean whether there is an active child menu item.

00172:      * @return array the normalized menu items

00173:      */

00174:     protected function normalizeItems($items,$route,&$active)

00175:     {

00176:         foreach($items as $i=>$item)

00177:         {

00178:             if(isset($item['visible']) && !$item['visible'])

00179:             {

00180:                 unset($items[$i]);

00181:                 continue;

00182:             }

00183:             if($this->encodeLabel)

00184:                 $items[$i]['label']=CHtml::encode($item['label']);

00185:             $hasActiveChild=false;

00186:             if(isset($item['items']))

00187:             {

00188:                 $items[$i]['items']=$this->normalizeItems($item['items'],$route,$hasActiveChild);

Stack Trace

#0 C:\wamp\www\ssis\lib\yii\zii\widgets\CMenu.php(111): CMenu->normalizeItems()

#1 C:\wamp\www\ssis\lib\yii\web\CBaseController.php(148): CMenu->init()

#2 C:\wamp\www\ssis\lib\yii\web\CBaseController.php(173): CoachController->createWidget()

#3 C:\wamp\www\ssis\www\themes\ssis\views\layouts\column2.php(16): CoachController->widget()

#4 C:\wamp\www\ssis\lib\yii\web\CBaseController.php(119): require()

#5 C:\wamp\www\ssis\lib\yii\web\CBaseController.php(88): CoachController->renderInternal()

#6 C:\wamp\www\ssis\lib\yii\web\CController.php(689): CoachController->renderFile()

#7 C:\wamp\www\ssis\modules\srbac\controllers\SBaseController.php(82): CoachController->render()

#8 C:\wamp\www\ssis\modules\srbac\controllers\SBaseController.php(56): CoachController->onUnauthorizedAccess()

#9 C:\wamp\www\ssis\lib\yii\web\CController.php(298): CoachController->beforeAction()

#10 C:\wamp\www\ssis\lib\yii\web\filters\CFilterChain.php(129): CoachController->runAction()

#11 C:\wamp\www\ssis\lib\yii\web\filters\CFilter.php(41): CFilterChain->run()

#12 C:\wamp\www\ssis\lib\yii\web\CController.php(999): CAccessControlFilter->filter()

#13 C:\wamp\www\ssis\lib\yii\web\filters\CInlineFilter.php(59): CoachController->filterAccessControl()

#14 C:\wamp\www\ssis\lib\yii\web\filters\CFilterChain.php(126): CInlineFilter->filter()

#15 C:\wamp\www\ssis\lib\yii\web\CController.php(283): CFilterChain->run()

#16 C:\wamp\www\ssis\lib\yii\web\CController.php(257): CoachController->runActionWithFilters()

#17 C:\wamp\www\ssis\lib\yii\web\CWebApplication.php(320): CoachController->run()

#18 C:\wamp\www\ssis\lib\yii\web\CWebApplication.php(120): CWebApplication->runController()

#19 C:\wamp\www\ssis\lib\yii\base\CApplication.php(135): CWebApplication->processRequest()

#20 C:\wamp\www\ssis\www\index.php(13): CWebApplication->run()



Greetings,

CoLT

Can you post the CMenu configuration with the line that produces the error?

Hello,

Of course,


	protected function normalizeItems($items,$route,&$active)

	{

176		foreach($items as $i=>$item)

		{

			if(isset($item['visible']) && !$item['visible'])

			{

				unset($items[$i]);

				continue;

			}

			if($this->encodeLabel)

				$items[$i]['label']=CHtml::encode($item['label']);

			$hasActiveChild=false;

			if(isset($item['items']))

			{

				$items[$i]['items']=$this->normalizeItems($item['items'],$route,$hasActiveChild);

				if(empty($items[$i]['items']) && $this->hideEmptyItems)

					unset($items[$i]['items']);

			}

			if(!isset($item['active']))

			{

				if($this->activateParents && $hasActiveChild || $this->isItemActive($item,$route))

					$active=$items[$i]['active']=true;

				else

					$items[$i]['active']=false;

			}

			else if($item['active'])

				$active=true;

			if($items[$i]['active'] && $this->activeCssClass!='')

			{

				if(isset($item['itemOptions']['class']))

					$items[$i]['itemOptions']['class'].=' '.$this->activeCssClass;

				else

					$items[$i]['itemOptions']['class']=$this->activeCssClass;

			}

		}

		return array_values($items);

	}

Best regards,

CoLT

Sorry, I mean the menu widget configuration

Sorry :) here it is:

p2b9\www\themes\ssis\views\layouts\column2.php

Problematic part:


		<?php

			$this->beginWidget('zii.widgets.CPortlet', array(

				'title'=>'Operations',

			));

			$this->widget('zii.widgets.CMenu', array(

				'items'=>$this->menu,

				'htmlOptions'=>array('class'=>'operations'),

			));

			$this->endWidget();

		?>

Whole file:


<?php $this->beginContent('/layouts/main'); ?>

	<div class="column2">

		<div id="content">

			<?php echo $content; ?>

		</div><!-- content -->

	</div>

	<div class="column1">

		<div id="sidebar">

		<?php

			$this->beginWidget('zii.widgets.CPortlet', array(

				'title'=>'Operations',

			));

			$this->widget('zii.widgets.CMenu', array(

				'items'=>$this->menu,

				'htmlOptions'=>array('class'=>'operations'),

			));

			$this->endWidget();

		?>

		</div><!-- sidebar -->

	</div>

	<?php echo P2Helper::clearfloat(); ?>

<?php $this->endContent(); ?>

Best regards,

CoLT

I don’t see anything srbac related in this code.

Maybe there’s something in $this->menu

Hi!

In the guide, it refers to the module configuration…

where can i find that?

and where do i declare the imports? sorry…i’m new to this framework…

Thanks!

You configure the modules and declare imports in your main.php configuration file (protected/config/main.php)

Thanks for the quick response! ;D

When $model_name = ‘module_a/test1/action1’, it result 404 error.

http ://localhost/grbacs/srbac/authitem/update/id/module_a%2FTest1Action1.html

Anyone having the same issue.




         <?php echo SHtml::ajaxLink(

         SHtml::image($this->module->getIconsPath().'/update.png',

         Helper::translate('srbac','Update'),

         array('border'=>0,'title'=>Helper::translate('srbac','Update'))),

         array('update','id'=>$model->name),

         array(

         'type'=>'POST',

         'update'=>'#preview',

         'beforeSend' => 'function(){

                      $("#preview").addClass("srbacLoading");

                  }',

         'complete' => 'function(){

                      $("#preview").removeClass("srbacLoading");

                  }',))?>



Hi all,

I have the srbac configured and running fine. I can use the srbac/authitem/manage, the auto assign and list roles. I extended the default controller with SBaseController. However, if I set ‘debug’ => false, all the pages become restricted except for the AlwaysAllowed. I don’t know what to check for clue.

Thanks,

Terry

Hi,

Have you auto created the operations/tasks?

Have you created the roles and assign them the auto created tasks?

Have you assigned the roles to your users?

My simple answers are Yes, Yes, and Yes

Here is my main.conf on srbac

‘srbac’ => array(

        // Your application's user class (default: User)


        'userclass' =&gt; &quot;User&quot;,


        // Your users' table user_id column (default: userid)


        'userid' =&gt; 'user_id',


        // your users' table username column (default: username)


        'username' =&gt; 'username',


        // Debug mode(default: false)


        // In debug mode every user (even guest) can admin srbac, also


        //if you use internationalization untranslated words/phrases


        //will be marked with a red star


        'debug' =&gt; false,


        // The number of items shown in each page (default:15)


        'pageSize' =&gt; 10,


        // The name of the super user


        'superUser' =&gt; 'Super',


        //The css file to use


        'css' =&gt; 'srbac.css', // must be in srbac css folder


        //The layout to use


        //'layout' =&gt; 'application.views.layouts.admin',


        //The not authorized page to render when a user tries to access an page


        //tha he's not authorized to


        'notAuthorizedView'=&gt;'application.modules.srbac.views.authitem.unauthorized',


        // The actions that are always allowed to every user (when using the


        // auto create mode of srbac)


        'alwaysAllowed' =&gt; array(


            'SiteLogin', 'SiteLogout', 'SiteIndex', 'SiteCaptcha',


            'SiteContact', 'SiteError', 'SitePage'),


        // The operationa assigned to users (when using the


        // auto create mode of srbac)


        'userActions' =&gt; array(


            'Show', 'View', 'List'


        ),


        //The number of lines in assign listboxes (default 10)


        'listBoxNumberOfLines' =&gt; 15,


        'imagesPath' =&gt; 'srbac.images',


        'imagesPack' =&gt; 'noia',


        'iconText' =&gt;true,


        'header'=&gt;'srbac.views.authitem.header',


        'footer'=&gt;'srbac.views.authitem.footer',


        'showHeader'=&gt;true,


        'showFooter'=&gt;true,


        'alwaysAllowedPath'=&gt;'srbac.components',


    ),

I also attached some screen shots.

If I set debug => false, only SiteController can be accessed. I already extended default controller in component with SBaseController. My UserController extends the default controller.

Have you also removed the default access rules from your controllers?

I am kind of new to Yii. Where are the default access rules? I commented out all filter access control and access rules in my controllers.

Yes these are the access rules.

I see you have assigned the tasks to the super user.

The super user is used for managing srbac.

Try to make another role "Admin" assign to it the tasks and see if a user with the Admin role can perform all the operations