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

I get this error when selecting a user… in user assignments:

<h1>PHP Error</h1>

<h3>Description</h3>

<p class="message">

unserialize() [&lt;a href='function.unserialize'&gt;function.unserialize&lt;/a&gt;]: Error at offset 0 of 3 bytes</p>

<h3>Source File</h3>

<p>

D:\wamp\www\frameworks\yii\web\auth\CDbAuthManager.php(406)</p>

Autocreate Auth Items is not working for me.

I had it working in a previous version, then removed srbac to try another extension (user). Now I’ve added it back in and have the interface up and running, but, when I click on the Autocreate Auth Items nothing happens. It used to scan my controllers and add in any new actions. Now no actions appear at all!

Yii Version 1.1.2, Srbac Version 1.1.1 rc2

Any ideas?

Check firebug to see if the ajax calls give an error when clicking the auto create button.

Thanks for your reply!

Got it working now. Not sure why… There were no errors before. I think I may have something funny going on with my PHP though.

Cheers!

Hi!

If a user that is not allowed to tries to access srbac an error message is displayed:

Error:403 ‘You are not authorized for this action’

Error while trying to access srbac/authitem/frontpage.

I was just wondering if i’d be a wise idea to change that behavior in the next release to redirecting to the login page? Maybe even a option to change this behavior in the config?

regards

You can override the onUnauthorizedAccess() function in SBaseController and do the redirect or print your custom message

Hi!

thank you a lot. I resolved the problem and replaced everything except return false; in onUnauthorizedAccess() function in SBaseController with the following:


Yii::app()->controller->redirect(Yii::app()->user->loginUrl);

thanks again!

regards

I added the auto create…

But it add some tasks / operations like…

Author Role Update Delete

blog/PostsViewing Task Update Delete

BlogPost Task Update Delete

blog/PostsAdministrating Task Update Delete

blog/PostsView Operation Update Delete

blog/PostsCreate Operation Update Delete

blog/PostsUpdate Operation Update Delete

blog/PostsDelete Operation Update Delete

blog/PostsIndex Operation Update Delete

blog/PostsAdmin Operation Update Delete

But every item with / in it i cannot edit or delete… I get:

Not Found

The requested URL /cept.me/srbac/authitem/update/id/blog/PostsAdmin was not found on this server.

umm i see the url is:

/blog%2FPostsViewing

But it should be :

blog%252fPostsViewing

else it is not a valid url (if you use url rewrite)…

What url rules do you use?

This is my htaccess…


# Error reporting

php_flag display_errors on

php_value error_reporting 2147483647


Options +FollowSymLinks

IndexIgnore */*




RewriteEngine on


# if a directory or a file exists, use it directly


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d




# otherwise forward it to index.php

RewriteRule ^(.*[^/])$ index.php [L]

I found some more details about it here…

http://www.webmasterworld.com/apache/3279075.htm

See bottom post :P

Now I tried to find a solution for this… I think the best way would be to encode the url valid in Yii if urlmanager sef url’s is turned on… :P So this cannot happend again. (As it is not valid as url so apache seems to do the right thing)

The easy way will probably be just changing htaccess :P

I found this:

Apache: AllowEncodedSlashes On

Doing this in my htaccess did not work however :P

Then I found this :P

That I need the NO ESCAPE flag :)

But changing the line to:

RewriteRule ^(.*[^/])$ index.php [L,R,NE]

Just give me a forbidden page :s If anybody know how to fix this in htaccess plz let me know :)

i actualy tried to solve the same problem - my current fix looks like this:

i think spyros already intended to avoid that problem with slashes in the url, since he coded his ajaxrequest, with sending post-requests

but with array(‘show’,‘id’=>$model->name), the modelname just got into the get-request parameter… (which is valid since post-requests still can contain get-data)

the solution is, to encapsulate the ajax-call between <form></form> and inside this a hidden field with the id…

in my patch i moved the <?php echo SHtml::endForm();?> from the bottom directly under the searchbox ends, cause i guess nested form-tags aren’t allowed

thank you for your great extension, i hope i could help with this :)

edit:there is still something missing:

model/AuthItem.php

needs a public $id; in the beginning, else it will complain, that AuthItem has no attribute named id…

so this is mostly a hackish solution, but i’m new to yii and guess you’ll find the right solution sooner :)


diff --git a/protected/modules/srbac/views/authitem/manage/list.php b/protected/modules/srbac/views/authitem/manage/list.php

index 275a2d0..e17608d 100644

--- a/protected/modules/srbac/views/authitem/manage/list.php

+++ b/protected/modules/srbac/views/authitem/manage/list.php

@@ -84,6 +84,7 @@

     ?>

     </div>

 </div>

+ <?php echo SHtml::endForm();?>

 <br />

 <table class="srbacDataGrid">

   <tr>

@@ -113,8 +114,11 @@

   </tr>

    <?php foreach($models as $n=>$model): ?>

   <tr class="<?php echo $n%2?'even':'odd';?>">

-    <td><?php echo SHtml::ajaxLink($model->name,

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

+    <td>

+         <?php echo SHtml::beginForm();?>

+         <input type="hidden" name="id" value="<?= SHtml::encode($model->name)?>" />

+    <?php echo SHtml::ajaxLink($model->name,

+    array('show'),

          array('type'=>'POST','update'=>'#preview',

          'beforeSend' => 'function(){

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

@@ -123,14 +127,18 @@

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

                   }',

          ), array("title"=>$model->description ? $model->description : $model->name)

-         ); ?></td>

+         ); ?>

+        <?php echo SHtml::endForm();?>

+    </td>

     <td><?php echo SHtml::encode(AuthItem::$TYPES[$model->type]); ?></td>

     <td>

+         <?php echo SHtml::beginForm();?>

+         <input type="hidden" name="id" value="<?= SHtml::encode($model->name)?>" />

          <?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('update'),

          array(

          'type'=>'POST',

          'update'=>'#preview',

@@ -140,6 +148,7 @@

          'complete' => 'function(){

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

                   }',))?>

+        <?php echo SHtml::endForm();?>

     </td>

     <td>

          <?php if ($model->name !=  Helper::findModule('srbac')->superUser) { ?>

@@ -163,7 +172,6 @@

   </tr>

    <?php endforeach; ?>

 </table>

- <?php echo SHtml::endForm();?>

 <br />

 <div class="simple">

    <?php $this->widget('CLinkPager',array(



Ok my solution… in SHtml.php

Line 45…


public static function ajaxLink($text,$url,$ajaxOptions=array(),$htmlOptions=array()) {

      if(isset($url['id'])){

          $url['id'] = urlencode($url['id']);

      }

In AuthItemController… line 574




  public function loadAuthItem($id=null) {

      

    if ($this->_model===null) {

      $r_id = urldecode(Yii::app()->getRequest()->getParam("id", ""));

Took some time to huntdown what ajaxLink was actually doing… amazed how much some people love to abstract html/js from php :P to the point where it only gets more difficult to read the code :P but that is another topic ^^

Thanks mech7.

I have already changed the code,

Balrok could you confirm that mech7 solution works for you too?

:) Nice thx for fast response and great extension ;)

I’m having the same problem when [data] field is populated. It appears that [data] should be serialized, but SRBAC is storing in [data] field whatever the user enters.

Spyros can you fix this please by serializing [data] fields?

Thanks!

(I am using r209 - the latest published version)

new bug report: (v209)

in /authitem/manage

press "create" button on left form. "Create new Item" panel is displayed on right.

Enter "test1". Set type = Role

press "create" button on right panel. Role is created & flash message is displayed

press "create" button on left form again. "create new item" panel is redisplayed

enter "test2". Set type = Role

press "create" button on right panel.

Role Test2 is created

BUT role Test1 is tried to be inserted again. Firebug shows error :

<h2>CDbCommand failed to execute the SQL statement: [23000][Microsoft][SQL Server Native Client 10.0][SQL Server]Violation of PRIMARY KEY constraint 'PK__auth_items__370627FE'. Cannot insert duplicate key in object 'dbo.auth_items'.</h2>

press "create" button on left form again. "create new item" panel is redisplayed

enter "test3"; set Type = Role

press "create" button on Right panel

Role Test3 is created and flash message is displayed

BUT both Test1 and Test2 are tried to be inserted again. Both give the same error as above

If you continue, it appears to keep stacking up the entries. Only way is to press the “Gear” icon to get a fresh copy of the page. I assume this is something due to AJAX subforms - but haven’t debugged at all.

The data serialize bug is fixed in SVN

Please get the code or add this to the AuthItem model and tell me if it’s working now




<?php

 protected function beforeSave() {

    $this->data = serialize($this->data);

    return parent::beforeSave();

  }


  protected function afterFind() {

    parent::afterFind();

    $this->data = unserialize($this->data);

  }


?>




Hi Spyros,

it’s almost but not quite fixed. Works ok to save a new Auth_item with non-empty [data] field. But if you edit an Auth_item with data, and change the data, it is redisplayed in the form in serialized form. For some reason I don’t know, the AfterFind() is not working in this context. As soon as the Save button is pressed in Edit Auth_Item panel, after [data] is changed from existing value to new value, then the new value is redisplayed in serialized form.

  • Jeremy

I don’t like that solution much - it’s clearly a hack… (but perhaps already writing own CHtml functions is one)

i think another good solution will be:

using (untested)


<?php echo SHtml::ajaxLink($model->name,

       array('show'),

          array('type'=>'POST',

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

'update'=>'#preview',

          'beforeSend' => 'function(){



I have read, that with the ‘data’-array we can specify what stuff should be posted - then the html-code wouldn’t look that ugly cause all my form-tags can be avoided

If you want a full diff example, i can create one… keeping it, as it is now surely works, but people who read the code won’t know about the magic you’re doing to the id-parameter

both solution is good to show the update screen, but after that you can’t save the changes. the problem is the id in form action.

ex:

srbac/authitem/update/id/srbac%2FAuthitemEditAllowed