An authorization library that supports access control models like ACL, RBAC, ABAC for webman plugin

Overview

webman casbin plugin

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require Main webman-permission

An authorization library that supports access control models like ACL, RBAC, ABAC for webman plugin

Requirements

Installation

composer require casbin/webman-permission

Configure

1、DI

configure config/container.php,Its final content is as follows:

$builder = new \DI\ContainerBuilder();
$builder->addDefinitions(config('dependence', []));
$builder->useAutowiring(true);
return $builder->build();

2、Database configuration

(1)修改数据库 thinkorm 配置

(2)创建 casbin_rule 数据表

CREATE TABLE `casbin_rule` (
	`id` BIGINT ( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
	`ptype` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v0` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v1` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v2` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v3` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v4` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v5` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	PRIMARY KEY ( `id` ) USING BTREE,
	KEY `idx_ptype` ( `ptype` ) USING BTREE,
	KEY `idx_v0` ( `v0` ) USING BTREE,
	KEY `idx_v1` ( `v1` ) USING BTREE,
	KEY `idx_v2` ( `v2` ) USING BTREE,
	KEY `idx_v3` ( `v3` ) USING BTREE,
	KEY `idx_v4` ( `v4` ) USING BTREE,
    KEY `idx_v5` ( `v5` ) USING BTREE 
) ENGINE = INNODB CHARSET = utf8mb4 COMMENT = '策略规则表';

(3)配置 config/redis 配置

重启webman

php start.php restart

或者

php start.php restart -d

用法

快速开始

安装成功后,可以这样使用:

use Tinywan\Casbin\Permission;

// adds permissions to a user
Permission::addPermissionForUser('eve', 'articles', 'read');
// adds a role for a user.
Permission::addRoleForUser('eve', 'writer');
// adds permissions to a rule
Permission::addPolicy('writer', 'articles','edit');

你可以检查一个用户是否拥有某个权限:

if (Permission::enforce("eve", "articles", "edit")) {
    echo '恭喜你!通过权限认证';
} else {
    echo '对不起,您没有该资源访问权限';
}

更多 API 参考 Casbin API

感谢

Casbin,你可以查看全部文档在其 官网 上。

You might also like...
Authentication and authorization library for Codeigniter 4

Authentication and Authorization Library for CodeIgniter 4. This library provides an easy and simple way to create login, logout, and user registratio

Slim Auth is an authorization and authentication library for the Slim Framework.

Slim Auth is an authorization and authentication library for the Slim Framework. Authentication is provided by the Zend Framework Zend\Authentication component, and authorization by the Zend Framework Zend\Permissions\Acl component.

A framework agnostic authentication & authorization system.

Sentinel Sentinel is a PHP 7.3+ framework agnostic fully-featured authentication & authorization system. It also provides additional features such as

Declarative style of authorization and validation in laravel.
Declarative style of authorization and validation in laravel.

Laravel Hey Man Readability Counts. In fact, Readability is the primary value of your code !!! 🎀 Heyman continues where the other role-permission pac

Minimalistic token-based authorization for Laravel API endpoints.

Bearer Minimalistic token-based authorization for Laravel API endpoints. Installation You can install the package via Composer: composer require ryang

Files Course Laravel Micro Auth and Authorization

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Easy, native Laravel user authorization.

An easy, native role / permission management system for Laravel. Index Installation Migration Customization Model Customization Usage Checking Permiss

It's authorization form, login button handler and login to your personal account, logout button
It's authorization form, login button handler and login to your personal account, logout button

Authorization-form It's authorization form, login button handler and login to your personal account, logout button Each file is: header.php - html-fil

Comments
  • Typed property Casbin\WebmanPermission\Model\LaravelRuleModel::$store must not be accessed before initialization in D:\www\backend2\vendor\casbin\webman-permission\src\Model\LaravelRuleModel.php:90

    Typed property Casbin\WebmanPermission\Model\LaravelRuleModel::$store must not be accessed before initialization in D:\www\backend2\vendor\casbin\webman-permission\src\Model\LaravelRuleModel.php:90

    Error: Typed property Casbin\WebmanPermission\Model\LaravelRuleModel::$store must not be accessed before initialization in D:\www\backend2\vendor\casbin\webman-permission\src\Model\LaravelRuleModel.php:90 Stack trace: #0 D:\www\backend2\vendor\casbin\webman-permission\src\Adapter\LaravelDatabaseAdapter.php(99): Casbin\WebmanPermission\Model\LaravelRuleModel->getAllFromCache() #1 D:\www\backend2\vendor\casbin\casbin\src\CoreEnforcer.php(363): Casbin\WebmanPermission\Adapter\LaravelDatabaseAdapter->loadPolicy() #2 D:\www\backend2\vendor\casbin\casbin\src\CoreEnforcer.php(223): Casbin\CoreEnforcer->loadPolicy() #3 D:\www\backend2\vendor\casbin\casbin\src\CoreEnforcer.php(156): Casbin\CoreEnforcer->initWithModelAndAdapter() #4 D:\www\backend2\vendor\casbin\webman-permission\src\Permission.php(73): Casbin\CoreEnforcer->__construct() #5 D:\www\backend2\support\bootstrap.php(109): Casbin\WebmanPermission\Permission::start() #6 D:\www\backend2\vendor\workerman\webman-framework\src\support\App.php(97): require_once('...') #7 D:\www\backend2\vendor\workerman\workerman\Worker.php(2454): support\App::support{closure}() #8 D:\www\backend2\vendor\workerman\workerman\Worker.php(1453): Workerman\Worker->run() #9 D:\www\backend2\vendor\workerman\workerman\Worker.php(1396): Workerman\Worker::forkWorkersForWindows() #10 D:\www\backend2\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers() #11 D:\www\backend2\vendor\workerman\webman-framework\src\support\App.php(124): Workerman\Worker::runAll() #12 D:\www\backend2\start.php(4): support\App::run()

    question 
    opened by skeam-tj 3
Releases(v1.0.7)
  • v1.0.7(Jun 13, 2022)

  • v1.0.6(Jun 10, 2022)

    What's Changed

    • 解除 https://github.com/PHP-DI/PHP-DI依赖的解决方案(不推荐) by @houaiai in https://github.com/php-casbin/webman-permission/pull/3
    • Watcher:1、属性类型说明,2、移除发布订阅无关的database

    New Contributors

    • @houaiai made their first contribution in https://github.com/php-casbin/webman-permission/pull/3

    Full Changelog: https://github.com/php-casbin/webman-permission/compare/v1.0.5...v1.0.6

    Source code(tar.gz)
    Source code(zip)
  • v1.0.5(Jun 1, 2022)

    • 1、简化配置文件读取
    • 2、策略模型支持多个,默认为第一个。其他扩展配置,只需要按照基础配置一样,复制一份,指定相关策略模型和适配器即可

    Full Changelog: https://github.com/php-casbin/webman-permission/compare/v1.0.4...v1.0.5

    Source code(tar.gz)
    Source code(zip)
  • v1.0.4(May 30, 2022)

    • 使用 laravel 的适配器的时候,数据能写进去,但是检查权限全部是 false

    Full Changelog: https://github.com/php-casbin/webman-permission/compare/v1.0.3...v1.0.4

    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Apr 7, 2022)

  • v1.0.2(Mar 30, 2022)

  • v1.0.0(Mar 23, 2022)

Owner
PHP-Casbin
PHP-Casbin authorization library and the official middlewares
PHP-Casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

Laravel Authorization Laravel-authz is an authorization library for the laravel framework. It's based on Casbin, an authorization library that support

PHP-Casbin 243 Jan 4, 2023
GUI manager for RBAC (Role Base Access Control) Yii2. Easy to manage authorization of user

RBAC Manager for Yii 2 GUI manager for RBAC (Role Base Access Control) Yii2. Easy to manage authorization of user ?? . Documentation Important: If you

MDMunir Software 1.2k Jan 7, 2023
Dynamic ACL is a package that handles Access Control Level on your Laravel Application.

Dynamic ACL Dynamic ACL is a package that handles Access Control Level on your Laravel Application. It's fast to running and simple to use. Install an

yasin 8 Jul 31, 2022
Authentication, authorization and access control for PHP

Jasny Auth Authentication, authorization and access control for PHP. Features Multiple authorization strategies, like groups (for acl) and levels. Aut

Arnold Daniels 105 Dec 12, 2022
JSON Web Token (JWT) for webman plugin

JSON Web Token (JWT) for webman plugin Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场景。

 ShaoBo Wan(無尘) 25 Dec 30, 2022
A flexible, driver based Acl package for PHP 5.4+

Lock - Acl for PHP 5.4+ I'm sad to say that Lock is currently not maintained. I won't be able to offer support or accept new contributions for the cur

Beatswitch 892 Dec 30, 2022
Register ,Login , Logout , having access control

Helo what's up dude read by the name of creator lov3yp :D This script is inspired by Lov3yp#2018 And Burak karahan Installation steps: !- Import the s

Lov3yp 2 Nov 1, 2021
Tech-Admin is Laravel + Bootstrap Admin Panel With User Management And Access Control based on Roles and Permissions.

Tech-Admin | Laravel 8 + Bootstrap 4 Tech-Admin is Admin Panel With Preset of Roles, Permissions, ACL, User Management, Profile Management. Features M

TechTool India 39 Dec 23, 2022
Middleware to generate access logs for each request using the Apache's access log format

Middleware to generate access logs for each request using the Apache's access log format. This middleware requires a Psr log implementation, for example monolog.

Middlewares 20 Jun 23, 2022
The easiest and most intuitive way to add access management to your Filament Resource Models through `spatie/laravel-permission`

Filament Shield The easiest and most intuitive way to add access management to your Filament Resource Models (more coming soon ?? ) One Plugin to rule

Bezhan Salleh 329 Jan 2, 2023