hybridauthmanager 1

An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignments in DB

codemix/hybridauthmanager

Written in PHP by 2 contributors

Contribute

Need Support?


we offer maintenance, support and development services for all our open source projects.

Contact Us

HybridAuthManager

An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignmens in DB.

This class is a combination of CDbAuthManager and CPhpAuthManager:

  • The authorization hierarchy is stored in a flat PHP file
  • Authorization assignments are stored in the database

This is useful if the authorization hierarchy is almost static and not very complex.

You can manage the authorization hierarchy in data/auth.php. To not loose the comments there, you should avoid to call any method to create auth items or add child items - even though it's supported.

Installation

We recommend to install the extension with composer. Add this to the require section of your composer.json:

'codemix/hybridautmanager' : 'dev-master'

Note: There's no stable version yet.

If you haven't yet, you should also add an alias to composer's vendor directory.

$vendor = realpath(__DIR__.'/../vendor');
return array(
    'alias' => array(
        'vendor' => realpath(__DIR__.'/../vendor'), // Fix this path
    ),
    ...

Configuration

Add this configuration to your main.php:

'components' => array(
    'authManager' => array(
        'class' => 'vendor.codemix.hybridautmanager.HybridAuthManager',
    ),
    ...
),

Just as with CPhpAuthManager you'll need to supply a file with auth rules. By default this is in data/auth.php. But here you only have to supply the auth hierarchy:

return array(
    // Admin == Root (Full permissions).
    'Admin' => array(
        'type'          => CAuthItem::TYPE_ROLE,
        'description'   => 'Administrator',
        'children'      => array(
            'manageUser',
            'managePosts',
        ),
    ),
    'manageUser' => array(
        'type' => CAuthItem::TYPE_TASK,
        'children' => array(
            'createUser',
            'updateUser',
            'deleteUser',
            'readUser',
        ),
    ),

    'createUser'    => array('type' => CAuthItem::TYPE_OPERATION),
    'updateUser'    => array('type' => CAuthItem::TYPE_OPERATION),
    'deleteUser'    => array('type' => CAuthItem::TYPE_OPERATION),
    'readUser'      => array('type' => CAuthItem::TYPE_OPERATION),

);

The content of this file will be cached unless you set cacheID to null.

The actual Role assignments will be saved in a DB table auth_assignments by default. You can change this name with the assignmentTable property of the authManager component.

Caching

The component can cache the RBAC hierarchy and auth assignments. You can configure the cache component ID on cacheID.

Caching hierarchy

By default the hierarchy file content is cache 3600 seconds. You can configure this through hierarchyCachingDuration.

Caching auth assigments

You can set the number of seconds to cache auth assignments in assignmentCachingDuration. The assignments will be cached per user to avoid DB calls on each request. By default this is set to 0 which means, that assignments will only be cached throughout the current requests, i.e. on consecutive calls of checkAccess().

Set this property to false to completely disable caching.





43 other PHP projects


phpwkhtmltopdfPHP 716

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

php-pdftkPHP 213

A PDF conversion and form utility based on pdftk

yii2-localeurlsPHP 189

Automatic locale/language management for URLs

YiiRedisPHP 131

A set of wrappers for different data types in redis

yiipasswordPHP 81

Password strategies for Yii

yii2-dockerizedPHP 64

A template for docker based Yii 2 applications

YiiSolrPHP 50

A wrapper for the pecl solr library that provides common Yii constructs, such as models, data providers etc

php-shellcommandPHP 48

A simple object oriented interface to execute shell commands in PHP

Yii-Docs-GeneratorPHP 47

Generates HTML documentation for Yii applications

YiiGitPHP 36

A git wrapper for Yii, allows access to all git commands programatically

YiiElasticSearchPHP 32

Elastic Search client for Yii

YiiCurlPHP 30

A curl library for Yii

YiiStateMachinePHP 28

A state machine behavior for Yii

yii2-streamlogPHP 19

A Yii 2 log target for streams in URL format

oauth2yiiPHP 18

An OAuth2 client / server extension for the Yii framework

restyiiPHP 16

A RESTful extension for Yii.

packagecompressorPHP 16

A Javascript/CSS compressor based on Yii's package system

localeurlsPHP 12

Automatic locale/language management for URLs

php-excel-readerPHP 12

It reads the binary format of XLS files directly and can return values and formats from any cell. This project is the fork of http://code.google.com/p/php-excel-reader/ that, apparently, is no longer maintained.

pdfablePHP 10

A Yii extension to create PDFs with PHPWkHtmlToPdf/wkhtmltopdf

yii-api-vimPHP 8

Yii API manual plugin for VIM

yii2-excel-messagePHP 7

Translate messages via Excel files

xcrudcontrollerPHP 7

A base class to quickly build customized CRUD interfaces.

yii2-bs3activeformPHP 7

A Bootstrap 3 enhanced ActiveForm for Yii 2

php-tmpfilePHP 6

A convenience class for temporary files

handlebarsphpPHP 6

Transpiles handlebars templates into native PHP templates

Yii-Package-ManagerPHP 6

A package manager for Yii

php-orientdbPHP 5

A fast PHP driver for the OrientDB binary protocol.

yii2-apidoc-vimPHP 5

Yii2 apidoc as Vim helpfiles

translatablePHP 4

Transparent attribute translation for ActiveRecords

YiiUsersPHP 4

User management for Yii

flushablePHP 3

Yii dependency that allows to flush records from the cache

Yii-Resource-ManagerPHP 3

Helpers to allow Yii to interact with resources (files) of different types

bs3activeformPHP 2

A lightweight utility to render Bootstrap 3 forms in Yii

AccessRestrictablePHP 2

A Yii ActiveRecordBehavior that automatically applies conditions for access restriction to every query.

YiiEmailerPHP 2

Emailing functions for Yii

defaultpersisterPHP 1

Yii extension to save and restore model values in user session.

YiiYaaPHP 1

YAA is an additional abstraction layer for Yii that aggregates a number of child models into a clean single model that is easy to cache

YiiLinkablePHP 1

A simple extension for Yii allowing easy and consistent access to model URLs and appropriate anchor text.

twittonioPHP

simple useless twitter client

yii2-base-appPHP

An alternative Yii2 application template for purists

YiiAbstractArrayModelPHP

Work with PHP files in Active Record way

xreturnablePHP

Yii extension to create URLs that allow to return to a page by storing its GET Parameters on a stack.