[Extension] Auth

Hello!

I’m trying to use auth module with yii-user module in my project. And have a several questions.

User module already have some role assignments (user/administrator). And when i navigate to /user/admin/create (new user creation), i see "Superuser" field. But if i understand clearly, all right management are now going through auth module. Am i right? Do i need to set default "superuser" to no? And how?

And how can i set default assignment user to role when i creating user?

Hi to all :)

Thank you Chris83 for this extension.

I have a question for all about this module. You think that i can use this extension with yiimongodbsuite and mongodbauthmanager.

I try to use but i found some erro like for example all user in Assigned items are Administrator (in my admin array i set only my email login -> ‘admins’ => array(‘admin@test.com’, ‘foo’, ‘bar’))

Let me know if you have suggest :)

Thank you

Ok i solved adding (string) before $data->{$this->columId} on widget/AuthAssignmentItemsColumn.php

So my extension actually works even with the mongodb auth manager? If so, that’s really nice to hear.

hi.

only superadmin -default admin in main config- is working in all the site. for another things, what i allow not only sa, else admins (RbacAdmin) is displaying a denied access.

i’ve followed what is written here but still with a 401 error for other users -admins or not admins-

how to set correctly permissions in the controller for not only sa?

thnx

Hi,

is there a way to get all users assigned to a specific role?

I have a dropdown in a form where I want to list only users having a specific role.

Cheers!

Thank you for this! I do think this should be native functionality of the module.

Hi,

I have a critical problem here.

I managed to install the extension and configured it as explained in the tutorial. However I can’t get the admins users having full access to the application:




   'components'=>array(

      'user'=>array(

         // enable cookie-based authentication

         'class' => 'auth.components.AuthWebUser',

         'allowAutoLogin'=>true,

      ),

      'authManager' => array(

         'class' => 'CDbAuthManager',

         'connectionID'=>'db',

         'behaviors' => array(

              array(

                  'class' => 'auth.components.AuthBehavior',

                  'admins' => array('admin'), // users with full access

                  ),

                ),

      ),



I then tried to login as ‘admin’ but I always get access denied. Enabling logging I can see the access verification for admin being done against the database authorization tables and I think it should bypass this process as it belongs to superuser list.

NOTE: admin is a valid username defined in User database table.

Any help?

Thanks

Miguel

when i configure this module i got this error

Object configuration must be an array containing a "class" element.

here is my configuration


    'authManager' => array(


      'behaviors' => array(

	    'class' => 'auth.components.AuthBehavior',

        'auth.components.AuthBehavior',

        'admins'=>array('admin', 'foo', 'bar'), // users with full access

      ),

    ),

    'user' => array(

      'class' => 'auth.components.AuthWebUser',

    ),

To correctly apply bootstrap theme ( yii-bootstrap-2.1.0.r355 ) to auth module ( yii-auth-1.6.0 ), I have to change the auth in config/main.php like below:





        'auth' => array(

            'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.

            'userClass' => 'User', // the name of the user model class.

            'userIdColumn' => 'id', // the name of the user id column.

            'userNameColumn' => 'username', // the name of the user name column.//my DB uses 'username' instead of 'name'

//            'appLayout' => 'application.views.layouts.main', // the layout used by the module.//not working

            'appLayout' => 'webroot.themes.bootstrap.views.layouts.main', // the layout used by the module.//good working

            'viewDir' => null, // the path to view files to use with this module.

        ),




Is there a demo how to use it with authorization? How to add roles to user on authenitication?

I made Operations assignment.* and role.* and added these operations to admin user but when I try to access I get 401 error.

Try this one:





        'authManager' => array(

            'behaviors' => array(

                'auth' => array(

                    'class' => 'auth.components.AuthBehavior',

                    'admins' => array('admin', 'demo', 'foo', 'bar'),// users with full access

                ),

            ),

        ),

        'user' => array(

            'class' => 'auth.components.AuthWebUser',

        ),




<== this part should be commented out to make the ‘eye-open’ link appear always in the right-most column of Assignments tab ( auth/widgets/AuthAssignmentColumn.php line 33 )




	/**

	 * Renders the data cell content.

	 * @param integer $row the row number (zero-based).

	 * @param mixed $data the data associated with the row.

	 */

	protected function renderDataCellContent($row, $data)

	{

//		if (!Yii::app()->user->isAdmin)

		{

			$this->grid->controller->widget('bootstrap.widgets.TbButton', array(

				'type' => 'link',

				'size' => 'mini',

				'icon' => 'eye-open',

				'url' => array('view', 'id' => $data->{$this->idColumn}),

				'htmlOptions' => array('rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'View')),

			));

		}

	}



Hello,

I am newer with Yii and today I have installed the auth extension but when I want to access to /auth/assignment/index, /auth/role/index, …, the application show me "Error 401 Access denied".

The problem is that "if ($user->isAdmin)" always return false. If I comment the above line and the extension works fine.

I have a rol "admin" in AuthItem and a user with this role in AuthAssignment.




	'import'=>array(

		'application.models.*',

		'application.components.*',

		'application.modules.auth.*',

		'application.modules.auth.components.*',

	),

	'theme'=>'bootstrap', // requires you to copy the theme under your themes directory

	'modules'=>array(

		// uncomment the following to enable the Gii tool

		

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'xxxx',

			// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

			'generatorPaths'=>array(

                		'bootstrap.gii',

			),

		),

		'auth' => array(

			'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.

			'userClass' => 'Usuario', // the name of the user model class.

			'userIdColumn' => 'id', // the name of the user id column.

			'userNameColumn' => 'email', // the name of the user name column.

			'defaultLayout' => 'application.views.layouts.main', // the layout used by the module.

			'viewDir' => null, // the path to view files to use with this module.

		),

	),

	// application components

	'components'=>array(

		'bootstrap'=>array(

			 'class'=>'bootstrap.components.Bootstrap',

		),

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

			'class' => 'auth.components.AuthWebUser',

		),

		// para gestionar la autenticación basada en roles con base de datos (db definido después en este mismo fichero)

		'authManager'=>array(

			'class'=>'CDbAuthManager',

			// 'class'=>'auth.components.CachedDbAuthManager',

			// 'cachingDuration'=>3600,

			'connectionID'=>'db',

			'behaviors' => array(

				'auth' => array(

					'class' => 'auth.components.AuthBehavior',

      					'admins' => array('admin'), // users with full access

				),

			),

		),



Thanks.

At the moment, i have the next function in AuthWebUser.php




	public function getIsAdmin()

	{

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

		if($auth->isAssigned("admin",Yii::app()->user->id)) {

			return true;

		}

			

		return $this->getState('__isAdmin', false);

	}



If someone has the right solution, please help me.

Thanks.

@jmendez

This problem has been solved.

See my comments in Auth extension page.

http://www.yiiframework.com/extension/auth/

#14354report it00

whatif at 2013/08/05 10:54pm

How to fix ’ “AuthWebUser.admins” is not defined.’

You do not need to change getIsAdmin() in AuthWebUser.php. Instead you should change the config/main.php as in my comment. Please check which version of Auth you are using and set the right config/main.php accordingly.

Cheers.

Hello @whatif,

I have the yii-auth-1.6.0 version downloaded from the extension site. My currently configuration is




'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

			'class' => 'auth.components.AuthWebUser',

		),

		// para gestionar la autenticación basada en roles con base de datos (db definido después en este mismo fichero)

		'authManager'=>array(

				'class'=>'CDbAuthManager',

				// 'class'=>'auth.components.CachedDbAuthManager',

  				// 'cachingDuration'=>3600,

				'connectionID'=>'db',

				'behaviors' => array(

			    	'auth' => array(

						'class' => 'auth.components.AuthBehavior',

      					'admins' => array('admin'), // users with full access

					),

			      ),

		),



and I think It likes your configuration, but if I don’t change getIsAdmin() I couldn’t access to /auth/assignment/index.html.

Could you tell me where the problem is?

Thanks

Hi @jmendez

  1. I think you made a typo.

You cannot directly access the file as in ‘/auth/assignment/index.html’.

Instead, you can access the auth page with this route /auth/assignment/index

If you cannot still access this route /auth/assignment/index, then check if you have registered your user name as an administrator.

For example if your username is "your_username", this should be added to the array like below:




              'authManager'=>array(

				'class'=>'CDbAuthManager',

				// 'class'=>'auth.components.CachedDbAuthManager',

  				// 'cachingDuration'=>3600,

				'connectionID'=>'db',

				'behaviors' => array(

			    	        'auth' => array(

						'class' => 'auth.components.AuthBehavior',

      					'admins' => array('admin', 'your_username' ), // users with full access

					),

			      ),

		),



Hope this helps

Hello @whatif,

I thought that "admins" contains the roles with full access but as you said "admins" contains the usernames with full access.

I work with roles. Is it possible define the admin role in the config file?

At the moment I have change the validation method but I am sure It is not the right solution.

Thanks.

I am new in this module… but i hope all of you want to help me.

Why i can not access create page for all controller (Roles, Task, Operations)

When i click add button, it show list page. not create page. if i see the url it show the right url (http://webapp/auth/role/create

anyone can help me…? :mellow: