Yii Framework Forum: RBAC defaultRoles with bizRule performance overhead? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

RBAC defaultRoles with bizRule performance overhead? Rate Topic: -----

#1 User is offline   DarkNSF 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 287
  • Joined: 12-November 08
  • Location:Palm Bay, Florida

Posted 17 August 2010 - 11:42 AM

We have a large user base on one of our sites, I wrote code to assign/revoke roles to users on login, on modification, and deletion.

Keeping this structure intact makes me cringe! Though the performance benefits may be worth it.

I would rather have default roles be assigned based on a bizRule that checks the type of the current user. This sounds like a lot of traffic though.. every page load is going to require a query to the database.



How have you guys solved this in the past? Is the bizRule method worth the overhead?
0

#2 User is offline   Chris83 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 27-February 10
  • Location:Helsinki, Finland

Posted 18 August 2010 - 03:35 AM

View PostDarkNSF, on 17 August 2010 - 11:42 AM, said:

We have a large user base on one of our sites, I wrote code to assign/revoke roles to users on login, on modification, and deletion.

Keeping this structure intact makes me cringe! Though the performance benefits may be worth it.

I would rather have default roles be assigned based on a bizRule that checks the type of the current user. This sounds like a lot of traffic though.. every page load is going to require a query to the database.



How have you guys solved this in the past? Is the bizRule method worth the overhead?


Which authorization manager are you using?
Best regards,
Chris

My contribution to the Yii community:
Account | Yiistrap | Auth | Bootstrap | NordCms | Rights | LESS | SEO | Img

Follow me:
Twitter | GitHub | Bitbucket
0

#3 User is offline   Cosmin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 15-August 10

Posted 03 September 2010 - 09:36 AM

you can use CPhpAuthManager which does not use the database, but a config file...it`s harder to maintain but has a smaller overhead
0

#4 User is offline   DarkNSF 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 287
  • Joined: 12-November 08
  • Location:Palm Bay, Florida

Posted 08 September 2010 - 10:35 AM

View PostCosmin, on 03 September 2010 - 09:36 AM, said:

you can use CPhpAuthManager which does not use the database, but a config file...it`s harder to maintain but has a smaller overhead



I am using CDbAuthManager, CPhpAuthManager seemed to be about the same from a visual inspection.

I ended up just modifying the auth assignment table each time a CRUD operation is performed on a user model.


  /**
   * (non-PHPdoc)
   * @see yii-dev/framework/base/CModel#afterSave($event)
   */
  public function afterSave()
  {
    $this->updateRole();
    
    return true;
  }

  /**
   * (non-PHPdoc)
   * @see yii-dev/framework/CActiveRecord#beforeDelete()
   */
  protected function beforeDelete()
  {
    $this->removeAllRoles();

    return true;
  }

  /**
   * update role
   *
   *
   */
  public function updateRole()
  {
    $auth = Yii::app()->authManager;

    $this->removeAllRoles();

    $auth->assign($this->type, $this->id);
    $auth->save();
  }

  /**
   * remove associated roles
   * 
   * 
   */
  private function removeAllRoles()
  {
    $auth = Yii::app()->authManager;

    $roles = $auth->getRoles($this->id);
    foreach($roles as $key=>$role)
    {
      $auth->revoke($key, $this->id);
    }
  }


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users