{"id":20876070,"url":"https://github.com/php-casbin/webman-permission","last_synced_at":"2025-04-05T12:03:58.970Z","repository":{"id":38832608,"uuid":"473046470","full_name":"php-casbin/webman-permission","owner":"php-casbin","description":"🔒 An authorization library that supports access control models like ACL, RBAC, ABAC for webman plugin","archived":false,"fork":false,"pushed_at":"2025-02-21T13:49:38.000Z","size":105,"stargazers_count":45,"open_issues_count":0,"forks_count":16,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-02T12:58:59.997Z","etag":null,"topics":["acl","auth","authorization","casbin","casbin-adapter","casbin-watcher","permission","php","rbac","thinkphp","tinywan","webman","workerman"],"latest_commit_sha":null,"homepage":"https://www.workerman.net/plugin/6","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-casbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-23T05:18:10.000Z","updated_at":"2025-03-31T14:48:29.000Z","dependencies_parsed_at":"2023-10-15T02:31:54.771Z","dependency_job_id":"8a796331-8609-4032-90b2-391d07d509ca","html_url":"https://github.com/php-casbin/webman-permission","commit_stats":{"total_commits":53,"total_committers":6,"mean_commits":8.833333333333334,"dds":"0.28301886792452835","last_synced_commit":"ad3e745504eab2d6fb9da57052e865736df22aa9"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fwebman-permission","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fwebman-permission/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fwebman-permission/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fwebman-permission/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-casbin","download_url":"https://codeload.github.com/php-casbin/webman-permission/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819770,"owners_count":20839095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acl","auth","authorization","casbin","casbin-adapter","casbin-watcher","permission","php","rbac","thinkphp","tinywan","webman","workerman"],"created_at":"2024-11-18T06:49:56.862Z","updated_at":"2025-04-05T12:03:58.937Z","avatar_url":"https://github.com/php-casbin.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\u003cimg width=\"260px\" src=\"https://chaz6chez.cn/images/workbunny-logo.png\" alt=\"workbunny\"\u003e\u003c/p\u003e\n\n**\u003cp align=\"center\"\u003e🐇 An Authorization For Webman Plugin. 🐇\u003c/p\u003e**\n\n# \u003cp align=\"center\"\u003e 🐇 Webman Authorization Plugin Base Casbin. 🐇\u003c/p\u003e\n\n[![Default](https://github.com/php-casbin/webman-permission/actions/workflows/default.yml/badge.svg)](https://github.com/php-casbin/webman-permission/actions/workflows/default.yml)\n[![Latest Stable Version](https://poser.pugx.org/casbin/webman-permission/v/stable)](https://packagist.org/packages/casbin/webman-permission)\n[![Total Downloads](https://poser.pugx.org/casbin/webman-permission/downloads)](https://packagist.org/packages/casbin/webman-permission)\n[![License](https://poser.pugx.org/casbin/webman-permission/license)](https://packagist.org/packages/casbin/webman-permission)\n\nAn authorization library that supports access control models like ACL, RBAC, ABAC for webman plugin\n\n# Install\n\nComposer Install\n```sh\ncomposer require -W casbin/webman-permission\n```\n\n# Use\n\n## Dependency Injection configuration\n\nModify the `config/container.php` configuration to perform the following final contents:\n\n```php\n$builder = new \\DI\\ContainerBuilder();\n$builder-\u003eaddDefinitions(config('dependence', []));\n$builder-\u003euseAutowiring(true);\nreturn $builder-\u003ebuild();\n```\n\n## Database configuration\n\n默认策略存储是使用的ThinkORM。\n\n### 1、模型配置\n\n默认使用ThinkORM。修改数据库 `thinkorm.php` 配置\n\n\u003e 如使用laravel数据库，配置参考如下\n  - 修改数据库 `database.php` 配置\n  - 修改数据库 `permission.php` 的`adapter`适配器为laravel适配器\n\n### 2、创建 `casbin_rule` 数据表\n```sql\nCREATE TABLE `casbin_rule` (\n\t`id` BIGINT ( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t`ptype` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\t`v0` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\t`v1` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\t`v2` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\t`v3` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\t`v4` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\t`v5` VARCHAR ( 128 ) NOT NULL DEFAULT '',\n\tPRIMARY KEY ( `id` ) USING BTREE,\n\tKEY `idx_ptype` ( `ptype` ) USING BTREE,\n\tKEY `idx_v0` ( `v0` ) USING BTREE,\n\tKEY `idx_v1` ( `v1` ) USING BTREE,\n\tKEY `idx_v2` ( `v2` ) USING BTREE,\n\tKEY `idx_v3` ( `v3` ) USING BTREE,\n\tKEY `idx_v4` ( `v4` ) USING BTREE,\n    KEY `idx_v5` ( `v5` ) USING BTREE \n) ENGINE = INNODB CHARSET = utf8mb4 COMMENT = '策略规则表';\n```\n### 3、配置 `config/redis` 配置\n\n### 4、重启webman\n\n```\nphp start.php restart\n```\n或者\n```\nphp start.php restart -d\n```\n\n# 使用\n\n安装成功后，可以这样使用:\n\n```php\nuse Casbin\\WebmanPermission\\Permission;\n\n// adds permissions to a user\nPermission::addPermissionForUser('eve', 'articles', 'read');\n// adds a role for a user.\nPermission::addRoleForUser('eve', 'writer');\n// adds permissions to a rule\nPermission::addPolicy('writer', 'articles','edit');\n```\n\n你可以检查一个用户是否拥有某个权限:\n\n```php\nif (\\Casbin\\WebmanPermission\\Permission::enforce('eve', 'articles', 'edit')) {\n    echo '恭喜你！通过权限认证';\n} else {\n    echo '对不起，您没有该资源访问权限';\n}\n```\n\n# 多套驱动配置\n\n```php\n$permission = \\Casbin\\WebmanPermission\\Permission::driver('restful_conf');\n// adds permissions to a user\n$permission-\u003eaddPermissionForUser('eve', 'articles', 'read');\n// adds a role for a user.\n$permission-\u003eaddRoleForUser('eve', 'writer');\n// adds permissions to a rule\n$permission-\u003eaddPolicy('writer', 'articles','edit');\n\nif ($permission-\u003eenforce('eve', 'articles', 'edit')) {\n    echo '恭喜你！通过权限认证';\n} else {\n    echo '对不起，您没有该资源访问权限';\n}\n```\n\n更多 `API` 参考 [Casbin API](https://casbin.org/docs/en/management-api) 。\n\n# 教程\n* [Casbin权限实战：入门分享(中文)](https://www.bilibili.com/video/BV1A541187M4/?vd_source=a9321be9ed112f8d6fdc8ee87640be1b)\n* [Casbin权限实战：基于角色的RBAC授权](https://www.bilibili.com/video/BV1A541187M4/?vd_source=a9321be9ed112f8d6fdc8ee87640be1b)\n* [Casbin权限实战：RESTful及中间件使用](https://www.bilibili.com/video/BV1uk4y117up/?vd_source=a9321be9ed112f8d6fdc8ee87640be1b)\n* [Casbin权限实战：如何使用自定义匹配函数](https://www.bilibili.com/video/BV1dq4y1Z78g/?vd_source=a9321be9ed112f8d6fdc8ee87640be1b)\n* [Webman实战教程：如何使用casbin权限控制](https://www.bilibili.com/video/BV1X34y1Q7ZH/?vd_source=a9321be9ed112f8d6fdc8ee87640be1b)\n\n# 感谢\n\n[Casbin](https://github.com/php-casbin/php-casbin)，你可以查看全部文档在其 [官网](https://casbin.org/) 上。\n\n\u003cdetails\u003e\n\t\n\u003csummary\u003e 解除 https://github.com/PHP-DI/PHP-DI依赖的解决方案（不推荐）\u003c/summary\u003e\n\n1、卸载DI依赖包：`composer remove php-di/php-di`\n\n2、修改：`Casbin\\WebmanPermission\\Permission` 文件\n\n```php\nif (is_null(static::$_manager)) {\n    static::$_manager = new Enforcer($model, Container::get($config['adapter']),false);\n}\n```\n替换为\n```php\nif (is_null(static::$_manager)) {\n    if ($config['adapter'] == DatabaseAdapter::class) {\n        $_model = new RuleModel();\n    } elseif ($config['adapter'] == LaravelDatabaseAdapter::class) {\n        $_model = new LaravelRuleModel();\n    }\n    static::$_manager = new Enforcer($model,  new $config['adapter']($_model), false);\n}\n```\n耦合太高，不建议这么搞，更多了解：https://www.workerman.net/doc/webman/di.html\n\u003c/details\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fwebman-permission","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-casbin%2Fwebman-permission","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fwebman-permission/lists"}