If your groups are already assigned to users in your external tables, then you only need to check group access in the controllers (unless your login determines what site the person is redirected to).
You don’t need a lot of overhead… just a quick access check in the controller. You could maybe override accessRules() (I’ve never looked at doing it that way but might be an option)… or you can just check in the controller’s beforeAction($action), just add it to your controller and cut out all the accessRules part, you can do the same thing like so:
protected function beforeAction($action)
{
// Check your custom role database (user_group_table).. best if in a custom model or component
// Yii::app()->customRbacComponent->isInRoles(...)
if($action->id === "view" && myCustomRbac::isInRoles(array("admin", "usermanager")))
return true;
else
return false;
}
You could still do something similar to accessRules if you wanted, then just loop through the arrays and do the same calls.
I have now found it easier to just do the following in the the UserIdentity class:
public function authenticate()
{
$record=UserMember::model()->findByAttributes(array('members_username'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($record->members_password!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$record->members_username;
/* New stuff starting here: */
$auth=Yii::app()->authManager; // Initialize Auth Manager
// Clear all previously set roles (from previous logins w/o logout)
foreach ($auth->getAuthItems(2,$this->_id) as $authItem) {
$auth->revoke($authItem->name, $this->_id);
}
// Now set new roles (loaded from databse via user model)
foreach ($record->Groups as $role) {
$auth->assign($role->groups_groupname,$this->_id);
}
// Save new roles to auth manager
Yii::app()->authManager->save();
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}