[Extension] Auth A modern and reponsive user interface for CAuthManager
#1
Posted 02 January 2013 - 04:45 AM
This is the thread for discussing my latest extension, Auth:
http://www.yiiframew.../extension/auth
Feel free to post any questions you have regarding extension below.
#2
Posted 02 January 2013 - 06:23 AM
You've made a great module, again, thanks!
Short question: is there an 'admin-account'-functionality, which gives the admin entrence to everything? It was available in Rights, and I liked it :-). Thanks!
Laurens
#3
Posted 02 January 2013 - 09:02 AM
I'm not sure "admin-account" functionality refers to, but note that when migrating from Rights to Auth, one thing I had to do is to implement the isSuperUser feature in my WebUser class; that is something not provided by Auth (but really fast & easy to adapt).
Hope it helps
#5
Posted 07 January 2013 - 06:16 AM
I edited my config/main.php.
When I try to add a role (foobar): yiiapp.local/auth/role/view/name/foobar I get php notice "Trying to get property of non-object" at yiiapp.local/protected/modules/auth/controllers/AuthItemController.php(133)
At first I thought it was a compatibility problem with "user" extension, but this "yiiapp" application is a clean one, with yii-bootstrap and User class took from your demo.
Any idea?
#6
Posted 08 January 2013 - 04:03 AM
Sounds like a problem with your authorization manager, make sure that you configured it correctly. That error can only occur if the application somehow fails to create the authorization item. I hope this helps you to solve your issue.
delphaber, on 07 January 2013 - 06:16 AM, said:
I edited my config/main.php.
When I try to add a role (foobar): yiiapp.local/auth/role/view/name/foobar I get php notice "Trying to get property of non-object" at yiiapp.local/protected/modules/auth/controllers/AuthItemController.php(133)
At first I thought it was a compatibility problem with "user" extension, but this "yiiapp" application is a clean one, with yii-bootstrap and User class took from your demo.
Any idea?
#7
Posted 09 January 2013 - 05:21 AM
Chris83, on 08 January 2013 - 04:03 AM, said:
Sounds like a problem with your authorization manager, make sure that you configured it correctly. That error can only occur if the application somehow fails to create the authorization item. I hope this helps you to solve your issue.
Thank you
#8
Posted 16 January 2013 - 05:43 PM
While following the documentation I ran into the following:
public function filters()
{
return array(
array('auth.components.AuthFilter'),
),
}
I am not really sure if this is a typo but the comma(,) after the last parenthesis should be replaced by a semicolon (
Also I got an error:
protected\modules\auth\components\AuthFilter.php(41): YiiBase::t("AuthModule.main", "Access denied.")
$itemName .= '.' . $controller->action->getId();
if ($user->checkAccess($itemName))
return true;
throw new CHttpException(401, Yii::t('AuthModule.main', 'Access denied.'));
}
}
I am not really sure why it caused the error but I tried replacing it with:
throw new CHttpException(401,'Access denied.');
This seemed to fix the error but now only the superuser had access to the tasks (although other roles were configured to have permission).
In the end, instead of using array('auth.components.AuthFilter') I tried using 'rights' (filter from your Rights Extension extending Rcontroller). Although I haven't tested it much it seems to work perfectly.
Again I haven't had much time with php and yii so maybe everything I said might be completely wrong.
#9
Posted 17 January 2013 - 04:04 AM
#10
Posted 20 January 2013 - 09:10 AM
gabu, on 16 January 2013 - 05:43 PM, said:
Also I got an error:
protected\modules\auth\components\AuthFilter.php(41): YiiBase::t("AuthModule.main", "Access denied.")
$itemName .= '.' . $controller->action->getId();
if ($user->checkAccess($itemName))
return true;
throw new CHttpException(401, Yii::t('AuthModule.main', 'Access denied.'));
}
}
I am not really sure why it caused the error but I tried replacing it with:
throw new CHttpException(401,'Access denied.');
This seemed to fix the error but now only the superuser had access to the tasks (although other roles were configured to have permission).
You must define
'import'=>array(
'application.modules.auth.*',
'application.modules.auth.components.*',
),
in "protected/config/main.php"
#11
Posted 21 January 2013 - 11:54 AM
'import'=>array(
'application.modules.auth.*',
'application.modules.auth.components.*',
),
in "protected/config/main.php"
[/quote]
Thanks a lot!
Now everything works perfectly
#12
Posted 21 January 2013 - 04:57 PM
I am getting this, does anyone have any ideas?
#13
Posted 23 January 2013 - 06:45 PM
Blogs:
http://yiideveloper.wordpress.com/
http://francis-yii-developer.me
Co-founder of Nintriva Wireless
mails:
jesusloves.francis@gmail.com
francis@nintriva.com
http://nintriva.com
#14
Posted 24 January 2013 - 06:43 AM
AuthAssignmentItemsColumn.php
have problem its check whether logined user is admin instead of user of that row.
so even for non-admin user it will show 'Administrator' instead of Assigned items
Blogs:
http://yiideveloper.wordpress.com/
http://francis-yii-developer.me
Co-founder of Nintriva Wireless
mails:
jesusloves.francis@gmail.com
francis@nintriva.com
http://nintriva.com
#15
Posted 24 January 2013 - 02:44 PM
- I previously was using the basic authentication method using the accessRules() of the Controller and with accessControl in filters.
- I managed so far to install the extension along with Bootstrap, set it up to use the bootstrap theme and configure the main.php as per the instructions.
- I created a user table with id,name,username,password and role fields and updated the UserIdentity.php authenticate() method to check for the user in the DB. That's working fine.
- I went into r=auth with user <<admin>>, and setup several operations like this: item.*
- I created a task name itemAdmin whose child is the item.* operation
- I created a role named admin whose child is itemAdmin.
- I assigned this role to my <<someuser>> user.
When loging in as <<someuser>> and trying to access any of the controller actions it says Error 401 Permission denied.
What do I do with the accessControl and accessRules? Do I have to change that?
Now how do I move forward from here?
#16
Posted 24 January 2013 - 08:22 PM
Jose Rullan, on 24 January 2013 - 02:44 PM, said:
- I previously was using the basic authentication method using the accessRules() of the Controller and with accessControl in filters.
- I managed so far to install the extension along with Bootstrap, set it up to use the bootstrap theme and configure the main.php as per the instructions.
- I created a user table with id,name,username,password and role fields and updated the UserIdentity.php authenticate() method to check for the user in the DB. That's working fine.
- I went into r=auth with user <<admin>>, and setup several operations like this: item.*
- I created a task name itemAdmin whose child is the item.* operation
- I created a role named admin whose child is itemAdmin.
- I assigned this role to my <<someuser>> user.
When loging in as <<someuser>> and trying to access any of the controller actions it says Error 401 Permission denied.
What do I do with the accessControl and accessRules? Do I have to change that?
Now how do I move forward from here?
Well this might be kind of embarrassing since for many this might have been obvious but for the few others that could be struggling these are the steps I took to get it to work. Hope it helps someone.
These are the steps I followed to achieve the use of Auth with CPhpAuthManager.
1. Create a table and model user with id,name,username,password,role.
2. Add one user:
name= Administrator
username = admin
password = admin
role = admin
3. Create a basic auth.txt and auth.php file in protected/data (follow Wiki mentioned below)
4. Install Auth and Bootstrap
Configure the authManager component
'authManager' => array(
'class'=>'CPhpAuthManager',
'behaviors' => array(
'auth' => array(
'class' => 'auth.components.AuthBehavior',
'admins'=>array('admin'), // users with full access
),
),
),
5. Copy the Bootstrap theme into application themes and rename as bootstrap
6. For theming only the Auth module had to configure Auth to use the theme layout located in themes/bootstrap/views/layouts/main.php
7. Modify UserIdentity
private $_id=null;
public function getId()
{
return $this->_id;
}
In the authenticate() function:
$this->_id=$user->id;
$this->username=$user->username;
$auth=Yii::app()->authManager;
if(!is_null($user->role)){
if(!$auth->isAssigned($user->role,$this->_id))
{
if($auth->assign($user->role,$this->_id))
{
Yii::app()->authManager->save();
}
}
}
8. Modify Controllers:
public function filters()
{
return array(
//'accessControl',
array('auth.filters.AuthFilter'),
'postOnly + delete',
);
}
public function accessRules()
{
/* ..... */
}
9. Login as admin
10. navigate to r=auth
11. Create some operations in the form controllerId.*
12. Create tasks and add operations to them
13. Create roles and add tasks or operations to them
14. Assign roles to the users (the Auth module reads them from the Database).
15. In a wiki (http://www.yiiframew...-a-php-file#hh4) read that you should revoke all assigned operations to the user upon logout, not sure if really needed.
#17
Posted 28 January 2013 - 04:22 AM
francis ja, on 24 January 2013 - 06:43 AM, said:
AuthAssignmentItemsColumn.php
have problem its check whether logined user is admin instead of user of that row.
so even for non-admin user it will show 'Administrator' instead of Assigned items
yes i found this problem too.
i remove the if check (on line 36 of AuthAssignmentItemsColumn.php) and the problem seem to solve
#18
Posted 28 January 2013 - 11:22 AM
i used it with Yii user extension so i changed it like below
$userArr=Yii::app()->getModule('user')->getAdmins();
if (in_array($data->username, $userArr))
echo Yii::t('AuthModule.main', 'Administrator');
else
{
Blogs:
http://yiideveloper.wordpress.com/
http://francis-yii-developer.me
Co-founder of Nintriva Wireless
mails:
jesusloves.francis@gmail.com
francis@nintriva.com
http://nintriva.com
#19
Posted 03 February 2013 - 02:38 PM
return array(
'modules' => array(
'auth',
),
'components' => array(
'authManager' => array(
.....
'behaviors' => array(
'auth' => array(
'class' => 'auth.components.AuthBehavior',
'admins'=>array('admin', 'foo', 'bar'), // users with full access
),
),
),
'user' => array(
'class' => 'auth.components.AuthWebUser',
),
),
);I get error
Quote
If I comment line
'admins'=>array('admin', 'foo', 'bar'), // users with full access
error goes off. Is this a bug?
#20
Posted 06 February 2013 - 12:30 PM
francis ja, on 23 January 2013 - 06:45 PM, said:
You can remove specific actions from the access filtering like this:
public function filters()
{
return array(
array('auth.components.AuthFilter - guestAction1, guestAction2, ...'),
);
}
Likewise you can specify which actions should be filtered by changing the minus sign to plus.

Help













