thinkingmik/acl-manager-laravel
Composer 安装命令:
composer require thinkingmik/acl-manager-laravel
包简介
A Laravel access control list package
README 文档
README
Versions
| Laravel | ACL Manager | PHP |
|---|---|---|
| 4.2.x | 1.x | >= 5.4 |
| 5.0.x | 2.x | >= 5.4 |
Summary
Introduction
Adds ACL to Laravel 5. This ACL solution for Laravel is useful when you need to store policy rules or users' roles into a database. ACL Manager are composed by three entities:
- Roles
- Resources
- Permissions
Installation
Add the following line to the require section of composer.json:
{
"require": {
"thinkingmik/acl-manager-laravel": "2.x"
}
}
Setup
- Add
'ThinKingMik\AclManager\AclManagerServiceProvider',into the service provider list inconfig/app.php. - Add
'Acl' => 'ThinKingMik\AclManager\Facades\AclManagerFacade',into the list of aliases inconfig/app.php. - Add
'ThinKingMik\AclManager\Middleware\AclManagerExceptionHandler',into the list of middlewere inapp/Http/Kernel.php.
Migrations and configuration file
In order to use the Acl Manager publish its configuration and migrations first
php artisan vendor:publish
Note: migrations are only published, remember to run them when ready.
Migrations
This package comes with all the migrations you need to run a full featured Acl Manager. First of all you need to check the reference to the user table name:
- Check the users table name of your Laravel installation in
config/auth.phpat the section:
/* |-------------------------------------------------------------------------- | Authentication Table |-------------------------------------------------------------------------- | | When using the "Database" authentication driver, we need to know which | table should be used to retrieve your users. We have chosen a basic | default value but you may easily change it to any table you like. | */ 'table' => 'system_users',
- Change the table reference for
user_idforeign key in these filesdatabase/migrations:
xxx_000006_create_acl_users_roles_table.php
xxx_000005_create_acl_users_policies_table.php
- Check
user_idforeign key in all the above files to be sure that the user table name is the same as'table' => 'system_users':
$table->foreign('user_id')->references('id')->on('system_users')
- Now you can run:
php artisan migrate
Configuration
Edit the file config/acl.php to suit your needs.
Usage
Routing
You can use Acl Manager in routes as a filter
Route::get('/private', array('before' => 'auth|acl:admin.*', 'uses' => function() { }));
All checks are made on user_id attribute retrieved from session.
You can define many different acl: filters:
acl:role.resource.permission //check if logged user has role and the permission on resource acl:*.resource.permission //check if logged user has permission on resource acl:role.* //check if logged user has role acl:role.resource.* //check if logged user has role and any permissions on resource acl:*.resource.* //check if logged user has any permissions on resource
You can also combine these filters with ; separator like:
acl:admin.*;guest.*
Facade
The Acl Manager is available through the Facade Acl or through the acl service in the IOC container.
The methods available are:
/** * Check if user ID has a specified policy/policies * @param integer $user User ID * @param string $policies The policies used in routing * return boolean **/ Acl::isRouteAllowed(1, 'admin.*;guest.*'); /** * Check if user has permission on resource * @param array $users Array of user objects or array of user IDs * @param array $resources Array of resource objects or array of resource IDs * @param array $permissions Array of permission objects or array of permission IDs * return boolean **/ Acl::isAllowed(array(1), array('post', 'dashboard'), array('edit', 'view')); /** * Check if role has permission on resource * @param array $roles Array of role objects or array of role IDs * @param array $resources Array of resource objects or array of resource IDs * @param array $permissions Array of permission objects or array of permission IDs * return boolean **/ Acl::areAnyRolesAllowed(array(1), array('post', 'dashboard'), array('edit', 'view')); /** * Check if user has roles * @param array $users Array of user objects or array of user IDs * @param array $roles Array of role objects or array of role IDs * return boolean **/ Acl::hasRole(array(1), array('1', '2')); /** * Add permissions on resources for users specified * @param array $users Array of user objects or array of user IDs * @param array $resources Array of resource objects or array of resource IDs * @param array $permissions Array of permission objects or array of permission IDs * @param date [$expire] Optionally you can specify an expiration date for policies * return boolean **/ Acl::allowUsers(array(1), array('post', 'dashboard'), array('edit', 'view'), '2099-11-01'); /** * Add permissions on resources for roles specified * @param array $roles Array of role objects or array of role IDs * @param array $resources Array of resource objects or array of resource IDs * @param array $permissions Array of permission objects or array of permission IDs * @param date [$expire] Optionally you can specify an expiration date for policies * return boolean **/ Acl::allowRoles(array(1), array('post', 'dashboard'), array('edit', 'view'), '2099-11-01'); /** * Remove permissions on resources for users specified * @param array $users Array of user objects or array of user IDs * @param array $resources Array of resource objects or array of resource IDs * @param array $permissions Array of permission objects or array of permission IDs * return integer The number of deleted policies **/ Acl::denyUsers(array(1), array('post', 'dashboard'), array('edit', 'view')); /** * Remove permissions on resources for roles specified * @param array $roles Array of role objects or array of role IDs * @param array $resources Array of resource objects or array of resource IDs * @param array $permissions Array of permission objects or array of permission IDs * return integer The number of deleted policies **/ Acl::denyRoles(array(1), array('post', 'dashboard'), array('edit', 'view')); /** * Add roles to users * @param array $users Array of user objects or array of user IDs * @param array $roles Array of role objects or array of role IDs * @param char [$main] Optionally you can specify the main role * return boolean **/ Acl::addUsersRoles(array(1), array('1', '2'), 'Y');
License
This package is released under the MIT License.
thinkingmik/acl-manager-laravel 适用场景与选型建议
thinkingmik/acl-manager-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「access」 「acl」 「laravel」 「resource」 「permission」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thinkingmik/acl-manager-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thinkingmik/acl-manager-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thinkingmik/acl-manager-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Laravel Multiauth package
Provide a way to secure accesses to all routes of an symfony application.
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
This package provides a flexible way to add Role-based Permissions to Laravel
General Interface for access control
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-28